@xchainjs/xchain-utxo-providers 1.0.5 → 1.0.6
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 +8 -1
- package/lib/index.js +29 -29
- package/package.json +4 -4
package/lib/index.esm.js
CHANGED
|
@@ -27,6 +27,8 @@ 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 */
|
|
31
|
+
|
|
30
32
|
|
|
31
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32
34
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -36,7 +38,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
36
38
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
39
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
40
|
});
|
|
39
|
-
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
44
|
+
var e = new Error(message);
|
|
45
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
|
+
};
|
|
40
47
|
|
|
41
48
|
/**
|
|
42
49
|
* Get transaction by hash.
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
6
4
|
var axios = require('axios');
|
|
7
5
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
8
6
|
var PromisePool = require('@supercharge/promise-pool');
|
|
9
7
|
|
|
10
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
-
|
|
12
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
13
|
-
var PromisePool__default = /*#__PURE__*/_interopDefaultLegacy(PromisePool);
|
|
14
|
-
|
|
15
8
|
exports.SochainNetwork = void 0;
|
|
16
9
|
(function (SochainNetwork) {
|
|
17
10
|
SochainNetwork["BTC"] = "BTC";
|
|
@@ -36,6 +29,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
36
29
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
37
30
|
PERFORMANCE OF THIS SOFTWARE.
|
|
38
31
|
***************************************************************************** */
|
|
32
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
33
|
+
|
|
39
34
|
|
|
40
35
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
41
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -45,7 +40,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
45
40
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
42
|
});
|
|
48
|
-
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
46
|
+
var e = new Error(message);
|
|
47
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Get transaction by hash.
|
|
@@ -59,7 +59,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
59
59
|
*/
|
|
60
60
|
const getTx$2 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
61
|
const url = `${sochainUrl}/transaction/${network}/${hash}`;
|
|
62
|
-
const response = yield
|
|
62
|
+
const response = yield axios.get(url, { headers: { 'API-KEY': apiKey } });
|
|
63
63
|
const tx = response.data;
|
|
64
64
|
return tx.data;
|
|
65
65
|
});
|
|
@@ -75,7 +75,7 @@ const getTx$2 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, voi
|
|
|
75
75
|
*/
|
|
76
76
|
const getTxs$2 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
77
|
const url = `${sochainUrl}/transactions/${network}/${address}/${page}`; //TODO support paging
|
|
78
|
-
const response = yield
|
|
78
|
+
const response = yield axios.get(url, { headers: { 'API-KEY': apiKey } });
|
|
79
79
|
const txs = response.data;
|
|
80
80
|
return txs.data;
|
|
81
81
|
});
|
|
@@ -92,7 +92,7 @@ const getTxs$2 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(
|
|
|
92
92
|
*/
|
|
93
93
|
const getBalance$2 = ({ apiKey, sochainUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
94
|
const url = `${sochainUrl}/balance/${network}/${address}`;
|
|
95
|
-
const response = yield
|
|
95
|
+
const response = yield axios.get(url, { headers: { 'API-KEY': apiKey } });
|
|
96
96
|
const balanceResponse = response.data;
|
|
97
97
|
const confirmed = xchainUtil.assetAmount(balanceResponse.data.confirmed, assetDecimals);
|
|
98
98
|
const unconfirmed = xchainUtil.assetAmount(balanceResponse.data.unconfirmed, assetDecimals);
|
|
@@ -112,7 +112,7 @@ const getBalance$2 = ({ apiKey, sochainUrl, network, address, confirmedOnly, ass
|
|
|
112
112
|
*/
|
|
113
113
|
const getUnspentTxs$1 = ({ apiKey, sochainUrl, network, address, page, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
114
|
const url = [sochainUrl, 'unspent_outputs', network, address, page].filter((v) => !!v).join('/');
|
|
115
|
-
const resp = yield
|
|
115
|
+
const resp = yield axios.get(url, { headers: { 'API-KEY': apiKey } });
|
|
116
116
|
const response = resp.data;
|
|
117
117
|
const txs = response.data.outputs;
|
|
118
118
|
if (txs.length === 10) {
|
|
@@ -143,7 +143,7 @@ const getUnspentTxs$1 = ({ apiKey, sochainUrl, network, address, page, }) => __a
|
|
|
143
143
|
*/
|
|
144
144
|
const broadcastTx$2 = ({ apiKey, sochainUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
145
145
|
const url = `${sochainUrl}/broadcast_transaction/${network}`;
|
|
146
|
-
const response = yield
|
|
146
|
+
const response = yield axios.post(url, { tx_hex: txHex }, { headers: { 'API-KEY': apiKey } });
|
|
147
147
|
const broadcastResponse = response.data;
|
|
148
148
|
return broadcastResponse.tx_hex;
|
|
149
149
|
});
|
|
@@ -380,7 +380,7 @@ const isErrorResponse = (response) => {
|
|
|
380
380
|
*/
|
|
381
381
|
const getAccount = ({ haskoinUrl, network, address }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
382
382
|
const url = `${haskoinUrl}/${network}/address/${address}/balance`;
|
|
383
|
-
const result = (yield
|
|
383
|
+
const result = (yield axios.get(url)).data;
|
|
384
384
|
if (!result || isErrorResponse(result))
|
|
385
385
|
throw new Error(`failed to query account by given address ${address}`);
|
|
386
386
|
return result;
|
|
@@ -395,7 +395,7 @@ const getAccount = ({ haskoinUrl, network, address }) => __awaiter(void 0, void
|
|
|
395
395
|
*/
|
|
396
396
|
const getAddress = ({ haskoinUrl, network, address }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
397
397
|
const url = `${haskoinUrl}/${network}/address/${address}/balance`;
|
|
398
|
-
const response = yield
|
|
398
|
+
const response = yield axios.get(url);
|
|
399
399
|
const addressResponse = response.data;
|
|
400
400
|
return addressResponse.data;
|
|
401
401
|
});
|
|
@@ -409,7 +409,7 @@ const getAddress = ({ haskoinUrl, network, address }) => __awaiter(void 0, void
|
|
|
409
409
|
* @throws {"failed to query transaction by a given hash"} thrown if failed to query transaction by a given hash
|
|
410
410
|
*/
|
|
411
411
|
const getTx$1 = ({ haskoinUrl, txId, network }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
412
|
-
const result = (yield
|
|
412
|
+
const result = (yield axios.get(`${haskoinUrl}/${network}/transaction/${txId}`)).data;
|
|
413
413
|
if (!result || isErrorResponse(result))
|
|
414
414
|
throw new Error(`failed to query transaction by a given hash ${txId}`);
|
|
415
415
|
return result;
|
|
@@ -424,7 +424,7 @@ const getTx$1 = ({ haskoinUrl, txId, network }) => __awaiter(void 0, void 0, voi
|
|
|
424
424
|
* @throws {"failed to query transaction by a given hash"} thrown if failed to query raw transaction by a given hash
|
|
425
425
|
*/
|
|
426
426
|
const getRawTransaction = ({ haskoinUrl, network, txId }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
|
-
const result = (yield
|
|
427
|
+
const result = (yield axios.get(`${haskoinUrl}/${network}/transaction/${txId}/raw`))
|
|
428
428
|
.data;
|
|
429
429
|
if (!result || isErrorResponse(result))
|
|
430
430
|
throw new Error(`failed to query transaction by a given hash ${txId}`);
|
|
@@ -443,7 +443,7 @@ const getRawTransaction = ({ haskoinUrl, network, txId }) => __awaiter(void 0, v
|
|
|
443
443
|
const getTxs$1 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
444
444
|
const params = { limit: `${limit}`, offset: `${offset}` };
|
|
445
445
|
const url = `${haskoinUrl}/${network}/address/${address}/transactions/full`;
|
|
446
|
-
const result = (yield
|
|
446
|
+
const result = (yield axios.get(url, { params })).data;
|
|
447
447
|
if (!result || isErrorResponse(result))
|
|
448
448
|
throw new Error('failed to query transactions');
|
|
449
449
|
return result;
|
|
@@ -454,7 +454,7 @@ const getTxs$1 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter
|
|
|
454
454
|
* @returns Returns BaseAmount
|
|
455
455
|
*/
|
|
456
456
|
const getBalance$1 = ({ haskoinUrl, haskoinNetwork, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
457
|
-
const { data: { confirmed, unconfirmed }, } = yield
|
|
457
|
+
const { data: { confirmed, unconfirmed }, } = yield axios.get(`${haskoinUrl}/${haskoinNetwork}/address/${address}/balance`);
|
|
458
458
|
const confirmedAmount = xchainUtil.baseAmount(confirmed, assetDecimals);
|
|
459
459
|
const unconfirmedAmount = xchainUtil.baseAmount(unconfirmed, assetDecimals);
|
|
460
460
|
return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
|
|
@@ -472,7 +472,7 @@ const getUnspentTxs = ({ haskoinUrl, network, address }) => __awaiter(void 0, vo
|
|
|
472
472
|
// Get transaction count for a given address.
|
|
473
473
|
const account = yield getAccount({ haskoinUrl, network, address });
|
|
474
474
|
// Set limit to the transaction count to be all the utxos.
|
|
475
|
-
const result = (yield
|
|
475
|
+
const result = (yield axios.get(`${haskoinUrl}/${network}/address/${address}/unspent?limit${account === null || account === void 0 ? void 0 : account.utxo}`)).data;
|
|
476
476
|
if (!result || isErrorResponse(result))
|
|
477
477
|
throw new Error('failed to query unspent transactions');
|
|
478
478
|
return result;
|
|
@@ -579,7 +579,7 @@ const getUnspentTransactions = ({ haskoinUrl, network, address }) => __awaiter(v
|
|
|
579
579
|
// Get transaction count for a given address.
|
|
580
580
|
const account = yield getAccount({ haskoinUrl, network, address });
|
|
581
581
|
// Set limit to the transaction count to be all the utxos.
|
|
582
|
-
const result = (yield
|
|
582
|
+
const result = (yield axios.get(`${haskoinUrl}/${network}/address/${address}/unspent?limit${account === null || account === void 0 ? void 0 : account.utxo}`)).data;
|
|
583
583
|
if (!result || isErrorResponse(result))
|
|
584
584
|
throw new Error('failed to query unspent transactions');
|
|
585
585
|
return result;
|
|
@@ -600,7 +600,7 @@ const broadcastTx$1 = ({ txHex, haskoinUrl, haskoinNetwork, }) => __awaiter(void
|
|
|
600
600
|
var _a;
|
|
601
601
|
const MAX_RETRIES = 5;
|
|
602
602
|
let retries = 0;
|
|
603
|
-
const axiosInstance =
|
|
603
|
+
const axiosInstance = axios.create();
|
|
604
604
|
const url = `${haskoinUrl}/${haskoinNetwork}/transactions`;
|
|
605
605
|
while (retries < MAX_RETRIES) {
|
|
606
606
|
try {
|
|
@@ -784,7 +784,7 @@ const getTx = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void
|
|
|
784
784
|
if (apiKey)
|
|
785
785
|
params['token'] = apiKey;
|
|
786
786
|
const url = `${baseUrl}/${network}/txs/${hash}`;
|
|
787
|
-
const response = yield
|
|
787
|
+
const response = yield axios.get(url, { params });
|
|
788
788
|
const tx = response.data;
|
|
789
789
|
return tx;
|
|
790
790
|
});
|
|
@@ -804,7 +804,7 @@ const getTxs = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspent
|
|
|
804
804
|
params['token'] = apiKey;
|
|
805
805
|
if (beforeBlock)
|
|
806
806
|
params['before'] = `${beforeBlock}`;
|
|
807
|
-
const response = yield
|
|
807
|
+
const response = yield axios.get(url, { params });
|
|
808
808
|
const txs = response.data;
|
|
809
809
|
return txs;
|
|
810
810
|
});
|
|
@@ -823,7 +823,7 @@ const getBalance = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDec
|
|
|
823
823
|
const url = `${baseUrl}/${network}/addrs/${address}/balance`;
|
|
824
824
|
if (apiKey)
|
|
825
825
|
params['token'] = apiKey;
|
|
826
|
-
const response = yield
|
|
826
|
+
const response = yield axios.get(url, { params });
|
|
827
827
|
const balanceResponse = response.data;
|
|
828
828
|
const confirmedAmount = xchainUtil.baseAmount(balanceResponse.balance, assetDecimals);
|
|
829
829
|
const finalBalance = xchainUtil.baseAmount(balanceResponse.final_balance, assetDecimals);
|
|
@@ -834,7 +834,7 @@ const broadcastTx = ({ apiKey, baseUrl, network, txHex, }) => __awaiter(void 0,
|
|
|
834
834
|
const url = `${baseUrl}/${network}/txs/push`;
|
|
835
835
|
if (apiKey)
|
|
836
836
|
params['token'] = apiKey;
|
|
837
|
-
const response = yield
|
|
837
|
+
const response = yield axios.post(url, { tx: txHex }, { params });
|
|
838
838
|
const broadcastResponse = response.data;
|
|
839
839
|
return broadcastResponse.tx.hash;
|
|
840
840
|
});
|
|
@@ -848,7 +848,7 @@ const getBlockchainData = ({ baseUrl, apiKey, }) => __awaiter(void 0, void 0, vo
|
|
|
848
848
|
const params = {};
|
|
849
849
|
if (apiKey)
|
|
850
850
|
params['token'] = apiKey;
|
|
851
|
-
const chainResponse = yield
|
|
851
|
+
const chainResponse = yield axios.get(`${baseUrl}`, { params });
|
|
852
852
|
return chainResponse.data;
|
|
853
853
|
});
|
|
854
854
|
|
|
@@ -1060,7 +1060,7 @@ class BlockcypherProvider {
|
|
|
1060
1060
|
//an errors means no more results
|
|
1061
1061
|
}
|
|
1062
1062
|
//note: blockcypher has rate of 3 req/sec --> https://www.blockcypher.com/dev/bitcoin/#rate-limits-and-tokens
|
|
1063
|
-
const batchResult = yield
|
|
1063
|
+
const batchResult = yield PromisePool.for(txHashesToFetch)
|
|
1064
1064
|
.withConcurrency(3)
|
|
1065
1065
|
.useCorrespondingResults()
|
|
1066
1066
|
.process((hash) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1095,7 +1095,7 @@ exports.BlockcypherNetwork = void 0;
|
|
|
1095
1095
|
* @returns {GetFeeEstimateResponse} Get fee estimate response
|
|
1096
1096
|
*/
|
|
1097
1097
|
const getFeeEstimate = (baseUrl, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1098
|
-
const response = yield
|
|
1098
|
+
const response = yield axios.get(`${baseUrl}/tx/fee`, { params: request });
|
|
1099
1099
|
return response.data;
|
|
1100
1100
|
});
|
|
1101
1101
|
|
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.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.esm.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"url": "git@github.com:xchainjs/xchainjs-lib.git"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "yarn clean && rollup -c",
|
|
20
|
+
"build": "yarn clean && rollup -c --bundleConfigAsCjs",
|
|
21
21
|
"build:release": "yarn exec rm -rf release && yarn pack && yarn exec \"mkdir release && tar zxvf package.tgz --directory release && rm package.tgz\"",
|
|
22
22
|
"clean": "rm -rf .turbo && rm -rf lib",
|
|
23
23
|
"e2e": "jest --config jest.config.e2e.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.6",
|
|
33
|
+
"@xchainjs/xchain-util": "1.0.5",
|
|
34
34
|
"axios": "1.7.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|