@xchainjs/xchain-utxo-providers 2.0.17 → 2.1.0
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 +288 -40
- package/lib/index.js +292 -43
- package/lib/providers/blockbook/blockbook-api-types.d.ts +73 -0
- package/lib/providers/blockbook/blockbook-api.d.ts +38 -0
- package/lib/providers/blockbook/blockbook-data-provider.d.ts +29 -0
- package/lib/providers/index.d.ts +1 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -62,7 +62,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
62
62
|
* @param {string} hash The transaction hash.
|
|
63
63
|
* @returns {Transactions}
|
|
64
64
|
*/
|
|
65
|
-
const getTx$
|
|
65
|
+
const getTx$4 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, sochainUrl, network, hash }) {
|
|
66
66
|
const url = `${sochainUrl}/transaction/${network}/${hash}`;
|
|
67
67
|
const response = yield axios__default.default.get(url, { headers: { 'API-KEY': apiKey } });
|
|
68
68
|
const tx = response.data;
|
|
@@ -78,7 +78,7 @@ const getTx$3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, soc
|
|
|
78
78
|
* @param {string} hash The transaction hash.
|
|
79
79
|
* @returns {Transactions}
|
|
80
80
|
*/
|
|
81
|
-
const getTxs$
|
|
81
|
+
const getTxs$4 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, sochainUrl, network, page, }) {
|
|
82
82
|
const url = `${sochainUrl}/transactions/${network}/${address}/${page}`; //TODO support paging
|
|
83
83
|
const response = yield axios__default.default.get(url, { headers: { 'API-KEY': apiKey } });
|
|
84
84
|
const txs = response.data;
|
|
@@ -95,7 +95,7 @@ const getTxs$3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, ad
|
|
|
95
95
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
96
96
|
* @returns {number}
|
|
97
97
|
*/
|
|
98
|
-
const getBalance$
|
|
98
|
+
const getBalance$4 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, sochainUrl, network, address, confirmedOnly, assetDecimals, }) {
|
|
99
99
|
const url = `${sochainUrl}/balance/${network}/${address}`;
|
|
100
100
|
const response = yield axios__default.default.get(url, { headers: { 'API-KEY': apiKey } });
|
|
101
101
|
const balanceResponse = response.data;
|
|
@@ -146,7 +146,7 @@ const getUnspentTxs$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ api
|
|
|
146
146
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
147
147
|
* @returns {number}
|
|
148
148
|
*/
|
|
149
|
-
const broadcastTx$
|
|
149
|
+
const broadcastTx$4 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, sochainUrl, network, txHex, }) {
|
|
150
150
|
const url = `${sochainUrl}/broadcast_transaction/${network}`;
|
|
151
151
|
const response = yield axios__default.default.post(url, { tx_hex: txHex }, { headers: { 'API-KEY': apiKey } });
|
|
152
152
|
const broadcastResponse = response.data;
|
|
@@ -170,7 +170,7 @@ class SochainProvider {
|
|
|
170
170
|
}
|
|
171
171
|
broadcastTx(txHex) {
|
|
172
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
return yield broadcastTx$
|
|
173
|
+
return yield broadcastTx$4({
|
|
174
174
|
apiKey: this._apiKey,
|
|
175
175
|
sochainUrl: this.baseUrl,
|
|
176
176
|
network: this.sochainNetwork,
|
|
@@ -206,7 +206,7 @@ class SochainProvider {
|
|
|
206
206
|
getBalance(address, confirmedOnly) {
|
|
207
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
208
|
try {
|
|
209
|
-
const amount = yield getBalance$
|
|
209
|
+
const amount = yield getBalance$4({
|
|
210
210
|
apiKey: this._apiKey,
|
|
211
211
|
sochainUrl: this.baseUrl,
|
|
212
212
|
network: this.sochainNetwork,
|
|
@@ -242,7 +242,7 @@ class SochainProvider {
|
|
|
242
242
|
let page = firstPage;
|
|
243
243
|
try {
|
|
244
244
|
while (page <= lastPage) {
|
|
245
|
-
const response = yield getTxs$
|
|
245
|
+
const response = yield getTxs$4({
|
|
246
246
|
apiKey: this._apiKey,
|
|
247
247
|
sochainUrl: this.baseUrl,
|
|
248
248
|
network: this.sochainNetwork,
|
|
@@ -284,7 +284,7 @@ class SochainProvider {
|
|
|
284
284
|
getTransactionData(txId) {
|
|
285
285
|
return __awaiter(this, void 0, void 0, function* () {
|
|
286
286
|
try {
|
|
287
|
-
const rawTx = yield getTx$
|
|
287
|
+
const rawTx = yield getTx$4({
|
|
288
288
|
apiKey: this._apiKey,
|
|
289
289
|
sochainUrl: this.baseUrl,
|
|
290
290
|
network: this.sochainNetwork,
|
|
@@ -411,7 +411,7 @@ const getAddress = (_a) => __awaiter(void 0, [_a], void 0, function* ({ haskoinU
|
|
|
411
411
|
*
|
|
412
412
|
* @throws {"failed to query transaction by a given hash"} thrown if failed to query transaction by a given hash
|
|
413
413
|
*/
|
|
414
|
-
const getTx$
|
|
414
|
+
const getTx$3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ haskoinUrl, txId, network }) {
|
|
415
415
|
const result = (yield axios__default.default.get(`${haskoinUrl}/${network}/transaction/${txId}`)).data;
|
|
416
416
|
if (!result || isErrorResponse(result))
|
|
417
417
|
throw new Error(`failed to query transaction by a given hash ${txId}`);
|
|
@@ -443,7 +443,7 @@ const getRawTransaction = (_a) => __awaiter(void 0, [_a], void 0, function* ({ h
|
|
|
443
443
|
* @param {string} hash The transaction hash.
|
|
444
444
|
* @returns {Transactions}
|
|
445
445
|
*/
|
|
446
|
-
const getTxs$
|
|
446
|
+
const getTxs$3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ address, haskoinUrl, network, limit, offset, }) {
|
|
447
447
|
const params = { limit: `${limit}`, offset: `${offset}` };
|
|
448
448
|
const url = `${haskoinUrl}/${network}/address/${address}/transactions/full`;
|
|
449
449
|
const result = (yield axios__default.default.get(url, { params })).data;
|
|
@@ -456,7 +456,7 @@ const getTxs$2 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ address, h
|
|
|
456
456
|
* @param param
|
|
457
457
|
* @returns Returns BaseAmount
|
|
458
458
|
*/
|
|
459
|
-
const getBalance$
|
|
459
|
+
const getBalance$3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ haskoinUrl, haskoinNetwork, address, confirmedOnly, assetDecimals, }) {
|
|
460
460
|
const { data: { confirmed, unconfirmed }, } = yield axios__default.default.get(`${haskoinUrl}/${haskoinNetwork}/address/${address}/balance`);
|
|
461
461
|
const confirmedAmount = xchainUtil.baseAmount(confirmed, assetDecimals);
|
|
462
462
|
const unconfirmedAmount = xchainUtil.baseAmount(unconfirmed, assetDecimals);
|
|
@@ -489,7 +489,7 @@ const getUnspentTxs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ hasko
|
|
|
489
489
|
* @returns {TxConfirmedStatus}
|
|
490
490
|
*/
|
|
491
491
|
const getIsTxConfirmed = (_a) => __awaiter(void 0, [_a], void 0, function* ({ haskoinUrl, network, txId }) {
|
|
492
|
-
const tx = yield getTx$
|
|
492
|
+
const tx = yield getTx$3({ haskoinUrl, network, txId });
|
|
493
493
|
return {
|
|
494
494
|
network: network,
|
|
495
495
|
txid: txId,
|
|
@@ -599,7 +599,7 @@ const getUnspentTransactions = (_a) => __awaiter(void 0, [_a], void 0, function*
|
|
|
599
599
|
* @param {BroadcastTxParams} params
|
|
600
600
|
* @returns {TxHash} Transaction hash.
|
|
601
601
|
*/
|
|
602
|
-
const broadcastTx$
|
|
602
|
+
const broadcastTx$3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ txHex, haskoinUrl, haskoinNetwork, }) {
|
|
603
603
|
var _b;
|
|
604
604
|
const MAX_RETRIES = 5;
|
|
605
605
|
let retries = 0;
|
|
@@ -635,7 +635,7 @@ class HaskoinProvider {
|
|
|
635
635
|
}
|
|
636
636
|
broadcastTx(txHex) {
|
|
637
637
|
return __awaiter(this, void 0, void 0, function* () {
|
|
638
|
-
return yield broadcastTx$
|
|
638
|
+
return yield broadcastTx$3({
|
|
639
639
|
haskoinUrl: this.baseUrl,
|
|
640
640
|
haskoinNetwork: this.haskoinNetwork,
|
|
641
641
|
txHex,
|
|
@@ -665,7 +665,7 @@ class HaskoinProvider {
|
|
|
665
665
|
}
|
|
666
666
|
getBalance(address, confirmedOnly) {
|
|
667
667
|
return __awaiter(this, void 0, void 0, function* () {
|
|
668
|
-
const amount = yield getBalance$
|
|
668
|
+
const amount = yield getBalance$3({
|
|
669
669
|
haskoinUrl: this.baseUrl,
|
|
670
670
|
haskoinNetwork: this.haskoinNetwork,
|
|
671
671
|
address,
|
|
@@ -691,7 +691,7 @@ class HaskoinProvider {
|
|
|
691
691
|
throw Error('cannot fetch more than last 2000 txs');
|
|
692
692
|
if (offset < 0 || limit < 0)
|
|
693
693
|
throw Error('ofset and limit must be equal or greater than 0');
|
|
694
|
-
const response = yield getTxs$
|
|
694
|
+
const response = yield getTxs$3({
|
|
695
695
|
address: `${params === null || params === void 0 ? void 0 : params.address}`,
|
|
696
696
|
haskoinUrl: this.baseUrl,
|
|
697
697
|
network: this.haskoinNetwork,
|
|
@@ -730,7 +730,7 @@ class HaskoinProvider {
|
|
|
730
730
|
getTransactionData(txId) {
|
|
731
731
|
return __awaiter(this, void 0, void 0, function* () {
|
|
732
732
|
try {
|
|
733
|
-
const rawTx = yield getTx$
|
|
733
|
+
const rawTx = yield getTx$3({
|
|
734
734
|
haskoinUrl: this.baseUrl,
|
|
735
735
|
network: this.haskoinNetwork,
|
|
736
736
|
txId: txId,
|
|
@@ -781,7 +781,7 @@ class HaskoinProvider {
|
|
|
781
781
|
* @param {string} hash The transaction hash.
|
|
782
782
|
* @returns {Transactions}
|
|
783
783
|
*/
|
|
784
|
-
const getTx$
|
|
784
|
+
const getTx$2 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, network, hash, limit = 20 }) {
|
|
785
785
|
const params = { includeHex: 'true', limit: limit.toString() };
|
|
786
786
|
if (apiKey)
|
|
787
787
|
params['token'] = apiKey;
|
|
@@ -799,7 +799,7 @@ const getTx$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, bas
|
|
|
799
799
|
* @param {string} hash The transaction hash.
|
|
800
800
|
* @returns {Transactions}
|
|
801
801
|
*/
|
|
802
|
-
const getTxs$
|
|
802
|
+
const getTxs$2 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspentOnly, }) {
|
|
803
803
|
const params = { limit: `${limit}`, unspentOnly: `${unspentOnly}` };
|
|
804
804
|
const url = `${baseUrl}/${network}/addrs/${address}`;
|
|
805
805
|
if (apiKey)
|
|
@@ -820,7 +820,7 @@ const getTxs$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, ad
|
|
|
820
820
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
821
821
|
* @returns {number}
|
|
822
822
|
*/
|
|
823
|
-
const getBalance$
|
|
823
|
+
const getBalance$2 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, network, address, confirmedOnly, assetDecimals, }) {
|
|
824
824
|
const params = {};
|
|
825
825
|
const url = `${baseUrl}/${network}/addrs/${address}/balance`;
|
|
826
826
|
if (apiKey)
|
|
@@ -831,7 +831,7 @@ const getBalance$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey
|
|
|
831
831
|
const finalBalance = xchainUtil.baseAmount(balanceResponse.final_balance, assetDecimals);
|
|
832
832
|
return confirmedOnly ? confirmedAmount : finalBalance;
|
|
833
833
|
});
|
|
834
|
-
const broadcastTx$
|
|
834
|
+
const broadcastTx$2 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, network, txHex, }) {
|
|
835
835
|
const params = {};
|
|
836
836
|
const url = `${baseUrl}/${network}/txs/push`;
|
|
837
837
|
if (apiKey)
|
|
@@ -871,7 +871,7 @@ class BlockcypherProvider {
|
|
|
871
871
|
}
|
|
872
872
|
broadcastTx(txHex) {
|
|
873
873
|
return __awaiter(this, void 0, void 0, function* () {
|
|
874
|
-
return yield broadcastTx$
|
|
874
|
+
return yield broadcastTx$2({
|
|
875
875
|
apiKey: this._apiKey,
|
|
876
876
|
baseUrl: this.baseUrl,
|
|
877
877
|
network: this.blockcypherNetwork,
|
|
@@ -893,7 +893,7 @@ class BlockcypherProvider {
|
|
|
893
893
|
}
|
|
894
894
|
getBalance(address, confirmedOnly) {
|
|
895
895
|
return __awaiter(this, void 0, void 0, function* () {
|
|
896
|
-
const amount = yield getBalance$
|
|
896
|
+
const amount = yield getBalance$2({
|
|
897
897
|
apiKey: this._apiKey,
|
|
898
898
|
baseUrl: this.baseUrl,
|
|
899
899
|
network: this.blockcypherNetwork,
|
|
@@ -931,7 +931,7 @@ class BlockcypherProvider {
|
|
|
931
931
|
getTransactionData(txId) {
|
|
932
932
|
return __awaiter(this, void 0, void 0, function* () {
|
|
933
933
|
try {
|
|
934
|
-
const rawTx = yield getTx$
|
|
934
|
+
const rawTx = yield getTx$2({
|
|
935
935
|
apiKey: this._apiKey,
|
|
936
936
|
baseUrl: this.baseUrl,
|
|
937
937
|
network: this.blockcypherNetwork,
|
|
@@ -1036,7 +1036,7 @@ class BlockcypherProvider {
|
|
|
1036
1036
|
throw Error('ofset and limit must be equal or greater than 0');
|
|
1037
1037
|
const txHashesToFetch = [];
|
|
1038
1038
|
try {
|
|
1039
|
-
const response = yield getTxs$
|
|
1039
|
+
const response = yield getTxs$2({
|
|
1040
1040
|
apiKey: this._apiKey,
|
|
1041
1041
|
baseUrl: this.baseUrl,
|
|
1042
1042
|
network: this.blockcypherNetwork,
|
|
@@ -1069,7 +1069,7 @@ class BlockcypherProvider {
|
|
|
1069
1069
|
.useCorrespondingResults()
|
|
1070
1070
|
.process((hash) => __awaiter(this, void 0, void 0, function* () {
|
|
1071
1071
|
yield this.delay(1000);
|
|
1072
|
-
const rawTx = yield getTx$
|
|
1072
|
+
const rawTx = yield getTx$2({
|
|
1073
1073
|
apiKey: this._apiKey,
|
|
1074
1074
|
baseUrl: this.baseUrl,
|
|
1075
1075
|
network: this.blockcypherNetwork,
|
|
@@ -1098,7 +1098,7 @@ exports.BlockcypherNetwork = void 0;
|
|
|
1098
1098
|
* @param {GetFeeEstimateRequest} request Get fee estimate params
|
|
1099
1099
|
* @returns {GetFeeEstimateResponse} Get fee estimate response
|
|
1100
1100
|
*/
|
|
1101
|
-
const getFeeEstimate = (baseUrl, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1101
|
+
const getFeeEstimate$1 = (baseUrl, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1102
1102
|
const response = yield axios__default.default.get(`${baseUrl}/tx/fee`, { params: request });
|
|
1103
1103
|
return response.data;
|
|
1104
1104
|
});
|
|
@@ -1115,7 +1115,7 @@ class BitgoProvider {
|
|
|
1115
1115
|
getFeeRates() {
|
|
1116
1116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1117
1117
|
var _a, _b, _c, _d;
|
|
1118
|
-
const gasFeeEstimateResponse = yield getFeeEstimate(`${this.baseUrl}/api/v2/${this.blockchainId}`, {
|
|
1118
|
+
const gasFeeEstimateResponse = yield getFeeEstimate$1(`${this.baseUrl}/api/v2/${this.blockchainId}`, {
|
|
1119
1119
|
numBlocks: 2,
|
|
1120
1120
|
});
|
|
1121
1121
|
const fastestRate = gasFeeEstimateResponse.feePerKb / 1000;
|
|
@@ -1176,7 +1176,7 @@ class BitgoProvider {
|
|
|
1176
1176
|
* @param {string} hash The transaction hash.
|
|
1177
1177
|
* @returns {Transactions}
|
|
1178
1178
|
*/
|
|
1179
|
-
const getTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, hash }) {
|
|
1179
|
+
const getTx$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, hash }) {
|
|
1180
1180
|
const url = `${baseUrl}/tx/${hash}`;
|
|
1181
1181
|
const response = yield axios__default.default.get(url, {
|
|
1182
1182
|
headers: {
|
|
@@ -1194,7 +1194,7 @@ const getTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseU
|
|
|
1194
1194
|
* @param {string} hash The transaction hash.
|
|
1195
1195
|
* @returns {Transactions}
|
|
1196
1196
|
*/
|
|
1197
|
-
const getTxs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, baseUrl, limit, }) {
|
|
1197
|
+
const getTxs$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, baseUrl, limit, }) {
|
|
1198
1198
|
const url = `${baseUrl}/address/${address}`;
|
|
1199
1199
|
const response = yield axios__default.default.get(url, {
|
|
1200
1200
|
params: {
|
|
@@ -1215,7 +1215,7 @@ const getTxs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, addr
|
|
|
1215
1215
|
* @param {string} address address.
|
|
1216
1216
|
* @returns {Transactions}
|
|
1217
1217
|
*/
|
|
1218
|
-
const getUTXOs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, baseUrl, isConfirmed = true, }) {
|
|
1218
|
+
const getUTXOs$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, baseUrl, isConfirmed = true, }) {
|
|
1219
1219
|
const url = `${baseUrl}/utxo/${address}`;
|
|
1220
1220
|
const response = yield axios__default.default.get(url, {
|
|
1221
1221
|
params: {
|
|
@@ -1237,7 +1237,7 @@ const getUTXOs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, ad
|
|
|
1237
1237
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
1238
1238
|
* @returns {number}
|
|
1239
1239
|
*/
|
|
1240
|
-
const getBalance = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, address, confirmedOnly = true, assetDecimals, }) {
|
|
1240
|
+
const getBalance$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, address, confirmedOnly = true, assetDecimals, }) {
|
|
1241
1241
|
const url = `${baseUrl}/address/${address}`;
|
|
1242
1242
|
const response = yield axios__default.default.get(url, {
|
|
1243
1243
|
headers: {
|
|
@@ -1275,7 +1275,7 @@ const getConsensusBranchId = (_a) => __awaiter(void 0, [_a], void 0, function* (
|
|
|
1275
1275
|
return undefined;
|
|
1276
1276
|
return parseInt(nextblock, 16);
|
|
1277
1277
|
});
|
|
1278
|
-
const broadcastTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, txHex, }) {
|
|
1278
|
+
const broadcastTx$1 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, txHex, }) {
|
|
1279
1279
|
const url = `${baseUrl}/sendtx/${txHex}`;
|
|
1280
1280
|
const response = yield axios__default.default.get(url, {
|
|
1281
1281
|
headers: {
|
|
@@ -1303,7 +1303,7 @@ class NownodesProvider {
|
|
|
1303
1303
|
}
|
|
1304
1304
|
broadcastTx(txHex) {
|
|
1305
1305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1306
|
-
return yield broadcastTx({
|
|
1306
|
+
return yield broadcastTx$1({
|
|
1307
1307
|
apiKey: this._apiKey,
|
|
1308
1308
|
baseUrl: this.baseUrl,
|
|
1309
1309
|
txHex,
|
|
@@ -1312,7 +1312,7 @@ class NownodesProvider {
|
|
|
1312
1312
|
}
|
|
1313
1313
|
getConfirmedUnspentTxs(address) {
|
|
1314
1314
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1315
|
-
const allUnspent = yield getUTXOs({
|
|
1315
|
+
const allUnspent = yield getUTXOs$1({
|
|
1316
1316
|
apiKey: this._apiKey,
|
|
1317
1317
|
baseUrl: this.baseUrl,
|
|
1318
1318
|
address: address,
|
|
@@ -1323,7 +1323,7 @@ class NownodesProvider {
|
|
|
1323
1323
|
}
|
|
1324
1324
|
getUnspentTxs(address) {
|
|
1325
1325
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1326
|
-
const allUnspent = yield getUTXOs({
|
|
1326
|
+
const allUnspent = yield getUTXOs$1({
|
|
1327
1327
|
apiKey: this._apiKey,
|
|
1328
1328
|
baseUrl: this.baseUrl,
|
|
1329
1329
|
address: address,
|
|
@@ -1334,7 +1334,7 @@ class NownodesProvider {
|
|
|
1334
1334
|
}
|
|
1335
1335
|
getBalance(address, confirmedOnly) {
|
|
1336
1336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1337
|
-
const amount = yield getBalance({
|
|
1337
|
+
const amount = yield getBalance$1({
|
|
1338
1338
|
apiKey: this._apiKey,
|
|
1339
1339
|
baseUrl: this.baseUrl,
|
|
1340
1340
|
address,
|
|
@@ -1358,7 +1358,7 @@ class NownodesProvider {
|
|
|
1358
1358
|
getTransactionData(txId) {
|
|
1359
1359
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1360
1360
|
try {
|
|
1361
|
-
const rawTx = yield getTx({
|
|
1361
|
+
const rawTx = yield getTx$1({
|
|
1362
1362
|
apiKey: this._apiKey,
|
|
1363
1363
|
baseUrl: this.baseUrl,
|
|
1364
1364
|
hash: txId,
|
|
@@ -1430,7 +1430,7 @@ class NownodesProvider {
|
|
|
1430
1430
|
if (offset < 0 || limit < 0)
|
|
1431
1431
|
throw Error('ofset and limit must be equal or greater than 0');
|
|
1432
1432
|
try {
|
|
1433
|
-
const transactions = yield getTxs({
|
|
1433
|
+
const transactions = yield getTxs$1({
|
|
1434
1434
|
apiKey: this._apiKey,
|
|
1435
1435
|
baseUrl: this.baseUrl,
|
|
1436
1436
|
address: `${params === null || params === void 0 ? void 0 : params.address}`,
|
|
@@ -1445,18 +1445,267 @@ class NownodesProvider {
|
|
|
1445
1445
|
}
|
|
1446
1446
|
}
|
|
1447
1447
|
|
|
1448
|
+
const makeHeaders = (apiKey) => (apiKey ? { 'api-key': apiKey } : {});
|
|
1449
|
+
const encodeAddressPathSegment = (address) => encodeURIComponent(address);
|
|
1450
|
+
const getTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, hash }) {
|
|
1451
|
+
const url = `${baseUrl}/tx/${hash}`;
|
|
1452
|
+
const response = yield axios__default.default.get(url, { headers: makeHeaders(apiKey) });
|
|
1453
|
+
return response.data;
|
|
1454
|
+
});
|
|
1455
|
+
const getTxs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, baseUrl, limit, }) {
|
|
1456
|
+
var _b;
|
|
1457
|
+
const url = `${baseUrl}/address/${encodeAddressPathSegment(address)}`;
|
|
1458
|
+
const response = yield axios__default.default.get(url, {
|
|
1459
|
+
params: { details: 'txs', pageSize: limit },
|
|
1460
|
+
headers: makeHeaders(apiKey),
|
|
1461
|
+
});
|
|
1462
|
+
const info = response.data;
|
|
1463
|
+
return { transactions: (_b = info.transactions) !== null && _b !== void 0 ? _b : [], total: info.txs };
|
|
1464
|
+
});
|
|
1465
|
+
const getUTXOs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, address, baseUrl, isConfirmed = true, }) {
|
|
1466
|
+
const url = `${baseUrl}/utxo/${encodeAddressPathSegment(address)}`;
|
|
1467
|
+
const response = yield axios__default.default.get(url, {
|
|
1468
|
+
params: { confirmed: isConfirmed },
|
|
1469
|
+
headers: makeHeaders(apiKey),
|
|
1470
|
+
});
|
|
1471
|
+
return response.data;
|
|
1472
|
+
});
|
|
1473
|
+
const getBalance = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, address, confirmedOnly = true, assetDecimals, }) {
|
|
1474
|
+
const url = `${baseUrl}/address/${encodeAddressPathSegment(address)}`;
|
|
1475
|
+
const response = yield axios__default.default.get(url, { params: { details: 'tokenBalances' }, headers: makeHeaders(apiKey) });
|
|
1476
|
+
const info = response.data;
|
|
1477
|
+
return confirmedOnly
|
|
1478
|
+
? xchainUtil.baseAmount(info.balance, assetDecimals)
|
|
1479
|
+
: xchainUtil.baseAmount(info.balance, assetDecimals).plus(xchainUtil.baseAmount(info.unconfirmedBalance, assetDecimals));
|
|
1480
|
+
});
|
|
1481
|
+
const broadcastTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, txHex, }) {
|
|
1482
|
+
const url = `${baseUrl}/sendtx/`;
|
|
1483
|
+
const response = yield axios__default.default.post(url, txHex, {
|
|
1484
|
+
headers: Object.assign(Object.assign({}, makeHeaders(apiKey)), { 'Content-Type': 'text/plain' }),
|
|
1485
|
+
});
|
|
1486
|
+
return response.data.result;
|
|
1487
|
+
});
|
|
1488
|
+
/**
|
|
1489
|
+
* Fetches fee estimate using Blockbook's V2 REST endpoint.
|
|
1490
|
+
*
|
|
1491
|
+
* Docs: https://github.com/trezor/blockbook/blob/master/docs/api.md
|
|
1492
|
+
*
|
|
1493
|
+
* @param numberOfBlocks Target block confirmation count
|
|
1494
|
+
* @returns Estimated fee rate in sat/byte
|
|
1495
|
+
*/
|
|
1496
|
+
const getFeeEstimate = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, numberOfBlocks, }) {
|
|
1497
|
+
const url = `${baseUrl}/estimatefee/${numberOfBlocks}`;
|
|
1498
|
+
const response = yield axios__default.default.get(url, { headers: makeHeaders(apiKey) });
|
|
1499
|
+
const dto = response.data;
|
|
1500
|
+
// result is in BTC/kB; convert to sat/byte
|
|
1501
|
+
const btcPerKb = parseFloat(dto.result);
|
|
1502
|
+
if (isNaN(btcPerKb) || btcPerKb <= 0) {
|
|
1503
|
+
throw new Error(`BlockbookProvider: invalid fee estimate: ${dto.result}`);
|
|
1504
|
+
}
|
|
1505
|
+
return (btcPerKb * 1e8) / 1000;
|
|
1506
|
+
});
|
|
1507
|
+
|
|
1508
|
+
class BlockbookProvider {
|
|
1509
|
+
constructor(baseUrl, asset, assetDecimals, options) {
|
|
1510
|
+
this.baseUrl = baseUrl;
|
|
1511
|
+
this._apiKey = options === null || options === void 0 ? void 0 : options.apiKey;
|
|
1512
|
+
this.asset = asset;
|
|
1513
|
+
this.assetDecimals = assetDecimals;
|
|
1514
|
+
this.normalizeAddressForApi = options === null || options === void 0 ? void 0 : options.normalizeAddressForApi;
|
|
1515
|
+
}
|
|
1516
|
+
toApiAddress(address) {
|
|
1517
|
+
return this.normalizeAddressForApi ? this.normalizeAddressForApi(address) : address;
|
|
1518
|
+
}
|
|
1519
|
+
get apiKey() {
|
|
1520
|
+
return this._apiKey;
|
|
1521
|
+
}
|
|
1522
|
+
set apiKey(value) {
|
|
1523
|
+
this._apiKey = value;
|
|
1524
|
+
}
|
|
1525
|
+
broadcastTx(txHex) {
|
|
1526
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1527
|
+
return yield broadcastTx({
|
|
1528
|
+
apiKey: this._apiKey,
|
|
1529
|
+
baseUrl: this.baseUrl,
|
|
1530
|
+
txHex,
|
|
1531
|
+
});
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
getConfirmedUnspentTxs(address) {
|
|
1535
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1536
|
+
const addr = this.toApiAddress(address);
|
|
1537
|
+
const utxos = yield getUTXOs({
|
|
1538
|
+
apiKey: this._apiKey,
|
|
1539
|
+
baseUrl: this.baseUrl,
|
|
1540
|
+
address: addr,
|
|
1541
|
+
isConfirmed: true,
|
|
1542
|
+
});
|
|
1543
|
+
return yield this.mapUTXOs(utxos);
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
getUnspentTxs(address) {
|
|
1547
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1548
|
+
const addr = this.toApiAddress(address);
|
|
1549
|
+
const utxos = yield getUTXOs({
|
|
1550
|
+
apiKey: this._apiKey,
|
|
1551
|
+
baseUrl: this.baseUrl,
|
|
1552
|
+
address: addr,
|
|
1553
|
+
isConfirmed: false,
|
|
1554
|
+
});
|
|
1555
|
+
return yield this.mapUTXOs(utxos);
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
getBalance(address, confirmedOnly) {
|
|
1559
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1560
|
+
const addr = this.toApiAddress(address);
|
|
1561
|
+
const amount = yield getBalance({
|
|
1562
|
+
apiKey: this._apiKey,
|
|
1563
|
+
baseUrl: this.baseUrl,
|
|
1564
|
+
address: addr,
|
|
1565
|
+
confirmedOnly: confirmedOnly !== undefined ? confirmedOnly : true,
|
|
1566
|
+
assetDecimals: this.assetDecimals,
|
|
1567
|
+
});
|
|
1568
|
+
return [{ amount, asset: this.asset }];
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
getTransactions(params) {
|
|
1572
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1573
|
+
const { transactions: rawTxs, total } = yield this.getRawTransactions(params);
|
|
1574
|
+
const txs = rawTxs.map((tx) => this.mapTransactionToTx(tx));
|
|
1575
|
+
return { total, txs };
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
getTransactionData(txId) {
|
|
1579
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1580
|
+
const rawTx = yield getTx({
|
|
1581
|
+
apiKey: this._apiKey,
|
|
1582
|
+
baseUrl: this.baseUrl,
|
|
1583
|
+
hash: txId,
|
|
1584
|
+
});
|
|
1585
|
+
return this.mapTransactionToTx(rawTx);
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
getFeeRate(feeOption) {
|
|
1589
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1590
|
+
return getFeeEstimate({
|
|
1591
|
+
apiKey: this._apiKey,
|
|
1592
|
+
baseUrl: this.baseUrl,
|
|
1593
|
+
numberOfBlocks: BlockbookProvider.BLOCK_TARGETS[feeOption],
|
|
1594
|
+
});
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
getFeeRates() {
|
|
1598
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1599
|
+
const [average, fast, fastest] = yield Promise.all([
|
|
1600
|
+
this.getFeeRate(xchainClient.FeeOption.Average),
|
|
1601
|
+
this.getFeeRate(xchainClient.FeeOption.Fast),
|
|
1602
|
+
this.getFeeRate(xchainClient.FeeOption.Fastest),
|
|
1603
|
+
]);
|
|
1604
|
+
return {
|
|
1605
|
+
[xchainClient.FeeOption.Average]: average,
|
|
1606
|
+
[xchainClient.FeeOption.Fast]: fast,
|
|
1607
|
+
[xchainClient.FeeOption.Fastest]: fastest,
|
|
1608
|
+
};
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
mapTransactionToTx(rawTx) {
|
|
1612
|
+
return {
|
|
1613
|
+
asset: this.asset,
|
|
1614
|
+
from: rawTx.vin
|
|
1615
|
+
.filter((i) => { var _a; return i.isAddress && ((_a = i.addresses) === null || _a === void 0 ? void 0 : _a.length) > 0; })
|
|
1616
|
+
.map((i) => ({
|
|
1617
|
+
from: i.addresses[0],
|
|
1618
|
+
amount: xchainUtil.baseAmount(i.value, this.assetDecimals),
|
|
1619
|
+
})),
|
|
1620
|
+
to: rawTx.vout
|
|
1621
|
+
.filter((i) => { var _a; return i.isAddress && ((_a = i.addresses) === null || _a === void 0 ? void 0 : _a.length) > 0; })
|
|
1622
|
+
.map((i) => ({ to: i.addresses[0], amount: xchainUtil.baseAmount(i.value, this.assetDecimals) })),
|
|
1623
|
+
date: rawTx.blockTime ? new Date(rawTx.blockTime * 1000) : new Date(0),
|
|
1624
|
+
type: xchainClient.TxType.Transfer,
|
|
1625
|
+
hash: rawTx.txid,
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
mapUTXOs(utxos) {
|
|
1629
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1630
|
+
const result = [];
|
|
1631
|
+
const txCache = new Map();
|
|
1632
|
+
for (const utxo of utxos) {
|
|
1633
|
+
let tx = txCache.get(utxo.txid);
|
|
1634
|
+
if (!tx) {
|
|
1635
|
+
// Rate-limit: pause between consecutive fetches to avoid overwhelming the node
|
|
1636
|
+
if (txCache.size > 0)
|
|
1637
|
+
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
1638
|
+
tx = yield getTx({
|
|
1639
|
+
apiKey: this._apiKey,
|
|
1640
|
+
baseUrl: this.baseUrl,
|
|
1641
|
+
hash: utxo.txid,
|
|
1642
|
+
});
|
|
1643
|
+
txCache.set(utxo.txid, tx);
|
|
1644
|
+
}
|
|
1645
|
+
const output = tx.vout.find((vout) => vout.n === utxo.vout);
|
|
1646
|
+
if (!(output === null || output === void 0 ? void 0 : output.hex)) {
|
|
1647
|
+
throw Error(`BlockbookProvider: could not resolve scriptPubKey for UTXO ${utxo.txid}:${utxo.vout}`);
|
|
1648
|
+
}
|
|
1649
|
+
const value = Number(utxo.value);
|
|
1650
|
+
result.push({
|
|
1651
|
+
hash: utxo.txid,
|
|
1652
|
+
index: utxo.vout,
|
|
1653
|
+
value,
|
|
1654
|
+
witnessUtxo: {
|
|
1655
|
+
value,
|
|
1656
|
+
script: Buffer.from(output.hex, 'hex'),
|
|
1657
|
+
},
|
|
1658
|
+
txHex: tx.hex,
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
return result;
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
getRawTransactions(params) {
|
|
1665
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1666
|
+
var _a;
|
|
1667
|
+
if (params === null || params === void 0 ? void 0 : params.startTime) {
|
|
1668
|
+
throw Error('BlockbookProvider: startTime is not supported');
|
|
1669
|
+
}
|
|
1670
|
+
const offset = (_a = params === null || params === void 0 ? void 0 : params.offset) !== null && _a !== void 0 ? _a : 0;
|
|
1671
|
+
const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
|
|
1672
|
+
if (offset + limit > 1000)
|
|
1673
|
+
throw Error('BlockbookProvider: cannot fetch more than the last 1000 txs');
|
|
1674
|
+
if (offset < 0 || limit < 0)
|
|
1675
|
+
throw Error('BlockbookProvider: offset and limit must be >= 0');
|
|
1676
|
+
const address = params === null || params === void 0 ? void 0 : params.address;
|
|
1677
|
+
if (!address)
|
|
1678
|
+
throw Error('BlockbookProvider: address is required');
|
|
1679
|
+
const addr = this.toApiAddress(address);
|
|
1680
|
+
const { transactions, total } = yield getTxs({
|
|
1681
|
+
apiKey: this._apiKey,
|
|
1682
|
+
baseUrl: this.baseUrl,
|
|
1683
|
+
address: addr,
|
|
1684
|
+
limit: offset + limit,
|
|
1685
|
+
});
|
|
1686
|
+
return { transactions: transactions.slice(offset, offset + limit), total };
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
BlockbookProvider.BLOCK_TARGETS = {
|
|
1691
|
+
[xchainClient.FeeOption.Average]: 5,
|
|
1692
|
+
[xchainClient.FeeOption.Fast]: 3,
|
|
1693
|
+
[xchainClient.FeeOption.Fastest]: 1,
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1448
1696
|
exports.BitgoProvider = BitgoProvider;
|
|
1697
|
+
exports.BlockbookProvider = BlockbookProvider;
|
|
1449
1698
|
exports.BlockcypherProvider = BlockcypherProvider;
|
|
1450
1699
|
exports.HaskoinProvider = HaskoinProvider;
|
|
1451
1700
|
exports.NownodesProvider = NownodesProvider;
|
|
1452
1701
|
exports.SochainProvider = SochainProvider;
|
|
1453
|
-
exports.broadcastTx = broadcastTx$
|
|
1702
|
+
exports.broadcastTx = broadcastTx$3;
|
|
1454
1703
|
exports.getAccount = getAccount;
|
|
1455
1704
|
exports.getAddress = getAddress;
|
|
1456
|
-
exports.getBalance = getBalance$
|
|
1705
|
+
exports.getBalance = getBalance$3;
|
|
1457
1706
|
exports.getConfirmedTxStatus = getConfirmedTxStatus;
|
|
1458
1707
|
exports.getConfirmedUnspentTxs = getConfirmedUnspentTxs;
|
|
1459
1708
|
exports.getIsTxConfirmed = getIsTxConfirmed;
|
|
1460
|
-
exports.getTx = getTx$
|
|
1461
|
-
exports.getTxs = getTxs$
|
|
1709
|
+
exports.getTx = getTx$3;
|
|
1710
|
+
exports.getTxs = getTxs$3;
|
|
1462
1711
|
exports.getUnspentTxs = getUnspentTxs;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { TxHash } from '@xchainjs/xchain-client';
|
|
2
|
+
export type BalanceParams = {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
address: string;
|
|
6
|
+
confirmedOnly: boolean;
|
|
7
|
+
assetDecimals: number;
|
|
8
|
+
};
|
|
9
|
+
export type TxHashParams = {
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
hash: TxHash;
|
|
13
|
+
};
|
|
14
|
+
export interface TxInput {
|
|
15
|
+
txid: string;
|
|
16
|
+
vout?: number;
|
|
17
|
+
n: number;
|
|
18
|
+
sequence: number;
|
|
19
|
+
addresses: string[];
|
|
20
|
+
isAddress: boolean;
|
|
21
|
+
value: string;
|
|
22
|
+
hex: string;
|
|
23
|
+
}
|
|
24
|
+
export interface TxOutput {
|
|
25
|
+
value: string;
|
|
26
|
+
n: number;
|
|
27
|
+
spent?: boolean;
|
|
28
|
+
hex: string;
|
|
29
|
+
addresses: string[];
|
|
30
|
+
isAddress: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface Transaction {
|
|
33
|
+
txid: string;
|
|
34
|
+
version: number;
|
|
35
|
+
vin: TxInput[];
|
|
36
|
+
vout: TxOutput[];
|
|
37
|
+
blockHash: string;
|
|
38
|
+
blockHeight: number;
|
|
39
|
+
confirmations: number;
|
|
40
|
+
blockTime: number;
|
|
41
|
+
size: number;
|
|
42
|
+
value: string;
|
|
43
|
+
valueIn: string;
|
|
44
|
+
fees: string;
|
|
45
|
+
hex: string;
|
|
46
|
+
}
|
|
47
|
+
export type AddressUTXO = {
|
|
48
|
+
txid: string;
|
|
49
|
+
vout: number;
|
|
50
|
+
value: string;
|
|
51
|
+
height: number;
|
|
52
|
+
confirmations: number;
|
|
53
|
+
};
|
|
54
|
+
export type GetAddressInfo = {
|
|
55
|
+
page: number;
|
|
56
|
+
totalPages: number;
|
|
57
|
+
itemsOnPage: number;
|
|
58
|
+
address: string;
|
|
59
|
+
balance: string;
|
|
60
|
+
totalReceived: string;
|
|
61
|
+
totalSent: string;
|
|
62
|
+
unconfirmedBalance: string;
|
|
63
|
+
unconfirmedTxs: number;
|
|
64
|
+
txs: number;
|
|
65
|
+
txids?: string[];
|
|
66
|
+
transactions?: Transaction[];
|
|
67
|
+
};
|
|
68
|
+
export type BroadcastDTO = {
|
|
69
|
+
result: string;
|
|
70
|
+
};
|
|
71
|
+
export type FeeEstimateDTO = {
|
|
72
|
+
result: string;
|
|
73
|
+
};
|