@xchainjs/xchain-bitcoin 0.20.2 → 0.20.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.d.ts +1 -1
- package/lib/haskoin-api.d.ts +1 -0
- package/lib/index.esm.js +86 -82
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +86 -82
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/lib/client.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare class Client extends UTXOClient {
|
|
|
17
17
|
*
|
|
18
18
|
* @param {BitcoinClientParams} params
|
|
19
19
|
*/
|
|
20
|
-
constructor({ network, feeBounds, sochainUrl, haskoinUrl, rootDerivationPaths, phrase, }: BitcoinClientParams);
|
|
20
|
+
constructor({ network, feeBounds, sochainUrl, haskoinUrl, rootDerivationPaths, phrase, customRequestHeaders, }: BitcoinClientParams);
|
|
21
21
|
/**
|
|
22
22
|
* Set/Update the sochain url.
|
|
23
23
|
*
|
package/lib/haskoin-api.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { Network, TxHash } from '@xchainjs/xchain-client';
|
|
|
8
8
|
import { BaseAmount } from '@xchainjs/xchain-util';
|
|
9
9
|
import type { BroadcastTxParams } from './types/common';
|
|
10
10
|
import type { UtxoData } from './types/haskoin-api-types';
|
|
11
|
+
export declare const setupHaskoinInstance: (customRequestHeaders: Record<string, string>) => void;
|
|
11
12
|
export declare const getBalance: ({ haskoinUrl, address, confirmedOnly, }: {
|
|
12
13
|
haskoinUrl: string;
|
|
13
14
|
address: string;
|
package/lib/index.esm.js
CHANGED
|
@@ -64857,7 +64857,6 @@ var Chain;
|
|
|
64857
64857
|
Chain["Cosmos"] = "GAIA";
|
|
64858
64858
|
Chain["BitcoinCash"] = "BCH";
|
|
64859
64859
|
Chain["Litecoin"] = "LTC";
|
|
64860
|
-
Chain["Terra"] = "TERRA";
|
|
64861
64860
|
Chain["Doge"] = "DOGE";
|
|
64862
64861
|
Chain["Avax"] = "AVAX";
|
|
64863
64862
|
})(Chain || (Chain = {}));
|
|
@@ -64869,7 +64868,6 @@ const THORChain = Chain.THORChain;
|
|
|
64869
64868
|
const CosmosChain = Chain.Cosmos;
|
|
64870
64869
|
const BCHChain = Chain.BitcoinCash;
|
|
64871
64870
|
const LTCChain = Chain.Litecoin;
|
|
64872
|
-
const TerraChain = Chain.Terra;
|
|
64873
64871
|
const DOGEChain = Chain.Doge;
|
|
64874
64872
|
const AVAXChain = Chain.Avax;
|
|
64875
64873
|
/**
|
|
@@ -64891,7 +64889,6 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64891
64889
|
[Chain.Ethereum]: 'Ethereum',
|
|
64892
64890
|
[Chain.Binance]: 'Binance Chain',
|
|
64893
64891
|
[Chain.Cosmos]: 'Cosmos',
|
|
64894
|
-
[Chain.Terra]: 'Terra',
|
|
64895
64892
|
[Chain.Doge]: 'Dogecoin',
|
|
64896
64893
|
});
|
|
64897
64894
|
|
|
@@ -65080,7 +65077,6 @@ const AssetRuneERC20Testnet = {
|
|
|
65080
65077
|
synth: false,
|
|
65081
65078
|
};
|
|
65082
65079
|
const AssetAtom = { chain: Chain.Cosmos, symbol: 'ATOM', ticker: 'ATOM', synth: false };
|
|
65083
|
-
const AssetLUNA = { chain: Chain.Terra, symbol: 'LUNA', ticker: 'LUNA', synth: false };
|
|
65084
65080
|
/**
|
|
65085
65081
|
* Currency symbols currently supported
|
|
65086
65082
|
*/
|
|
@@ -85261,6 +85257,84 @@ const getSuggestedTxFee = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
85261
85257
|
}
|
|
85262
85258
|
});
|
|
85263
85259
|
|
|
85260
|
+
/**
|
|
85261
|
+
* Module to interact with Haskoin API
|
|
85262
|
+
*
|
|
85263
|
+
* Doc (SwaggerHub) https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3
|
|
85264
|
+
*
|
|
85265
|
+
*/
|
|
85266
|
+
let instance = axios.create();
|
|
85267
|
+
const setupHaskoinInstance = (customRequestHeaders) => {
|
|
85268
|
+
instance = axios.create({ headers: customRequestHeaders });
|
|
85269
|
+
};
|
|
85270
|
+
const getBalance$1 = ({ haskoinUrl, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85271
|
+
const { data: { confirmed, unconfirmed }, } = yield instance.get(`${haskoinUrl}/address/${address}/balance`);
|
|
85272
|
+
const confirmedAmount = baseAmount(confirmed, BTC_DECIMAL);
|
|
85273
|
+
const unconfirmedAmount = baseAmount(unconfirmed, BTC_DECIMAL);
|
|
85274
|
+
return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
|
|
85275
|
+
});
|
|
85276
|
+
const getUnspentTxs$1 = ({ haskoinUrl, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85277
|
+
const { data: response } = yield instance.get(`${haskoinUrl}/address/${address}/unspent`);
|
|
85278
|
+
return response;
|
|
85279
|
+
});
|
|
85280
|
+
const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85281
|
+
const allUtxos = yield getUnspentTxs$1({ haskoinUrl, address });
|
|
85282
|
+
const confirmedUTXOs = [];
|
|
85283
|
+
yield Promise.all(allUtxos.map((tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85284
|
+
const confirmed = yield getConfirmedTxStatus({
|
|
85285
|
+
sochainUrl,
|
|
85286
|
+
network,
|
|
85287
|
+
txHash: tx.txid,
|
|
85288
|
+
});
|
|
85289
|
+
if (confirmed) {
|
|
85290
|
+
confirmedUTXOs.push(tx);
|
|
85291
|
+
}
|
|
85292
|
+
})));
|
|
85293
|
+
return confirmedUTXOs;
|
|
85294
|
+
});
|
|
85295
|
+
/**
|
|
85296
|
+
* Broadcast transaction.
|
|
85297
|
+
*
|
|
85298
|
+
* @see https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3#/blockchain/sendTransaction
|
|
85299
|
+
*
|
|
85300
|
+
* Note: Because of an Haskoin issue (@see https://github.com/haskoin/haskoin-store/issues/25),
|
|
85301
|
+
* we need to broadcast same tx several times in case of `500` errors
|
|
85302
|
+
* @see https://github.com/xchainjs/xchainjs-lib/issues/492
|
|
85303
|
+
*
|
|
85304
|
+
* @param {BroadcastTxParams} params
|
|
85305
|
+
* @returns {TxHash} Transaction hash.
|
|
85306
|
+
*/
|
|
85307
|
+
const broadcastTx = ({ txHex, haskoinUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85308
|
+
const MAX = 5;
|
|
85309
|
+
let counter = 0;
|
|
85310
|
+
const onFullfilled = (res) => res;
|
|
85311
|
+
const onRejected = (error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85312
|
+
var _a;
|
|
85313
|
+
const config = error.config;
|
|
85314
|
+
if (counter < MAX && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 500) {
|
|
85315
|
+
counter++;
|
|
85316
|
+
yield delay(200 * counter);
|
|
85317
|
+
return instance.request(config);
|
|
85318
|
+
}
|
|
85319
|
+
return Promise.reject(error);
|
|
85320
|
+
});
|
|
85321
|
+
// All logic for re-sending same tx is handled by Axios' response interceptor
|
|
85322
|
+
// https://github.com/axios/axios#interceptors
|
|
85323
|
+
const id = instance.interceptors.response.use(onFullfilled, onRejected);
|
|
85324
|
+
const url = `${haskoinUrl}/transactions`;
|
|
85325
|
+
try {
|
|
85326
|
+
const { data: { txid }, } = yield instance.post(url, txHex);
|
|
85327
|
+
// clean up interceptor from axios instance
|
|
85328
|
+
instance.interceptors.response.eject(id);
|
|
85329
|
+
return txid;
|
|
85330
|
+
}
|
|
85331
|
+
catch (error) {
|
|
85332
|
+
// clean up interceptor from axios instance
|
|
85333
|
+
instance.interceptors.response.eject(id);
|
|
85334
|
+
return Promise.reject(error);
|
|
85335
|
+
}
|
|
85336
|
+
});
|
|
85337
|
+
|
|
85264
85338
|
// baseline estimates, used to improve performance
|
|
85265
85339
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
85266
85340
|
var TX_INPUT_BASE = 32 + 4 + 1 + 4;
|
|
@@ -85373,81 +85447,6 @@ var accumulative = function accumulative (utxos, outputs, feeRate) {
|
|
|
85373
85447
|
return { fee: feeRate * bytesAccum }
|
|
85374
85448
|
};
|
|
85375
85449
|
|
|
85376
|
-
/**
|
|
85377
|
-
* Module to interact with Haskoin API
|
|
85378
|
-
*
|
|
85379
|
-
* Doc (SwaggerHub) https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3
|
|
85380
|
-
*
|
|
85381
|
-
*/
|
|
85382
|
-
const getBalance$1 = ({ haskoinUrl, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85383
|
-
const { data: { confirmed, unconfirmed }, } = yield axios.get(`${haskoinUrl}/address/${address}/balance`);
|
|
85384
|
-
const confirmedAmount = baseAmount(confirmed, BTC_DECIMAL);
|
|
85385
|
-
const unconfirmedAmount = baseAmount(unconfirmed, BTC_DECIMAL);
|
|
85386
|
-
return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
|
|
85387
|
-
});
|
|
85388
|
-
const getUnspentTxs$1 = ({ haskoinUrl, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85389
|
-
const { data: response } = yield axios.get(`${haskoinUrl}/address/${address}/unspent`);
|
|
85390
|
-
return response;
|
|
85391
|
-
});
|
|
85392
|
-
const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85393
|
-
const allUtxos = yield getUnspentTxs$1({ haskoinUrl, address });
|
|
85394
|
-
const confirmedUTXOs = [];
|
|
85395
|
-
yield Promise.all(allUtxos.map((tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85396
|
-
const confirmed = yield getConfirmedTxStatus({
|
|
85397
|
-
sochainUrl,
|
|
85398
|
-
network,
|
|
85399
|
-
txHash: tx.txid,
|
|
85400
|
-
});
|
|
85401
|
-
if (confirmed) {
|
|
85402
|
-
confirmedUTXOs.push(tx);
|
|
85403
|
-
}
|
|
85404
|
-
})));
|
|
85405
|
-
return confirmedUTXOs;
|
|
85406
|
-
});
|
|
85407
|
-
/**
|
|
85408
|
-
* Broadcast transaction.
|
|
85409
|
-
*
|
|
85410
|
-
* @see https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3#/blockchain/sendTransaction
|
|
85411
|
-
*
|
|
85412
|
-
* Note: Because of an Haskoin issue (@see https://github.com/haskoin/haskoin-store/issues/25),
|
|
85413
|
-
* we need to broadcast same tx several times in case of `500` errors
|
|
85414
|
-
* @see https://github.com/xchainjs/xchainjs-lib/issues/492
|
|
85415
|
-
*
|
|
85416
|
-
* @param {BroadcastTxParams} params
|
|
85417
|
-
* @returns {TxHash} Transaction hash.
|
|
85418
|
-
*/
|
|
85419
|
-
const broadcastTx = ({ txHex, haskoinUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85420
|
-
const instance = axios.create();
|
|
85421
|
-
const MAX = 5;
|
|
85422
|
-
let counter = 0;
|
|
85423
|
-
const onFullfilled = (res) => res;
|
|
85424
|
-
const onRejected = (error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85425
|
-
var _a;
|
|
85426
|
-
const config = error.config;
|
|
85427
|
-
if (counter < MAX && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 500) {
|
|
85428
|
-
counter++;
|
|
85429
|
-
yield delay(200 * counter);
|
|
85430
|
-
return instance.request(config);
|
|
85431
|
-
}
|
|
85432
|
-
return Promise.reject(error);
|
|
85433
|
-
});
|
|
85434
|
-
// All logic for re-sending same tx is handled by Axios' response interceptor
|
|
85435
|
-
// https://github.com/axios/axios#interceptors
|
|
85436
|
-
const id = instance.interceptors.response.use(onFullfilled, onRejected);
|
|
85437
|
-
const url = `${haskoinUrl}/transactions`;
|
|
85438
|
-
try {
|
|
85439
|
-
const { data: { txid }, } = yield instance.post(url, txHex);
|
|
85440
|
-
// clean up interceptor from axios instance
|
|
85441
|
-
instance.interceptors.response.eject(id);
|
|
85442
|
-
return txid;
|
|
85443
|
-
}
|
|
85444
|
-
catch (error) {
|
|
85445
|
-
// clean up interceptor from axios instance
|
|
85446
|
-
instance.interceptors.response.eject(id);
|
|
85447
|
-
return Promise.reject(error);
|
|
85448
|
-
}
|
|
85449
|
-
});
|
|
85450
|
-
|
|
85451
85450
|
const TX_EMPTY_SIZE$1 = 4 + 1 + 1 + 4; //10
|
|
85452
85451
|
const TX_INPUT_BASE$1 = 32 + 4 + 1 + 4; // 41
|
|
85453
85452
|
const TX_INPUT_PUBKEYHASH$1 = 107;
|
|
@@ -85748,7 +85747,7 @@ class Client extends UTXOClient {
|
|
|
85748
85747
|
*
|
|
85749
85748
|
* @param {BitcoinClientParams} params
|
|
85750
85749
|
*/
|
|
85751
|
-
constructor({ network = Network.
|
|
85750
|
+
constructor({ network = Network.Mainnet, feeBounds = {
|
|
85752
85751
|
lower: LOWER_FEE_BOUND,
|
|
85753
85752
|
upper: UPPER_FEE_BOUND,
|
|
85754
85753
|
}, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
|
|
@@ -85759,11 +85758,16 @@ class Client extends UTXOClient {
|
|
|
85759
85758
|
[Network.Mainnet]: `84'/0'/0'/0/`,
|
|
85760
85759
|
[Network.Testnet]: `84'/1'/0'/0/`,
|
|
85761
85760
|
[Network.Stagenet]: `84'/0'/0'/0/`,
|
|
85762
|
-
}, phrase = '', }) {
|
|
85763
|
-
super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds });
|
|
85761
|
+
}, phrase = '', customRequestHeaders = {}, }) {
|
|
85762
|
+
super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds, customRequestHeaders });
|
|
85764
85763
|
this.sochainUrl = '';
|
|
85765
85764
|
this.setSochainUrl(sochainUrl);
|
|
85766
85765
|
this.haskoinUrl = haskoinUrl;
|
|
85766
|
+
// need to ensure x-client-id is set if we are using 9R endpoints
|
|
85767
|
+
if (this.haskoinUrl.mainnet.includes('haskoin.ninerealms.com') && !this.customRequestHeaders['x-client-id']) {
|
|
85768
|
+
this.customRequestHeaders['x-client-id'] = 'xchainjs-client';
|
|
85769
|
+
}
|
|
85770
|
+
setupHaskoinInstance(this.customRequestHeaders);
|
|
85767
85771
|
}
|
|
85768
85772
|
/**
|
|
85769
85773
|
* Set/Update the sochain url.
|