@xchainjs/xchain-bitcoin 0.18.0-alpha.1 → 0.18.0-alpha.2
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/CHANGELOG.md +4 -0
- package/lib/haskoin-api.d.ts +4 -0
- package/lib/index.esm.js +64 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +64 -3
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
- Return `inputs` UTXOs from `buildTx` #489
|
|
9
9
|
- Extract `Haskoin` types #490
|
|
10
10
|
|
|
11
|
+
## Fix
|
|
12
|
+
|
|
13
|
+
- Broadcast same tx several times to Haskoin in case of `500` error #492
|
|
14
|
+
|
|
11
15
|
## Breaking change
|
|
12
16
|
|
|
13
17
|
- Add `confirmedOnly` param to `Client.getBalance` and to misc. `balance*` helpers #490
|
package/lib/haskoin-api.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export declare const getConfirmedUnspentTxs: ({ haskoinUrl, sochainUrl, address,
|
|
|
28
28
|
*
|
|
29
29
|
* @see https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3#/blockchain/sendTransaction
|
|
30
30
|
*
|
|
31
|
+
* Note: Because of an Haskoin issue (@see https://github.com/haskoin/haskoin-store/issues/25),
|
|
32
|
+
* we need to broadcast same tx several times in case of `500` errors
|
|
33
|
+
* @see https://github.com/xchainjs/xchainjs-lib/issues/492
|
|
34
|
+
*
|
|
31
35
|
* @param {BroadcastTxParams} params
|
|
32
36
|
* @returns {TxHash} Transaction hash.
|
|
33
37
|
*/
|
package/lib/index.esm.js
CHANGED
|
@@ -64845,6 +64845,26 @@ var bignumber$1 = createCommonjsModule$1(function (module) {
|
|
|
64845
64845
|
})(commonjsGlobal$1);
|
|
64846
64846
|
});
|
|
64847
64847
|
|
|
64848
|
+
/**
|
|
64849
|
+
* Helper to delay anything within an `async` function
|
|
64850
|
+
*
|
|
64851
|
+
* @param ms delay in milliseconds
|
|
64852
|
+
*
|
|
64853
|
+
* @example
|
|
64854
|
+
*
|
|
64855
|
+
* ```
|
|
64856
|
+
* const anyAsyncFunc = async () => {
|
|
64857
|
+
* // do something
|
|
64858
|
+
* console.log('before delay')
|
|
64859
|
+
* // wait for 200ms
|
|
64860
|
+
* await delay(200)
|
|
64861
|
+
* // and do other things
|
|
64862
|
+
* console.log('after delay')
|
|
64863
|
+
* }
|
|
64864
|
+
* ```
|
|
64865
|
+
*/
|
|
64866
|
+
var delay = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
|
|
64867
|
+
|
|
64848
64868
|
/**
|
|
64849
64869
|
* Shortcut to create a BigNumber
|
|
64850
64870
|
*
|
|
@@ -64905,7 +64925,7 @@ var CosmosChain = Chain.Cosmos;
|
|
|
64905
64925
|
var PolkadotChain = Chain.Polkadot;
|
|
64906
64926
|
var BCHChain = Chain.BitcoinCash;
|
|
64907
64927
|
var LTCChain = Chain.Litecoin;
|
|
64908
|
-
var
|
|
64928
|
+
var LUNAChain = Chain.Terra;
|
|
64909
64929
|
var DOGEChain = Chain.Doge;
|
|
64910
64930
|
/**
|
|
64911
64931
|
* Convert chain to string.
|
|
@@ -85603,19 +85623,60 @@ var getConfirmedUnspentTxs$1 = function (_a) {
|
|
|
85603
85623
|
*
|
|
85604
85624
|
* @see https://app.swaggerhub.com/apis/eligecode/blockchain-api/0.0.1-oas3#/blockchain/sendTransaction
|
|
85605
85625
|
*
|
|
85626
|
+
* Note: Because of an Haskoin issue (@see https://github.com/haskoin/haskoin-store/issues/25),
|
|
85627
|
+
* we need to broadcast same tx several times in case of `500` errors
|
|
85628
|
+
* @see https://github.com/xchainjs/xchainjs-lib/issues/492
|
|
85629
|
+
*
|
|
85606
85630
|
* @param {BroadcastTxParams} params
|
|
85607
85631
|
* @returns {TxHash} Transaction hash.
|
|
85608
85632
|
*/
|
|
85609
85633
|
var broadcastTx = function (_a) {
|
|
85610
85634
|
var txHex = _a.txHex, haskoinUrl = _a.haskoinUrl;
|
|
85611
85635
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
85612
|
-
var txid;
|
|
85636
|
+
var instance, MAX, counter, onFullfilled, onRejected, id, url, txid, error_1;
|
|
85613
85637
|
return __generator(this, function (_b) {
|
|
85614
85638
|
switch (_b.label) {
|
|
85615
|
-
case 0:
|
|
85639
|
+
case 0:
|
|
85640
|
+
instance = axios.create();
|
|
85641
|
+
MAX = 5;
|
|
85642
|
+
counter = 0;
|
|
85643
|
+
onFullfilled = function (res) { return res; };
|
|
85644
|
+
onRejected = function (error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
85645
|
+
var config;
|
|
85646
|
+
var _a;
|
|
85647
|
+
return __generator(this, function (_b) {
|
|
85648
|
+
switch (_b.label) {
|
|
85649
|
+
case 0:
|
|
85650
|
+
config = error.config;
|
|
85651
|
+
if (!(counter < MAX && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 500)) return [3 /*break*/, 2];
|
|
85652
|
+
counter++;
|
|
85653
|
+
return [4 /*yield*/, delay(200 * counter)];
|
|
85654
|
+
case 1:
|
|
85655
|
+
_b.sent();
|
|
85656
|
+
return [2 /*return*/, instance.request(config)];
|
|
85657
|
+
case 2: return [2 /*return*/, Promise.reject(error)];
|
|
85658
|
+
}
|
|
85659
|
+
});
|
|
85660
|
+
}); };
|
|
85661
|
+
id = instance.interceptors.response.use(onFullfilled, onRejected);
|
|
85662
|
+
url = haskoinUrl + "/transactions";
|
|
85663
|
+
_b.label = 1;
|
|
85616
85664
|
case 1:
|
|
85665
|
+
_b.trys.push([1, 3, , 4]);
|
|
85666
|
+
return [4 /*yield*/, instance.post(url, txHex)
|
|
85667
|
+
// clean up interceptor from axios instance
|
|
85668
|
+
];
|
|
85669
|
+
case 2:
|
|
85617
85670
|
txid = (_b.sent()).data.txid;
|
|
85671
|
+
// clean up interceptor from axios instance
|
|
85672
|
+
instance.interceptors.response.eject(id);
|
|
85618
85673
|
return [2 /*return*/, txid];
|
|
85674
|
+
case 3:
|
|
85675
|
+
error_1 = _b.sent();
|
|
85676
|
+
// clean up interceptor from axios instance
|
|
85677
|
+
instance.interceptors.response.eject(id);
|
|
85678
|
+
return [2 /*return*/, Promise.reject(error_1)];
|
|
85679
|
+
case 4: return [2 /*return*/];
|
|
85619
85680
|
}
|
|
85620
85681
|
});
|
|
85621
85682
|
});
|