@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/index.js CHANGED
@@ -64871,7 +64871,6 @@ var Chain;
64871
64871
  Chain["Cosmos"] = "GAIA";
64872
64872
  Chain["BitcoinCash"] = "BCH";
64873
64873
  Chain["Litecoin"] = "LTC";
64874
- Chain["Terra"] = "TERRA";
64875
64874
  Chain["Doge"] = "DOGE";
64876
64875
  Chain["Avax"] = "AVAX";
64877
64876
  })(Chain || (Chain = {}));
@@ -64883,7 +64882,6 @@ const THORChain = Chain.THORChain;
64883
64882
  const CosmosChain = Chain.Cosmos;
64884
64883
  const BCHChain = Chain.BitcoinCash;
64885
64884
  const LTCChain = Chain.Litecoin;
64886
- const TerraChain = Chain.Terra;
64887
64885
  const DOGEChain = Chain.Doge;
64888
64886
  const AVAXChain = Chain.Avax;
64889
64887
  /**
@@ -64905,7 +64903,6 @@ const chainToString = Object.assign((chainId) => {
64905
64903
  [Chain.Ethereum]: 'Ethereum',
64906
64904
  [Chain.Binance]: 'Binance Chain',
64907
64905
  [Chain.Cosmos]: 'Cosmos',
64908
- [Chain.Terra]: 'Terra',
64909
64906
  [Chain.Doge]: 'Dogecoin',
64910
64907
  });
64911
64908
 
@@ -65094,7 +65091,6 @@ const AssetRuneERC20Testnet = {
65094
65091
  synth: false,
65095
65092
  };
65096
65093
  const AssetAtom = { chain: Chain.Cosmos, symbol: 'ATOM', ticker: 'ATOM', synth: false };
65097
- const AssetLUNA = { chain: Chain.Terra, symbol: 'LUNA', ticker: 'LUNA', synth: false };
65098
65094
  /**
65099
65095
  * Currency symbols currently supported
65100
65096
  */
@@ -85275,6 +85271,84 @@ const getSuggestedTxFee = () => __awaiter(void 0, void 0, void 0, function* () {
85275
85271
  }
85276
85272
  });
85277
85273
 
85274
+ /**
85275
+ * Module to interact with Haskoin API
85276
+ *
85277
+ * Doc (SwaggerHub) https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3
85278
+ *
85279
+ */
85280
+ let instance = axios__default['default'].create();
85281
+ const setupHaskoinInstance = (customRequestHeaders) => {
85282
+ instance = axios__default['default'].create({ headers: customRequestHeaders });
85283
+ };
85284
+ const getBalance$1 = ({ haskoinUrl, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
85285
+ const { data: { confirmed, unconfirmed }, } = yield instance.get(`${haskoinUrl}/address/${address}/balance`);
85286
+ const confirmedAmount = baseAmount(confirmed, BTC_DECIMAL);
85287
+ const unconfirmedAmount = baseAmount(unconfirmed, BTC_DECIMAL);
85288
+ return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
85289
+ });
85290
+ const getUnspentTxs$1 = ({ haskoinUrl, address, }) => __awaiter(void 0, void 0, void 0, function* () {
85291
+ const { data: response } = yield instance.get(`${haskoinUrl}/address/${address}/unspent`);
85292
+ return response;
85293
+ });
85294
+ const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, }) => __awaiter(void 0, void 0, void 0, function* () {
85295
+ const allUtxos = yield getUnspentTxs$1({ haskoinUrl, address });
85296
+ const confirmedUTXOs = [];
85297
+ yield Promise.all(allUtxos.map((tx) => __awaiter(void 0, void 0, void 0, function* () {
85298
+ const confirmed = yield getConfirmedTxStatus({
85299
+ sochainUrl,
85300
+ network,
85301
+ txHash: tx.txid,
85302
+ });
85303
+ if (confirmed) {
85304
+ confirmedUTXOs.push(tx);
85305
+ }
85306
+ })));
85307
+ return confirmedUTXOs;
85308
+ });
85309
+ /**
85310
+ * Broadcast transaction.
85311
+ *
85312
+ * @see https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3#/blockchain/sendTransaction
85313
+ *
85314
+ * Note: Because of an Haskoin issue (@see https://github.com/haskoin/haskoin-store/issues/25),
85315
+ * we need to broadcast same tx several times in case of `500` errors
85316
+ * @see https://github.com/xchainjs/xchainjs-lib/issues/492
85317
+ *
85318
+ * @param {BroadcastTxParams} params
85319
+ * @returns {TxHash} Transaction hash.
85320
+ */
85321
+ const broadcastTx = ({ txHex, haskoinUrl }) => __awaiter(void 0, void 0, void 0, function* () {
85322
+ const MAX = 5;
85323
+ let counter = 0;
85324
+ const onFullfilled = (res) => res;
85325
+ const onRejected = (error) => __awaiter(void 0, void 0, void 0, function* () {
85326
+ var _a;
85327
+ const config = error.config;
85328
+ if (counter < MAX && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 500) {
85329
+ counter++;
85330
+ yield delay(200 * counter);
85331
+ return instance.request(config);
85332
+ }
85333
+ return Promise.reject(error);
85334
+ });
85335
+ // All logic for re-sending same tx is handled by Axios' response interceptor
85336
+ // https://github.com/axios/axios#interceptors
85337
+ const id = instance.interceptors.response.use(onFullfilled, onRejected);
85338
+ const url = `${haskoinUrl}/transactions`;
85339
+ try {
85340
+ const { data: { txid }, } = yield instance.post(url, txHex);
85341
+ // clean up interceptor from axios instance
85342
+ instance.interceptors.response.eject(id);
85343
+ return txid;
85344
+ }
85345
+ catch (error) {
85346
+ // clean up interceptor from axios instance
85347
+ instance.interceptors.response.eject(id);
85348
+ return Promise.reject(error);
85349
+ }
85350
+ });
85351
+
85278
85352
  // baseline estimates, used to improve performance
85279
85353
  var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
85280
85354
  var TX_INPUT_BASE = 32 + 4 + 1 + 4;
@@ -85387,81 +85461,6 @@ var accumulative = function accumulative (utxos, outputs, feeRate) {
85387
85461
  return { fee: feeRate * bytesAccum }
85388
85462
  };
85389
85463
 
85390
- /**
85391
- * Module to interact with Haskoin API
85392
- *
85393
- * Doc (SwaggerHub) https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3
85394
- *
85395
- */
85396
- const getBalance$1 = ({ haskoinUrl, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
85397
- const { data: { confirmed, unconfirmed }, } = yield axios__default['default'].get(`${haskoinUrl}/address/${address}/balance`);
85398
- const confirmedAmount = baseAmount(confirmed, BTC_DECIMAL);
85399
- const unconfirmedAmount = baseAmount(unconfirmed, BTC_DECIMAL);
85400
- return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
85401
- });
85402
- const getUnspentTxs$1 = ({ haskoinUrl, address, }) => __awaiter(void 0, void 0, void 0, function* () {
85403
- const { data: response } = yield axios__default['default'].get(`${haskoinUrl}/address/${address}/unspent`);
85404
- return response;
85405
- });
85406
- const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, }) => __awaiter(void 0, void 0, void 0, function* () {
85407
- const allUtxos = yield getUnspentTxs$1({ haskoinUrl, address });
85408
- const confirmedUTXOs = [];
85409
- yield Promise.all(allUtxos.map((tx) => __awaiter(void 0, void 0, void 0, function* () {
85410
- const confirmed = yield getConfirmedTxStatus({
85411
- sochainUrl,
85412
- network,
85413
- txHash: tx.txid,
85414
- });
85415
- if (confirmed) {
85416
- confirmedUTXOs.push(tx);
85417
- }
85418
- })));
85419
- return confirmedUTXOs;
85420
- });
85421
- /**
85422
- * Broadcast transaction.
85423
- *
85424
- * @see https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3#/blockchain/sendTransaction
85425
- *
85426
- * Note: Because of an Haskoin issue (@see https://github.com/haskoin/haskoin-store/issues/25),
85427
- * we need to broadcast same tx several times in case of `500` errors
85428
- * @see https://github.com/xchainjs/xchainjs-lib/issues/492
85429
- *
85430
- * @param {BroadcastTxParams} params
85431
- * @returns {TxHash} Transaction hash.
85432
- */
85433
- const broadcastTx = ({ txHex, haskoinUrl }) => __awaiter(void 0, void 0, void 0, function* () {
85434
- const instance = axios__default['default'].create();
85435
- const MAX = 5;
85436
- let counter = 0;
85437
- const onFullfilled = (res) => res;
85438
- const onRejected = (error) => __awaiter(void 0, void 0, void 0, function* () {
85439
- var _a;
85440
- const config = error.config;
85441
- if (counter < MAX && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 500) {
85442
- counter++;
85443
- yield delay(200 * counter);
85444
- return instance.request(config);
85445
- }
85446
- return Promise.reject(error);
85447
- });
85448
- // All logic for re-sending same tx is handled by Axios' response interceptor
85449
- // https://github.com/axios/axios#interceptors
85450
- const id = instance.interceptors.response.use(onFullfilled, onRejected);
85451
- const url = `${haskoinUrl}/transactions`;
85452
- try {
85453
- const { data: { txid }, } = yield instance.post(url, txHex);
85454
- // clean up interceptor from axios instance
85455
- instance.interceptors.response.eject(id);
85456
- return txid;
85457
- }
85458
- catch (error) {
85459
- // clean up interceptor from axios instance
85460
- instance.interceptors.response.eject(id);
85461
- return Promise.reject(error);
85462
- }
85463
- });
85464
-
85465
85464
  const TX_EMPTY_SIZE$1 = 4 + 1 + 1 + 4; //10
85466
85465
  const TX_INPUT_BASE$1 = 32 + 4 + 1 + 4; // 41
85467
85466
  const TX_INPUT_PUBKEYHASH$1 = 107;
@@ -85762,7 +85761,7 @@ class Client extends xchainClient.UTXOClient {
85762
85761
  *
85763
85762
  * @param {BitcoinClientParams} params
85764
85763
  */
85765
- constructor({ network = xchainClient.Network.Testnet, feeBounds = {
85764
+ constructor({ network = xchainClient.Network.Mainnet, feeBounds = {
85766
85765
  lower: LOWER_FEE_BOUND,
85767
85766
  upper: UPPER_FEE_BOUND,
85768
85767
  }, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
@@ -85773,11 +85772,16 @@ class Client extends xchainClient.UTXOClient {
85773
85772
  [xchainClient.Network.Mainnet]: `84'/0'/0'/0/`,
85774
85773
  [xchainClient.Network.Testnet]: `84'/1'/0'/0/`,
85775
85774
  [xchainClient.Network.Stagenet]: `84'/0'/0'/0/`,
85776
- }, phrase = '', }) {
85777
- super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds });
85775
+ }, phrase = '', customRequestHeaders = {}, }) {
85776
+ super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds, customRequestHeaders });
85778
85777
  this.sochainUrl = '';
85779
85778
  this.setSochainUrl(sochainUrl);
85780
85779
  this.haskoinUrl = haskoinUrl;
85780
+ // need to ensure x-client-id is set if we are using 9R endpoints
85781
+ if (this.haskoinUrl.mainnet.includes('haskoin.ninerealms.com') && !this.customRequestHeaders['x-client-id']) {
85782
+ this.customRequestHeaders['x-client-id'] = 'xchainjs-client';
85783
+ }
85784
+ setupHaskoinInstance(this.customRequestHeaders);
85781
85785
  }
85782
85786
  /**
85783
85787
  * Set/Update the sochain url.