@xchainjs/xchain-utxo-providers 1.0.6 → 1.0.7
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.esm.js +1 -1
- package/lib/index.js +27 -22
- package/package.json +3 -3
package/lib/index.esm.js
CHANGED
|
@@ -27,7 +27,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
27
27
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
28
|
PERFORMANCE OF THIS SOFTWARE.
|
|
29
29
|
***************************************************************************** */
|
|
30
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
30
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,11 @@ var axios = require('axios');
|
|
|
5
5
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
6
6
|
var PromisePool = require('@supercharge/promise-pool');
|
|
7
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
11
|
+
var PromisePool__default = /*#__PURE__*/_interopDefault(PromisePool);
|
|
12
|
+
|
|
8
13
|
exports.SochainNetwork = void 0;
|
|
9
14
|
(function (SochainNetwork) {
|
|
10
15
|
SochainNetwork["BTC"] = "BTC";
|
|
@@ -29,7 +34,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
29
34
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
30
35
|
PERFORMANCE OF THIS SOFTWARE.
|
|
31
36
|
***************************************************************************** */
|
|
32
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
37
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
33
38
|
|
|
34
39
|
|
|
35
40
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
@@ -59,7 +64,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
59
64
|
*/
|
|
60
65
|
const getTx$2 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
66
|
const url = `${sochainUrl}/transaction/${network}/${hash}`;
|
|
62
|
-
const response = yield
|
|
67
|
+
const response = yield axios__default.default.get(url, { headers: { 'API-KEY': apiKey } });
|
|
63
68
|
const tx = response.data;
|
|
64
69
|
return tx.data;
|
|
65
70
|
});
|
|
@@ -75,7 +80,7 @@ const getTx$2 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, voi
|
|
|
75
80
|
*/
|
|
76
81
|
const getTxs$2 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
82
|
const url = `${sochainUrl}/transactions/${network}/${address}/${page}`; //TODO support paging
|
|
78
|
-
const response = yield
|
|
83
|
+
const response = yield axios__default.default.get(url, { headers: { 'API-KEY': apiKey } });
|
|
79
84
|
const txs = response.data;
|
|
80
85
|
return txs.data;
|
|
81
86
|
});
|
|
@@ -92,7 +97,7 @@ const getTxs$2 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(
|
|
|
92
97
|
*/
|
|
93
98
|
const getBalance$2 = ({ apiKey, sochainUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
99
|
const url = `${sochainUrl}/balance/${network}/${address}`;
|
|
95
|
-
const response = yield
|
|
100
|
+
const response = yield axios__default.default.get(url, { headers: { 'API-KEY': apiKey } });
|
|
96
101
|
const balanceResponse = response.data;
|
|
97
102
|
const confirmed = xchainUtil.assetAmount(balanceResponse.data.confirmed, assetDecimals);
|
|
98
103
|
const unconfirmed = xchainUtil.assetAmount(balanceResponse.data.unconfirmed, assetDecimals);
|
|
@@ -112,7 +117,7 @@ const getBalance$2 = ({ apiKey, sochainUrl, network, address, confirmedOnly, ass
|
|
|
112
117
|
*/
|
|
113
118
|
const getUnspentTxs$1 = ({ apiKey, sochainUrl, network, address, page, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
119
|
const url = [sochainUrl, 'unspent_outputs', network, address, page].filter((v) => !!v).join('/');
|
|
115
|
-
const resp = yield
|
|
120
|
+
const resp = yield axios__default.default.get(url, { headers: { 'API-KEY': apiKey } });
|
|
116
121
|
const response = resp.data;
|
|
117
122
|
const txs = response.data.outputs;
|
|
118
123
|
if (txs.length === 10) {
|
|
@@ -143,7 +148,7 @@ const getUnspentTxs$1 = ({ apiKey, sochainUrl, network, address, page, }) => __a
|
|
|
143
148
|
*/
|
|
144
149
|
const broadcastTx$2 = ({ apiKey, sochainUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
145
150
|
const url = `${sochainUrl}/broadcast_transaction/${network}`;
|
|
146
|
-
const response = yield
|
|
151
|
+
const response = yield axios__default.default.post(url, { tx_hex: txHex }, { headers: { 'API-KEY': apiKey } });
|
|
147
152
|
const broadcastResponse = response.data;
|
|
148
153
|
return broadcastResponse.tx_hex;
|
|
149
154
|
});
|
|
@@ -380,7 +385,7 @@ const isErrorResponse = (response) => {
|
|
|
380
385
|
*/
|
|
381
386
|
const getAccount = ({ haskoinUrl, network, address }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
382
387
|
const url = `${haskoinUrl}/${network}/address/${address}/balance`;
|
|
383
|
-
const result = (yield
|
|
388
|
+
const result = (yield axios__default.default.get(url)).data;
|
|
384
389
|
if (!result || isErrorResponse(result))
|
|
385
390
|
throw new Error(`failed to query account by given address ${address}`);
|
|
386
391
|
return result;
|
|
@@ -395,7 +400,7 @@ const getAccount = ({ haskoinUrl, network, address }) => __awaiter(void 0, void
|
|
|
395
400
|
*/
|
|
396
401
|
const getAddress = ({ haskoinUrl, network, address }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
397
402
|
const url = `${haskoinUrl}/${network}/address/${address}/balance`;
|
|
398
|
-
const response = yield
|
|
403
|
+
const response = yield axios__default.default.get(url);
|
|
399
404
|
const addressResponse = response.data;
|
|
400
405
|
return addressResponse.data;
|
|
401
406
|
});
|
|
@@ -409,7 +414,7 @@ const getAddress = ({ haskoinUrl, network, address }) => __awaiter(void 0, void
|
|
|
409
414
|
* @throws {"failed to query transaction by a given hash"} thrown if failed to query transaction by a given hash
|
|
410
415
|
*/
|
|
411
416
|
const getTx$1 = ({ haskoinUrl, txId, network }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
412
|
-
const result = (yield
|
|
417
|
+
const result = (yield axios__default.default.get(`${haskoinUrl}/${network}/transaction/${txId}`)).data;
|
|
413
418
|
if (!result || isErrorResponse(result))
|
|
414
419
|
throw new Error(`failed to query transaction by a given hash ${txId}`);
|
|
415
420
|
return result;
|
|
@@ -424,7 +429,7 @@ const getTx$1 = ({ haskoinUrl, txId, network }) => __awaiter(void 0, void 0, voi
|
|
|
424
429
|
* @throws {"failed to query transaction by a given hash"} thrown if failed to query raw transaction by a given hash
|
|
425
430
|
*/
|
|
426
431
|
const getRawTransaction = ({ haskoinUrl, network, txId }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
|
-
const result = (yield
|
|
432
|
+
const result = (yield axios__default.default.get(`${haskoinUrl}/${network}/transaction/${txId}/raw`))
|
|
428
433
|
.data;
|
|
429
434
|
if (!result || isErrorResponse(result))
|
|
430
435
|
throw new Error(`failed to query transaction by a given hash ${txId}`);
|
|
@@ -443,7 +448,7 @@ const getRawTransaction = ({ haskoinUrl, network, txId }) => __awaiter(void 0, v
|
|
|
443
448
|
const getTxs$1 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
444
449
|
const params = { limit: `${limit}`, offset: `${offset}` };
|
|
445
450
|
const url = `${haskoinUrl}/${network}/address/${address}/transactions/full`;
|
|
446
|
-
const result = (yield
|
|
451
|
+
const result = (yield axios__default.default.get(url, { params })).data;
|
|
447
452
|
if (!result || isErrorResponse(result))
|
|
448
453
|
throw new Error('failed to query transactions');
|
|
449
454
|
return result;
|
|
@@ -454,7 +459,7 @@ const getTxs$1 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter
|
|
|
454
459
|
* @returns Returns BaseAmount
|
|
455
460
|
*/
|
|
456
461
|
const getBalance$1 = ({ haskoinUrl, haskoinNetwork, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
457
|
-
const { data: { confirmed, unconfirmed }, } = yield
|
|
462
|
+
const { data: { confirmed, unconfirmed }, } = yield axios__default.default.get(`${haskoinUrl}/${haskoinNetwork}/address/${address}/balance`);
|
|
458
463
|
const confirmedAmount = xchainUtil.baseAmount(confirmed, assetDecimals);
|
|
459
464
|
const unconfirmedAmount = xchainUtil.baseAmount(unconfirmed, assetDecimals);
|
|
460
465
|
return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
|
|
@@ -472,7 +477,7 @@ const getUnspentTxs = ({ haskoinUrl, network, address }) => __awaiter(void 0, vo
|
|
|
472
477
|
// Get transaction count for a given address.
|
|
473
478
|
const account = yield getAccount({ haskoinUrl, network, address });
|
|
474
479
|
// Set limit to the transaction count to be all the utxos.
|
|
475
|
-
const result = (yield
|
|
480
|
+
const result = (yield axios__default.default.get(`${haskoinUrl}/${network}/address/${address}/unspent?limit${account === null || account === void 0 ? void 0 : account.utxo}`)).data;
|
|
476
481
|
if (!result || isErrorResponse(result))
|
|
477
482
|
throw new Error('failed to query unspent transactions');
|
|
478
483
|
return result;
|
|
@@ -579,7 +584,7 @@ const getUnspentTransactions = ({ haskoinUrl, network, address }) => __awaiter(v
|
|
|
579
584
|
// Get transaction count for a given address.
|
|
580
585
|
const account = yield getAccount({ haskoinUrl, network, address });
|
|
581
586
|
// Set limit to the transaction count to be all the utxos.
|
|
582
|
-
const result = (yield
|
|
587
|
+
const result = (yield axios__default.default.get(`${haskoinUrl}/${network}/address/${address}/unspent?limit${account === null || account === void 0 ? void 0 : account.utxo}`)).data;
|
|
583
588
|
if (!result || isErrorResponse(result))
|
|
584
589
|
throw new Error('failed to query unspent transactions');
|
|
585
590
|
return result;
|
|
@@ -600,7 +605,7 @@ const broadcastTx$1 = ({ txHex, haskoinUrl, haskoinNetwork, }) => __awaiter(void
|
|
|
600
605
|
var _a;
|
|
601
606
|
const MAX_RETRIES = 5;
|
|
602
607
|
let retries = 0;
|
|
603
|
-
const axiosInstance =
|
|
608
|
+
const axiosInstance = axios__default.default.create();
|
|
604
609
|
const url = `${haskoinUrl}/${haskoinNetwork}/transactions`;
|
|
605
610
|
while (retries < MAX_RETRIES) {
|
|
606
611
|
try {
|
|
@@ -784,7 +789,7 @@ const getTx = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void
|
|
|
784
789
|
if (apiKey)
|
|
785
790
|
params['token'] = apiKey;
|
|
786
791
|
const url = `${baseUrl}/${network}/txs/${hash}`;
|
|
787
|
-
const response = yield
|
|
792
|
+
const response = yield axios__default.default.get(url, { params });
|
|
788
793
|
const tx = response.data;
|
|
789
794
|
return tx;
|
|
790
795
|
});
|
|
@@ -804,7 +809,7 @@ const getTxs = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspent
|
|
|
804
809
|
params['token'] = apiKey;
|
|
805
810
|
if (beforeBlock)
|
|
806
811
|
params['before'] = `${beforeBlock}`;
|
|
807
|
-
const response = yield
|
|
812
|
+
const response = yield axios__default.default.get(url, { params });
|
|
808
813
|
const txs = response.data;
|
|
809
814
|
return txs;
|
|
810
815
|
});
|
|
@@ -823,7 +828,7 @@ const getBalance = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDec
|
|
|
823
828
|
const url = `${baseUrl}/${network}/addrs/${address}/balance`;
|
|
824
829
|
if (apiKey)
|
|
825
830
|
params['token'] = apiKey;
|
|
826
|
-
const response = yield
|
|
831
|
+
const response = yield axios__default.default.get(url, { params });
|
|
827
832
|
const balanceResponse = response.data;
|
|
828
833
|
const confirmedAmount = xchainUtil.baseAmount(balanceResponse.balance, assetDecimals);
|
|
829
834
|
const finalBalance = xchainUtil.baseAmount(balanceResponse.final_balance, assetDecimals);
|
|
@@ -834,7 +839,7 @@ const broadcastTx = ({ apiKey, baseUrl, network, txHex, }) => __awaiter(void 0,
|
|
|
834
839
|
const url = `${baseUrl}/${network}/txs/push`;
|
|
835
840
|
if (apiKey)
|
|
836
841
|
params['token'] = apiKey;
|
|
837
|
-
const response = yield
|
|
842
|
+
const response = yield axios__default.default.post(url, { tx: txHex }, { params });
|
|
838
843
|
const broadcastResponse = response.data;
|
|
839
844
|
return broadcastResponse.tx.hash;
|
|
840
845
|
});
|
|
@@ -848,7 +853,7 @@ const getBlockchainData = ({ baseUrl, apiKey, }) => __awaiter(void 0, void 0, vo
|
|
|
848
853
|
const params = {};
|
|
849
854
|
if (apiKey)
|
|
850
855
|
params['token'] = apiKey;
|
|
851
|
-
const chainResponse = yield
|
|
856
|
+
const chainResponse = yield axios__default.default.get(`${baseUrl}`, { params });
|
|
852
857
|
return chainResponse.data;
|
|
853
858
|
});
|
|
854
859
|
|
|
@@ -1060,7 +1065,7 @@ class BlockcypherProvider {
|
|
|
1060
1065
|
//an errors means no more results
|
|
1061
1066
|
}
|
|
1062
1067
|
//note: blockcypher has rate of 3 req/sec --> https://www.blockcypher.com/dev/bitcoin/#rate-limits-and-tokens
|
|
1063
|
-
const batchResult = yield
|
|
1068
|
+
const batchResult = yield PromisePool__default.default.for(txHashesToFetch)
|
|
1064
1069
|
.withConcurrency(3)
|
|
1065
1070
|
.useCorrespondingResults()
|
|
1066
1071
|
.process((hash) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1095,7 +1100,7 @@ exports.BlockcypherNetwork = void 0;
|
|
|
1095
1100
|
* @returns {GetFeeEstimateResponse} Get fee estimate response
|
|
1096
1101
|
*/
|
|
1097
1102
|
const getFeeEstimate = (baseUrl, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1098
|
-
const response = yield
|
|
1103
|
+
const response = yield axios__default.default.get(`${baseUrl}/tx/fee`, { params: request });
|
|
1099
1104
|
return response.data;
|
|
1100
1105
|
});
|
|
1101
1106
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-utxo-providers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.esm.js",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@supercharge/promise-pool": "2.4.0",
|
|
32
|
-
"@xchainjs/xchain-client": "1.0.
|
|
33
|
-
"@xchainjs/xchain-util": "1.0.
|
|
32
|
+
"@xchainjs/xchain-client": "1.0.7",
|
|
33
|
+
"@xchainjs/xchain-util": "1.0.6",
|
|
34
34
|
"axios": "1.7.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|