@xchainjs/xchain-utxo-providers 1.0.10 → 2.0.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 +262 -27
- package/lib/index.js +266 -30
- package/lib/providers/index.d.ts +1 -0
- package/lib/providers/nownodes/nownodes-api-types.d.ts +70 -0
- package/lib/providers/nownodes/nownodes-api.d.ts +54 -0
- package/lib/providers/nownodes/nownodes-data-provider.d.ts +22 -0
- package/package.json +4 -4
package/lib/index.esm.js
CHANGED
|
@@ -55,7 +55,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
55
55
|
* @param {string} hash The transaction hash.
|
|
56
56
|
* @returns {Transactions}
|
|
57
57
|
*/
|
|
58
|
-
const getTx$
|
|
58
|
+
const getTx$3 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
59
|
const url = `${sochainUrl}/transaction/${network}/${hash}`;
|
|
60
60
|
const response = yield axios.get(url, { headers: { 'API-KEY': apiKey } });
|
|
61
61
|
const tx = response.data;
|
|
@@ -71,7 +71,7 @@ const getTx$2 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, voi
|
|
|
71
71
|
* @param {string} hash The transaction hash.
|
|
72
72
|
* @returns {Transactions}
|
|
73
73
|
*/
|
|
74
|
-
const getTxs$
|
|
74
|
+
const getTxs$3 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
75
|
const url = `${sochainUrl}/transactions/${network}/${address}/${page}`; //TODO support paging
|
|
76
76
|
const response = yield axios.get(url, { headers: { 'API-KEY': apiKey } });
|
|
77
77
|
const txs = response.data;
|
|
@@ -88,7 +88,7 @@ const getTxs$2 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(
|
|
|
88
88
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
89
89
|
* @returns {number}
|
|
90
90
|
*/
|
|
91
|
-
const getBalance$
|
|
91
|
+
const getBalance$3 = ({ apiKey, sochainUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
92
|
const url = `${sochainUrl}/balance/${network}/${address}`;
|
|
93
93
|
const response = yield axios.get(url, { headers: { 'API-KEY': apiKey } });
|
|
94
94
|
const balanceResponse = response.data;
|
|
@@ -139,7 +139,7 @@ const getUnspentTxs$1 = ({ apiKey, sochainUrl, network, address, page, }) => __a
|
|
|
139
139
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
140
140
|
* @returns {number}
|
|
141
141
|
*/
|
|
142
|
-
const broadcastTx$
|
|
142
|
+
const broadcastTx$3 = ({ apiKey, sochainUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
143
|
const url = `${sochainUrl}/broadcast_transaction/${network}`;
|
|
144
144
|
const response = yield axios.post(url, { tx_hex: txHex }, { headers: { 'API-KEY': apiKey } });
|
|
145
145
|
const broadcastResponse = response.data;
|
|
@@ -165,7 +165,7 @@ class SochainProvider {
|
|
|
165
165
|
}
|
|
166
166
|
broadcastTx(txHex) {
|
|
167
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
-
return yield broadcastTx$
|
|
168
|
+
return yield broadcastTx$3({
|
|
169
169
|
apiKey: this._apiKey,
|
|
170
170
|
sochainUrl: this.baseUrl,
|
|
171
171
|
network: this.sochainNetwork,
|
|
@@ -201,7 +201,7 @@ class SochainProvider {
|
|
|
201
201
|
getBalance(address, confirmedOnly) {
|
|
202
202
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
203
|
try {
|
|
204
|
-
const amount = yield getBalance$
|
|
204
|
+
const amount = yield getBalance$3({
|
|
205
205
|
apiKey: this._apiKey,
|
|
206
206
|
sochainUrl: this.baseUrl,
|
|
207
207
|
network: this.sochainNetwork,
|
|
@@ -237,7 +237,7 @@ class SochainProvider {
|
|
|
237
237
|
let page = firstPage;
|
|
238
238
|
try {
|
|
239
239
|
while (page <= lastPage) {
|
|
240
|
-
const response = yield getTxs$
|
|
240
|
+
const response = yield getTxs$3({
|
|
241
241
|
apiKey: this._apiKey,
|
|
242
242
|
sochainUrl: this.baseUrl,
|
|
243
243
|
network: this.sochainNetwork,
|
|
@@ -279,7 +279,7 @@ class SochainProvider {
|
|
|
279
279
|
getTransactionData(txId) {
|
|
280
280
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
281
|
try {
|
|
282
|
-
const rawTx = yield getTx$
|
|
282
|
+
const rawTx = yield getTx$3({
|
|
283
283
|
apiKey: this._apiKey,
|
|
284
284
|
sochainUrl: this.baseUrl,
|
|
285
285
|
network: this.sochainNetwork,
|
|
@@ -406,7 +406,7 @@ const getAddress = ({ haskoinUrl, network, address }) => __awaiter(void 0, void
|
|
|
406
406
|
*
|
|
407
407
|
* @throws {"failed to query transaction by a given hash"} thrown if failed to query transaction by a given hash
|
|
408
408
|
*/
|
|
409
|
-
const getTx$
|
|
409
|
+
const getTx$2 = ({ haskoinUrl, txId, network }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
410
410
|
const result = (yield axios.get(`${haskoinUrl}/${network}/transaction/${txId}`)).data;
|
|
411
411
|
if (!result || isErrorResponse(result))
|
|
412
412
|
throw new Error(`failed to query transaction by a given hash ${txId}`);
|
|
@@ -438,7 +438,7 @@ const getRawTransaction = ({ haskoinUrl, network, txId }) => __awaiter(void 0, v
|
|
|
438
438
|
* @param {string} hash The transaction hash.
|
|
439
439
|
* @returns {Transactions}
|
|
440
440
|
*/
|
|
441
|
-
const getTxs$
|
|
441
|
+
const getTxs$2 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
442
442
|
const params = { limit: `${limit}`, offset: `${offset}` };
|
|
443
443
|
const url = `${haskoinUrl}/${network}/address/${address}/transactions/full`;
|
|
444
444
|
const result = (yield axios.get(url, { params })).data;
|
|
@@ -451,7 +451,7 @@ const getTxs$1 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter
|
|
|
451
451
|
* @param param
|
|
452
452
|
* @returns Returns BaseAmount
|
|
453
453
|
*/
|
|
454
|
-
const getBalance$
|
|
454
|
+
const getBalance$2 = ({ haskoinUrl, haskoinNetwork, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
455
455
|
const { data: { confirmed, unconfirmed }, } = yield axios.get(`${haskoinUrl}/${haskoinNetwork}/address/${address}/balance`);
|
|
456
456
|
const confirmedAmount = baseAmount(confirmed, assetDecimals);
|
|
457
457
|
const unconfirmedAmount = baseAmount(unconfirmed, assetDecimals);
|
|
@@ -484,7 +484,7 @@ const getUnspentTxs = ({ haskoinUrl, network, address }) => __awaiter(void 0, vo
|
|
|
484
484
|
* @returns {TxConfirmedStatus}
|
|
485
485
|
*/
|
|
486
486
|
const getIsTxConfirmed = ({ haskoinUrl, network, txId }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
|
-
const tx = yield getTx$
|
|
487
|
+
const tx = yield getTx$2({ haskoinUrl, network, txId });
|
|
488
488
|
return {
|
|
489
489
|
network: network,
|
|
490
490
|
txid: txId,
|
|
@@ -594,7 +594,7 @@ const getUnspentTransactions = ({ haskoinUrl, network, address }) => __awaiter(v
|
|
|
594
594
|
* @param {BroadcastTxParams} params
|
|
595
595
|
* @returns {TxHash} Transaction hash.
|
|
596
596
|
*/
|
|
597
|
-
const broadcastTx$
|
|
597
|
+
const broadcastTx$2 = ({ txHex, haskoinUrl, haskoinNetwork, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
598
598
|
var _a;
|
|
599
599
|
const MAX_RETRIES = 5;
|
|
600
600
|
let retries = 0;
|
|
@@ -631,7 +631,7 @@ class HaskoinProvider {
|
|
|
631
631
|
}
|
|
632
632
|
broadcastTx(txHex) {
|
|
633
633
|
return __awaiter(this, void 0, void 0, function* () {
|
|
634
|
-
return yield broadcastTx$
|
|
634
|
+
return yield broadcastTx$2({
|
|
635
635
|
haskoinUrl: this.baseUrl,
|
|
636
636
|
haskoinNetwork: this.haskoinNetwork,
|
|
637
637
|
txHex,
|
|
@@ -661,7 +661,7 @@ class HaskoinProvider {
|
|
|
661
661
|
}
|
|
662
662
|
getBalance(address, confirmedOnly) {
|
|
663
663
|
return __awaiter(this, void 0, void 0, function* () {
|
|
664
|
-
const amount = yield getBalance$
|
|
664
|
+
const amount = yield getBalance$2({
|
|
665
665
|
haskoinUrl: this.baseUrl,
|
|
666
666
|
haskoinNetwork: this.haskoinNetwork,
|
|
667
667
|
address,
|
|
@@ -687,7 +687,7 @@ class HaskoinProvider {
|
|
|
687
687
|
throw Error('cannot fetch more than last 2000 txs');
|
|
688
688
|
if (offset < 0 || limit < 0)
|
|
689
689
|
throw Error('ofset and limit must be equal or greater than 0');
|
|
690
|
-
const response = yield getTxs$
|
|
690
|
+
const response = yield getTxs$2({
|
|
691
691
|
address: `${params === null || params === void 0 ? void 0 : params.address}`,
|
|
692
692
|
haskoinUrl: this.baseUrl,
|
|
693
693
|
network: this.haskoinNetwork,
|
|
@@ -726,7 +726,7 @@ class HaskoinProvider {
|
|
|
726
726
|
getTransactionData(txId) {
|
|
727
727
|
return __awaiter(this, void 0, void 0, function* () {
|
|
728
728
|
try {
|
|
729
|
-
const rawTx = yield getTx$
|
|
729
|
+
const rawTx = yield getTx$2({
|
|
730
730
|
haskoinUrl: this.baseUrl,
|
|
731
731
|
network: this.haskoinNetwork,
|
|
732
732
|
txId: txId,
|
|
@@ -777,7 +777,7 @@ class HaskoinProvider {
|
|
|
777
777
|
* @param {string} hash The transaction hash.
|
|
778
778
|
* @returns {Transactions}
|
|
779
779
|
*/
|
|
780
|
-
const getTx = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
780
|
+
const getTx$1 = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
781
781
|
const params = { includeHex: 'true', limit: limit.toString() };
|
|
782
782
|
if (apiKey)
|
|
783
783
|
params['token'] = apiKey;
|
|
@@ -795,7 +795,7 @@ const getTx = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void
|
|
|
795
795
|
* @param {string} hash The transaction hash.
|
|
796
796
|
* @returns {Transactions}
|
|
797
797
|
*/
|
|
798
|
-
const getTxs = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspentOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
798
|
+
const getTxs$1 = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspentOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
799
799
|
const params = { limit: `${limit}`, unspentOnly: `${unspentOnly}` };
|
|
800
800
|
const url = `${baseUrl}/${network}/addrs/${address}`;
|
|
801
801
|
if (apiKey)
|
|
@@ -816,7 +816,7 @@ const getTxs = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspent
|
|
|
816
816
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
817
817
|
* @returns {number}
|
|
818
818
|
*/
|
|
819
|
-
const getBalance = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
819
|
+
const getBalance$1 = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
820
820
|
const params = {};
|
|
821
821
|
const url = `${baseUrl}/${network}/addrs/${address}/balance`;
|
|
822
822
|
if (apiKey)
|
|
@@ -827,7 +827,7 @@ const getBalance = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDec
|
|
|
827
827
|
const finalBalance = baseAmount(balanceResponse.final_balance, assetDecimals);
|
|
828
828
|
return confirmedOnly ? confirmedAmount : finalBalance;
|
|
829
829
|
});
|
|
830
|
-
const broadcastTx = ({ apiKey, baseUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
830
|
+
const broadcastTx$1 = ({ apiKey, baseUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
831
831
|
const params = {};
|
|
832
832
|
const url = `${baseUrl}/${network}/txs/push`;
|
|
833
833
|
if (apiKey)
|
|
@@ -869,7 +869,7 @@ class BlockcypherProvider {
|
|
|
869
869
|
}
|
|
870
870
|
broadcastTx(txHex) {
|
|
871
871
|
return __awaiter(this, void 0, void 0, function* () {
|
|
872
|
-
return yield broadcastTx({
|
|
872
|
+
return yield broadcastTx$1({
|
|
873
873
|
apiKey: this._apiKey,
|
|
874
874
|
baseUrl: this.baseUrl,
|
|
875
875
|
network: this.blockcypherNetwork,
|
|
@@ -891,7 +891,7 @@ class BlockcypherProvider {
|
|
|
891
891
|
}
|
|
892
892
|
getBalance(address, confirmedOnly) {
|
|
893
893
|
return __awaiter(this, void 0, void 0, function* () {
|
|
894
|
-
const amount = yield getBalance({
|
|
894
|
+
const amount = yield getBalance$1({
|
|
895
895
|
apiKey: this._apiKey,
|
|
896
896
|
baseUrl: this.baseUrl,
|
|
897
897
|
network: this.blockcypherNetwork,
|
|
@@ -929,7 +929,7 @@ class BlockcypherProvider {
|
|
|
929
929
|
getTransactionData(txId) {
|
|
930
930
|
return __awaiter(this, void 0, void 0, function* () {
|
|
931
931
|
try {
|
|
932
|
-
const rawTx = yield getTx({
|
|
932
|
+
const rawTx = yield getTx$1({
|
|
933
933
|
apiKey: this._apiKey,
|
|
934
934
|
baseUrl: this.baseUrl,
|
|
935
935
|
network: this.blockcypherNetwork,
|
|
@@ -1034,7 +1034,7 @@ class BlockcypherProvider {
|
|
|
1034
1034
|
throw Error('ofset and limit must be equal or greater than 0');
|
|
1035
1035
|
const txHashesToFetch = [];
|
|
1036
1036
|
try {
|
|
1037
|
-
const response = yield getTxs({
|
|
1037
|
+
const response = yield getTxs$1({
|
|
1038
1038
|
apiKey: this._apiKey,
|
|
1039
1039
|
baseUrl: this.baseUrl,
|
|
1040
1040
|
network: this.blockcypherNetwork,
|
|
@@ -1063,7 +1063,7 @@ class BlockcypherProvider {
|
|
|
1063
1063
|
.useCorrespondingResults()
|
|
1064
1064
|
.process((hash) => __awaiter(this, void 0, void 0, function* () {
|
|
1065
1065
|
yield this.delay(1000);
|
|
1066
|
-
const rawTx = yield getTx({
|
|
1066
|
+
const rawTx = yield getTx$1({
|
|
1067
1067
|
apiKey: this._apiKey,
|
|
1068
1068
|
baseUrl: this.baseUrl,
|
|
1069
1069
|
network: this.blockcypherNetwork,
|
|
@@ -1162,4 +1162,239 @@ class BitgoProvider {
|
|
|
1162
1162
|
}
|
|
1163
1163
|
}
|
|
1164
1164
|
|
|
1165
|
-
|
|
1165
|
+
/**
|
|
1166
|
+
* Get transaction by hash.
|
|
1167
|
+
*
|
|
1168
|
+
*
|
|
1169
|
+
* @param {string} baseUrl The sochain node url.
|
|
1170
|
+
* @param {string} hash The transaction hash.
|
|
1171
|
+
* @returns {Transactions}
|
|
1172
|
+
*/
|
|
1173
|
+
const getTx = ({ apiKey, baseUrl, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1174
|
+
const url = `${baseUrl}/tx/${hash}`;
|
|
1175
|
+
const response = yield axios.get(url, {
|
|
1176
|
+
headers: {
|
|
1177
|
+
'api-key': apiKey,
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
const tx = response.data;
|
|
1181
|
+
return tx;
|
|
1182
|
+
});
|
|
1183
|
+
/**
|
|
1184
|
+
* Get transactions
|
|
1185
|
+
*
|
|
1186
|
+
*
|
|
1187
|
+
* @param {string} baseUrl The sochain node url.
|
|
1188
|
+
* @param {string} hash The transaction hash.
|
|
1189
|
+
* @returns {Transactions}
|
|
1190
|
+
*/
|
|
1191
|
+
const getTxs = ({ apiKey, address, baseUrl, limit, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1192
|
+
const url = `${baseUrl}/address/${address}`;
|
|
1193
|
+
const response = yield axios.get(url, {
|
|
1194
|
+
params: {
|
|
1195
|
+
details: 'txs',
|
|
1196
|
+
pageSize: limit
|
|
1197
|
+
},
|
|
1198
|
+
headers: {
|
|
1199
|
+
'api-key': apiKey,
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
const txs = response.data;
|
|
1203
|
+
return txs.transactions;
|
|
1204
|
+
});
|
|
1205
|
+
/**
|
|
1206
|
+
* Get UTXOs
|
|
1207
|
+
*
|
|
1208
|
+
* @param {string} baseUrl The nownodes blockbook URL.
|
|
1209
|
+
* @param {string} address address.
|
|
1210
|
+
* @returns {Transactions}
|
|
1211
|
+
*/
|
|
1212
|
+
const getUTXOs = ({ apiKey, address, baseUrl, isConfirmed = true, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1213
|
+
const url = `${baseUrl}/utxo/${address}`;
|
|
1214
|
+
const response = yield axios.get(url, {
|
|
1215
|
+
params: {
|
|
1216
|
+
confirmed: isConfirmed
|
|
1217
|
+
},
|
|
1218
|
+
headers: {
|
|
1219
|
+
'api-key': apiKey,
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
const utxos = response.data;
|
|
1223
|
+
return utxos;
|
|
1224
|
+
});
|
|
1225
|
+
/**
|
|
1226
|
+
* Get address balance.
|
|
1227
|
+
*
|
|
1228
|
+
*
|
|
1229
|
+
* @param {string} baseUrl The sochain node url.
|
|
1230
|
+
* @param {string} address Address
|
|
1231
|
+
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
1232
|
+
* @returns {number}
|
|
1233
|
+
*/
|
|
1234
|
+
const getBalance = ({ apiKey, baseUrl, address, confirmedOnly = true, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1235
|
+
const url = `${baseUrl}/address/${address}`;
|
|
1236
|
+
const response = yield axios.get(url, {
|
|
1237
|
+
headers: {
|
|
1238
|
+
'api-key': apiKey,
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
const balanceResponse = response.data;
|
|
1242
|
+
const balance = confirmedOnly ? baseAmount(balanceResponse.balance, assetDecimals) : baseAmount(balanceResponse.balance).plus(balanceResponse.unconfirmedBalance, assetDecimals);
|
|
1243
|
+
return balance;
|
|
1244
|
+
});
|
|
1245
|
+
const broadcastTx = ({ apiKey, baseUrl, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1246
|
+
const url = `${baseUrl}/sendtx/${txHex}`;
|
|
1247
|
+
const response = yield axios.get(url, {
|
|
1248
|
+
headers: {
|
|
1249
|
+
'api-key': apiKey,
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
return response.data.result;
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
class NownodesProvider {
|
|
1256
|
+
constructor(baseUrl = 'https://zecbook.nownodes.io/api/v2', chain, asset, assetDecimals, apiKey) {
|
|
1257
|
+
this.baseUrl = baseUrl;
|
|
1258
|
+
this._apiKey = apiKey;
|
|
1259
|
+
this.asset = asset;
|
|
1260
|
+
this.assetDecimals = assetDecimals;
|
|
1261
|
+
if (chain !== 'ZEC' || asset.chain !== 'ZEC') {
|
|
1262
|
+
throw Error(`Now nodes provider does not support chain or asset ${chain} ${asset}`);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
get apiKey() {
|
|
1266
|
+
return this._apiKey;
|
|
1267
|
+
}
|
|
1268
|
+
set apiKey(value) {
|
|
1269
|
+
this._apiKey = value;
|
|
1270
|
+
}
|
|
1271
|
+
broadcastTx(txHex) {
|
|
1272
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1273
|
+
return yield broadcastTx({
|
|
1274
|
+
apiKey: this._apiKey,
|
|
1275
|
+
baseUrl: this.baseUrl,
|
|
1276
|
+
txHex,
|
|
1277
|
+
});
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
getConfirmedUnspentTxs(address) {
|
|
1281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1282
|
+
const allUnspent = yield getUTXOs({
|
|
1283
|
+
apiKey: this._apiKey,
|
|
1284
|
+
baseUrl: this.baseUrl,
|
|
1285
|
+
address: address,
|
|
1286
|
+
isConfirmed: true
|
|
1287
|
+
});
|
|
1288
|
+
return this.mapUTXOs(allUnspent);
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
getUnspentTxs(address) {
|
|
1292
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1293
|
+
const allUnspent = yield getUTXOs({
|
|
1294
|
+
apiKey: this._apiKey,
|
|
1295
|
+
baseUrl: this.baseUrl,
|
|
1296
|
+
address: address,
|
|
1297
|
+
isConfirmed: false
|
|
1298
|
+
});
|
|
1299
|
+
return this.mapUTXOs(allUnspent);
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
getBalance(address, confirmedOnly) {
|
|
1303
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1304
|
+
const amount = yield getBalance({
|
|
1305
|
+
apiKey: this._apiKey,
|
|
1306
|
+
baseUrl: this.baseUrl,
|
|
1307
|
+
address,
|
|
1308
|
+
confirmedOnly: confirmedOnly !== undefined ? confirmedOnly : true,
|
|
1309
|
+
assetDecimals: this.assetDecimals,
|
|
1310
|
+
});
|
|
1311
|
+
return [{ amount, asset: this.asset }];
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
getTransactions(params) {
|
|
1315
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1316
|
+
const rawTxs = yield this.getRawTransactions(params);
|
|
1317
|
+
const txs = rawTxs.map((i) => this.mapTransactionToTx(i));
|
|
1318
|
+
const result = {
|
|
1319
|
+
total: txs.length,
|
|
1320
|
+
txs,
|
|
1321
|
+
};
|
|
1322
|
+
return result;
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
getTransactionData(txId) {
|
|
1326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1327
|
+
try {
|
|
1328
|
+
const rawTx = yield getTx({
|
|
1329
|
+
apiKey: this._apiKey,
|
|
1330
|
+
baseUrl: this.baseUrl,
|
|
1331
|
+
hash: txId,
|
|
1332
|
+
});
|
|
1333
|
+
return this.mapTransactionToTx(rawTx);
|
|
1334
|
+
}
|
|
1335
|
+
catch (error) {
|
|
1336
|
+
console.error(error);
|
|
1337
|
+
throw error;
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
getFeeRates() {
|
|
1342
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1343
|
+
throw Error('Zcash has flat fees. Fee rates not apply');
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
mapTransactionToTx(rawTx) {
|
|
1347
|
+
return {
|
|
1348
|
+
asset: this.asset,
|
|
1349
|
+
from: rawTx.vin.map((i) => ({
|
|
1350
|
+
from: i.addresses[0],
|
|
1351
|
+
amount: baseAmount(i.value, this.assetDecimals),
|
|
1352
|
+
})),
|
|
1353
|
+
to: rawTx.vout
|
|
1354
|
+
.filter((i) => i.isAddress) //filter out op_return outputs
|
|
1355
|
+
.map((i) => ({ to: i.addresses[0], amount: baseAmount(i.value, this.assetDecimals) })),
|
|
1356
|
+
date: new Date(rawTx.blockTime * 1000),
|
|
1357
|
+
type: TxType.Transfer,
|
|
1358
|
+
hash: rawTx.txid,
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
mapUTXOs(utxos) {
|
|
1362
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1363
|
+
return utxos.flatMap((currentUtxo) => {
|
|
1364
|
+
return [{
|
|
1365
|
+
hash: currentUtxo.txid,
|
|
1366
|
+
index: currentUtxo.vout,
|
|
1367
|
+
value: Number(currentUtxo.value)
|
|
1368
|
+
}];
|
|
1369
|
+
});
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
getRawTransactions(params) {
|
|
1373
|
+
var _a;
|
|
1374
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1375
|
+
if (params === null || params === void 0 ? void 0 : params.startTime) {
|
|
1376
|
+
throw Error('startTime not supported on nownodes provider');
|
|
1377
|
+
}
|
|
1378
|
+
const offset = (_a = params === null || params === void 0 ? void 0 : params.offset) !== null && _a !== void 0 ? _a : 0;
|
|
1379
|
+
const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
|
|
1380
|
+
if (offset + limit > 1000)
|
|
1381
|
+
throw Error('cannot fetch more than last 1000 txs'); // note: Is possible increase the number if necessary
|
|
1382
|
+
if (offset < 0 || limit < 0)
|
|
1383
|
+
throw Error('ofset and limit must be equal or greater than 0');
|
|
1384
|
+
try {
|
|
1385
|
+
const transactions = yield getTxs({
|
|
1386
|
+
apiKey: this._apiKey,
|
|
1387
|
+
baseUrl: this.baseUrl,
|
|
1388
|
+
address: `${params === null || params === void 0 ? void 0 : params.address}`,
|
|
1389
|
+
limit: offset + limit || 1000, // fetch the maximum wihtout pagination
|
|
1390
|
+
});
|
|
1391
|
+
return transactions.slice(offset, offset + limit);
|
|
1392
|
+
}
|
|
1393
|
+
catch (error) {
|
|
1394
|
+
throw error;
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
export { BitgoProvider, BlockcypherNetwork, BlockcypherProvider, HaskoinNetwork, HaskoinProvider, NownodesProvider, SochainNetwork, SochainProvider, broadcastTx$2 as broadcastTx, getAccount, getAddress, getBalance$2 as getBalance, getConfirmedTxStatus, getConfirmedUnspentTxs, getIsTxConfirmed, getTx$2 as getTx, getTxs$2 as getTxs, getUnspentTxs };
|
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$3 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
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$2 = ({ apiKey, sochainUrl, network, hash }) => __awaiter(void 0, voi
|
|
|
78
78
|
* @param {string} hash The transaction hash.
|
|
79
79
|
* @returns {Transactions}
|
|
80
80
|
*/
|
|
81
|
-
const getTxs$
|
|
81
|
+
const getTxs$3 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
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$2 = ({ apiKey, address, sochainUrl, network, page, }) => __awaiter(
|
|
|
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$3 = ({ apiKey, sochainUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
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 = ({ apiKey, sochainUrl, network, address, page, }) => __a
|
|
|
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$3 = ({ apiKey, sochainUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
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;
|
|
@@ -172,7 +172,7 @@ class SochainProvider {
|
|
|
172
172
|
}
|
|
173
173
|
broadcastTx(txHex) {
|
|
174
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
return yield broadcastTx$
|
|
175
|
+
return yield broadcastTx$3({
|
|
176
176
|
apiKey: this._apiKey,
|
|
177
177
|
sochainUrl: this.baseUrl,
|
|
178
178
|
network: this.sochainNetwork,
|
|
@@ -208,7 +208,7 @@ class SochainProvider {
|
|
|
208
208
|
getBalance(address, confirmedOnly) {
|
|
209
209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
210
|
try {
|
|
211
|
-
const amount = yield getBalance$
|
|
211
|
+
const amount = yield getBalance$3({
|
|
212
212
|
apiKey: this._apiKey,
|
|
213
213
|
sochainUrl: this.baseUrl,
|
|
214
214
|
network: this.sochainNetwork,
|
|
@@ -244,7 +244,7 @@ class SochainProvider {
|
|
|
244
244
|
let page = firstPage;
|
|
245
245
|
try {
|
|
246
246
|
while (page <= lastPage) {
|
|
247
|
-
const response = yield getTxs$
|
|
247
|
+
const response = yield getTxs$3({
|
|
248
248
|
apiKey: this._apiKey,
|
|
249
249
|
sochainUrl: this.baseUrl,
|
|
250
250
|
network: this.sochainNetwork,
|
|
@@ -286,7 +286,7 @@ class SochainProvider {
|
|
|
286
286
|
getTransactionData(txId) {
|
|
287
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
288
288
|
try {
|
|
289
|
-
const rawTx = yield getTx$
|
|
289
|
+
const rawTx = yield getTx$3({
|
|
290
290
|
apiKey: this._apiKey,
|
|
291
291
|
sochainUrl: this.baseUrl,
|
|
292
292
|
network: this.sochainNetwork,
|
|
@@ -413,7 +413,7 @@ const getAddress = ({ haskoinUrl, network, address }) => __awaiter(void 0, void
|
|
|
413
413
|
*
|
|
414
414
|
* @throws {"failed to query transaction by a given hash"} thrown if failed to query transaction by a given hash
|
|
415
415
|
*/
|
|
416
|
-
const getTx$
|
|
416
|
+
const getTx$2 = ({ haskoinUrl, txId, network }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
417
417
|
const result = (yield axios__default.default.get(`${haskoinUrl}/${network}/transaction/${txId}`)).data;
|
|
418
418
|
if (!result || isErrorResponse(result))
|
|
419
419
|
throw new Error(`failed to query transaction by a given hash ${txId}`);
|
|
@@ -445,7 +445,7 @@ const getRawTransaction = ({ haskoinUrl, network, txId }) => __awaiter(void 0, v
|
|
|
445
445
|
* @param {string} hash The transaction hash.
|
|
446
446
|
* @returns {Transactions}
|
|
447
447
|
*/
|
|
448
|
-
const getTxs$
|
|
448
|
+
const getTxs$2 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
449
449
|
const params = { limit: `${limit}`, offset: `${offset}` };
|
|
450
450
|
const url = `${haskoinUrl}/${network}/address/${address}/transactions/full`;
|
|
451
451
|
const result = (yield axios__default.default.get(url, { params })).data;
|
|
@@ -458,7 +458,7 @@ const getTxs$1 = ({ address, haskoinUrl, network, limit, offset, }) => __awaiter
|
|
|
458
458
|
* @param param
|
|
459
459
|
* @returns Returns BaseAmount
|
|
460
460
|
*/
|
|
461
|
-
const getBalance$
|
|
461
|
+
const getBalance$2 = ({ haskoinUrl, haskoinNetwork, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
462
462
|
const { data: { confirmed, unconfirmed }, } = yield axios__default.default.get(`${haskoinUrl}/${haskoinNetwork}/address/${address}/balance`);
|
|
463
463
|
const confirmedAmount = xchainUtil.baseAmount(confirmed, assetDecimals);
|
|
464
464
|
const unconfirmedAmount = xchainUtil.baseAmount(unconfirmed, assetDecimals);
|
|
@@ -491,7 +491,7 @@ const getUnspentTxs = ({ haskoinUrl, network, address }) => __awaiter(void 0, vo
|
|
|
491
491
|
* @returns {TxConfirmedStatus}
|
|
492
492
|
*/
|
|
493
493
|
const getIsTxConfirmed = ({ haskoinUrl, network, txId }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
494
|
-
const tx = yield getTx$
|
|
494
|
+
const tx = yield getTx$2({ haskoinUrl, network, txId });
|
|
495
495
|
return {
|
|
496
496
|
network: network,
|
|
497
497
|
txid: txId,
|
|
@@ -601,7 +601,7 @@ const getUnspentTransactions = ({ haskoinUrl, network, address }) => __awaiter(v
|
|
|
601
601
|
* @param {BroadcastTxParams} params
|
|
602
602
|
* @returns {TxHash} Transaction hash.
|
|
603
603
|
*/
|
|
604
|
-
const broadcastTx$
|
|
604
|
+
const broadcastTx$2 = ({ txHex, haskoinUrl, haskoinNetwork, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
605
605
|
var _a;
|
|
606
606
|
const MAX_RETRIES = 5;
|
|
607
607
|
let retries = 0;
|
|
@@ -638,7 +638,7 @@ class HaskoinProvider {
|
|
|
638
638
|
}
|
|
639
639
|
broadcastTx(txHex) {
|
|
640
640
|
return __awaiter(this, void 0, void 0, function* () {
|
|
641
|
-
return yield broadcastTx$
|
|
641
|
+
return yield broadcastTx$2({
|
|
642
642
|
haskoinUrl: this.baseUrl,
|
|
643
643
|
haskoinNetwork: this.haskoinNetwork,
|
|
644
644
|
txHex,
|
|
@@ -668,7 +668,7 @@ class HaskoinProvider {
|
|
|
668
668
|
}
|
|
669
669
|
getBalance(address, confirmedOnly) {
|
|
670
670
|
return __awaiter(this, void 0, void 0, function* () {
|
|
671
|
-
const amount = yield getBalance$
|
|
671
|
+
const amount = yield getBalance$2({
|
|
672
672
|
haskoinUrl: this.baseUrl,
|
|
673
673
|
haskoinNetwork: this.haskoinNetwork,
|
|
674
674
|
address,
|
|
@@ -694,7 +694,7 @@ class HaskoinProvider {
|
|
|
694
694
|
throw Error('cannot fetch more than last 2000 txs');
|
|
695
695
|
if (offset < 0 || limit < 0)
|
|
696
696
|
throw Error('ofset and limit must be equal or greater than 0');
|
|
697
|
-
const response = yield getTxs$
|
|
697
|
+
const response = yield getTxs$2({
|
|
698
698
|
address: `${params === null || params === void 0 ? void 0 : params.address}`,
|
|
699
699
|
haskoinUrl: this.baseUrl,
|
|
700
700
|
network: this.haskoinNetwork,
|
|
@@ -733,7 +733,7 @@ class HaskoinProvider {
|
|
|
733
733
|
getTransactionData(txId) {
|
|
734
734
|
return __awaiter(this, void 0, void 0, function* () {
|
|
735
735
|
try {
|
|
736
|
-
const rawTx = yield getTx$
|
|
736
|
+
const rawTx = yield getTx$2({
|
|
737
737
|
haskoinUrl: this.baseUrl,
|
|
738
738
|
network: this.haskoinNetwork,
|
|
739
739
|
txId: txId,
|
|
@@ -784,7 +784,7 @@ class HaskoinProvider {
|
|
|
784
784
|
* @param {string} hash The transaction hash.
|
|
785
785
|
* @returns {Transactions}
|
|
786
786
|
*/
|
|
787
|
-
const getTx = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
787
|
+
const getTx$1 = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
788
788
|
const params = { includeHex: 'true', limit: limit.toString() };
|
|
789
789
|
if (apiKey)
|
|
790
790
|
params['token'] = apiKey;
|
|
@@ -802,7 +802,7 @@ const getTx = ({ apiKey, baseUrl, network, hash, limit = 20 }) => __awaiter(void
|
|
|
802
802
|
* @param {string} hash The transaction hash.
|
|
803
803
|
* @returns {Transactions}
|
|
804
804
|
*/
|
|
805
|
-
const getTxs = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspentOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
805
|
+
const getTxs$1 = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspentOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
806
806
|
const params = { limit: `${limit}`, unspentOnly: `${unspentOnly}` };
|
|
807
807
|
const url = `${baseUrl}/${network}/addrs/${address}`;
|
|
808
808
|
if (apiKey)
|
|
@@ -823,7 +823,7 @@ const getTxs = ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspent
|
|
|
823
823
|
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
824
824
|
* @returns {number}
|
|
825
825
|
*/
|
|
826
|
-
const getBalance = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
826
|
+
const getBalance$1 = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
827
827
|
const params = {};
|
|
828
828
|
const url = `${baseUrl}/${network}/addrs/${address}/balance`;
|
|
829
829
|
if (apiKey)
|
|
@@ -834,7 +834,7 @@ const getBalance = ({ apiKey, baseUrl, network, address, confirmedOnly, assetDec
|
|
|
834
834
|
const finalBalance = xchainUtil.baseAmount(balanceResponse.final_balance, assetDecimals);
|
|
835
835
|
return confirmedOnly ? confirmedAmount : finalBalance;
|
|
836
836
|
});
|
|
837
|
-
const broadcastTx = ({ apiKey, baseUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
837
|
+
const broadcastTx$1 = ({ apiKey, baseUrl, network, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
838
838
|
const params = {};
|
|
839
839
|
const url = `${baseUrl}/${network}/txs/push`;
|
|
840
840
|
if (apiKey)
|
|
@@ -876,7 +876,7 @@ class BlockcypherProvider {
|
|
|
876
876
|
}
|
|
877
877
|
broadcastTx(txHex) {
|
|
878
878
|
return __awaiter(this, void 0, void 0, function* () {
|
|
879
|
-
return yield broadcastTx({
|
|
879
|
+
return yield broadcastTx$1({
|
|
880
880
|
apiKey: this._apiKey,
|
|
881
881
|
baseUrl: this.baseUrl,
|
|
882
882
|
network: this.blockcypherNetwork,
|
|
@@ -898,7 +898,7 @@ class BlockcypherProvider {
|
|
|
898
898
|
}
|
|
899
899
|
getBalance(address, confirmedOnly) {
|
|
900
900
|
return __awaiter(this, void 0, void 0, function* () {
|
|
901
|
-
const amount = yield getBalance({
|
|
901
|
+
const amount = yield getBalance$1({
|
|
902
902
|
apiKey: this._apiKey,
|
|
903
903
|
baseUrl: this.baseUrl,
|
|
904
904
|
network: this.blockcypherNetwork,
|
|
@@ -936,7 +936,7 @@ class BlockcypherProvider {
|
|
|
936
936
|
getTransactionData(txId) {
|
|
937
937
|
return __awaiter(this, void 0, void 0, function* () {
|
|
938
938
|
try {
|
|
939
|
-
const rawTx = yield getTx({
|
|
939
|
+
const rawTx = yield getTx$1({
|
|
940
940
|
apiKey: this._apiKey,
|
|
941
941
|
baseUrl: this.baseUrl,
|
|
942
942
|
network: this.blockcypherNetwork,
|
|
@@ -1041,7 +1041,7 @@ class BlockcypherProvider {
|
|
|
1041
1041
|
throw Error('ofset and limit must be equal or greater than 0');
|
|
1042
1042
|
const txHashesToFetch = [];
|
|
1043
1043
|
try {
|
|
1044
|
-
const response = yield getTxs({
|
|
1044
|
+
const response = yield getTxs$1({
|
|
1045
1045
|
apiKey: this._apiKey,
|
|
1046
1046
|
baseUrl: this.baseUrl,
|
|
1047
1047
|
network: this.blockcypherNetwork,
|
|
@@ -1070,7 +1070,7 @@ class BlockcypherProvider {
|
|
|
1070
1070
|
.useCorrespondingResults()
|
|
1071
1071
|
.process((hash) => __awaiter(this, void 0, void 0, function* () {
|
|
1072
1072
|
yield this.delay(1000);
|
|
1073
|
-
const rawTx = yield getTx({
|
|
1073
|
+
const rawTx = yield getTx$1({
|
|
1074
1074
|
apiKey: this._apiKey,
|
|
1075
1075
|
baseUrl: this.baseUrl,
|
|
1076
1076
|
network: this.blockcypherNetwork,
|
|
@@ -1169,17 +1169,253 @@ class BitgoProvider {
|
|
|
1169
1169
|
}
|
|
1170
1170
|
}
|
|
1171
1171
|
|
|
1172
|
+
/**
|
|
1173
|
+
* Get transaction by hash.
|
|
1174
|
+
*
|
|
1175
|
+
*
|
|
1176
|
+
* @param {string} baseUrl The sochain node url.
|
|
1177
|
+
* @param {string} hash The transaction hash.
|
|
1178
|
+
* @returns {Transactions}
|
|
1179
|
+
*/
|
|
1180
|
+
const getTx = ({ apiKey, baseUrl, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1181
|
+
const url = `${baseUrl}/tx/${hash}`;
|
|
1182
|
+
const response = yield axios__default.default.get(url, {
|
|
1183
|
+
headers: {
|
|
1184
|
+
'api-key': apiKey,
|
|
1185
|
+
}
|
|
1186
|
+
});
|
|
1187
|
+
const tx = response.data;
|
|
1188
|
+
return tx;
|
|
1189
|
+
});
|
|
1190
|
+
/**
|
|
1191
|
+
* Get transactions
|
|
1192
|
+
*
|
|
1193
|
+
*
|
|
1194
|
+
* @param {string} baseUrl The sochain node url.
|
|
1195
|
+
* @param {string} hash The transaction hash.
|
|
1196
|
+
* @returns {Transactions}
|
|
1197
|
+
*/
|
|
1198
|
+
const getTxs = ({ apiKey, address, baseUrl, limit, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1199
|
+
const url = `${baseUrl}/address/${address}`;
|
|
1200
|
+
const response = yield axios__default.default.get(url, {
|
|
1201
|
+
params: {
|
|
1202
|
+
details: 'txs',
|
|
1203
|
+
pageSize: limit
|
|
1204
|
+
},
|
|
1205
|
+
headers: {
|
|
1206
|
+
'api-key': apiKey,
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
const txs = response.data;
|
|
1210
|
+
return txs.transactions;
|
|
1211
|
+
});
|
|
1212
|
+
/**
|
|
1213
|
+
* Get UTXOs
|
|
1214
|
+
*
|
|
1215
|
+
* @param {string} baseUrl The nownodes blockbook URL.
|
|
1216
|
+
* @param {string} address address.
|
|
1217
|
+
* @returns {Transactions}
|
|
1218
|
+
*/
|
|
1219
|
+
const getUTXOs = ({ apiKey, address, baseUrl, isConfirmed = true, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1220
|
+
const url = `${baseUrl}/utxo/${address}`;
|
|
1221
|
+
const response = yield axios__default.default.get(url, {
|
|
1222
|
+
params: {
|
|
1223
|
+
confirmed: isConfirmed
|
|
1224
|
+
},
|
|
1225
|
+
headers: {
|
|
1226
|
+
'api-key': apiKey,
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
const utxos = response.data;
|
|
1230
|
+
return utxos;
|
|
1231
|
+
});
|
|
1232
|
+
/**
|
|
1233
|
+
* Get address balance.
|
|
1234
|
+
*
|
|
1235
|
+
*
|
|
1236
|
+
* @param {string} baseUrl The sochain node url.
|
|
1237
|
+
* @param {string} address Address
|
|
1238
|
+
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
1239
|
+
* @returns {number}
|
|
1240
|
+
*/
|
|
1241
|
+
const getBalance = ({ apiKey, baseUrl, address, confirmedOnly = true, assetDecimals, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1242
|
+
const url = `${baseUrl}/address/${address}`;
|
|
1243
|
+
const response = yield axios__default.default.get(url, {
|
|
1244
|
+
headers: {
|
|
1245
|
+
'api-key': apiKey,
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
const balanceResponse = response.data;
|
|
1249
|
+
const balance = confirmedOnly ? xchainUtil.baseAmount(balanceResponse.balance, assetDecimals) : xchainUtil.baseAmount(balanceResponse.balance).plus(balanceResponse.unconfirmedBalance, assetDecimals);
|
|
1250
|
+
return balance;
|
|
1251
|
+
});
|
|
1252
|
+
const broadcastTx = ({ apiKey, baseUrl, txHex, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1253
|
+
const url = `${baseUrl}/sendtx/${txHex}`;
|
|
1254
|
+
const response = yield axios__default.default.get(url, {
|
|
1255
|
+
headers: {
|
|
1256
|
+
'api-key': apiKey,
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
return response.data.result;
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
class NownodesProvider {
|
|
1263
|
+
constructor(baseUrl = 'https://zecbook.nownodes.io/api/v2', chain, asset, assetDecimals, apiKey) {
|
|
1264
|
+
this.baseUrl = baseUrl;
|
|
1265
|
+
this._apiKey = apiKey;
|
|
1266
|
+
this.asset = asset;
|
|
1267
|
+
this.assetDecimals = assetDecimals;
|
|
1268
|
+
if (chain !== 'ZEC' || asset.chain !== 'ZEC') {
|
|
1269
|
+
throw Error(`Now nodes provider does not support chain or asset ${chain} ${asset}`);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
get apiKey() {
|
|
1273
|
+
return this._apiKey;
|
|
1274
|
+
}
|
|
1275
|
+
set apiKey(value) {
|
|
1276
|
+
this._apiKey = value;
|
|
1277
|
+
}
|
|
1278
|
+
broadcastTx(txHex) {
|
|
1279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1280
|
+
return yield broadcastTx({
|
|
1281
|
+
apiKey: this._apiKey,
|
|
1282
|
+
baseUrl: this.baseUrl,
|
|
1283
|
+
txHex,
|
|
1284
|
+
});
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
getConfirmedUnspentTxs(address) {
|
|
1288
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1289
|
+
const allUnspent = yield getUTXOs({
|
|
1290
|
+
apiKey: this._apiKey,
|
|
1291
|
+
baseUrl: this.baseUrl,
|
|
1292
|
+
address: address,
|
|
1293
|
+
isConfirmed: true
|
|
1294
|
+
});
|
|
1295
|
+
return this.mapUTXOs(allUnspent);
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
getUnspentTxs(address) {
|
|
1299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1300
|
+
const allUnspent = yield getUTXOs({
|
|
1301
|
+
apiKey: this._apiKey,
|
|
1302
|
+
baseUrl: this.baseUrl,
|
|
1303
|
+
address: address,
|
|
1304
|
+
isConfirmed: false
|
|
1305
|
+
});
|
|
1306
|
+
return this.mapUTXOs(allUnspent);
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
getBalance(address, confirmedOnly) {
|
|
1310
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1311
|
+
const amount = yield getBalance({
|
|
1312
|
+
apiKey: this._apiKey,
|
|
1313
|
+
baseUrl: this.baseUrl,
|
|
1314
|
+
address,
|
|
1315
|
+
confirmedOnly: confirmedOnly !== undefined ? confirmedOnly : true,
|
|
1316
|
+
assetDecimals: this.assetDecimals,
|
|
1317
|
+
});
|
|
1318
|
+
return [{ amount, asset: this.asset }];
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
getTransactions(params) {
|
|
1322
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1323
|
+
const rawTxs = yield this.getRawTransactions(params);
|
|
1324
|
+
const txs = rawTxs.map((i) => this.mapTransactionToTx(i));
|
|
1325
|
+
const result = {
|
|
1326
|
+
total: txs.length,
|
|
1327
|
+
txs,
|
|
1328
|
+
};
|
|
1329
|
+
return result;
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
getTransactionData(txId) {
|
|
1333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1334
|
+
try {
|
|
1335
|
+
const rawTx = yield getTx({
|
|
1336
|
+
apiKey: this._apiKey,
|
|
1337
|
+
baseUrl: this.baseUrl,
|
|
1338
|
+
hash: txId,
|
|
1339
|
+
});
|
|
1340
|
+
return this.mapTransactionToTx(rawTx);
|
|
1341
|
+
}
|
|
1342
|
+
catch (error) {
|
|
1343
|
+
console.error(error);
|
|
1344
|
+
throw error;
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
getFeeRates() {
|
|
1349
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1350
|
+
throw Error('Zcash has flat fees. Fee rates not apply');
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
mapTransactionToTx(rawTx) {
|
|
1354
|
+
return {
|
|
1355
|
+
asset: this.asset,
|
|
1356
|
+
from: rawTx.vin.map((i) => ({
|
|
1357
|
+
from: i.addresses[0],
|
|
1358
|
+
amount: xchainUtil.baseAmount(i.value, this.assetDecimals),
|
|
1359
|
+
})),
|
|
1360
|
+
to: rawTx.vout
|
|
1361
|
+
.filter((i) => i.isAddress) //filter out op_return outputs
|
|
1362
|
+
.map((i) => ({ to: i.addresses[0], amount: xchainUtil.baseAmount(i.value, this.assetDecimals) })),
|
|
1363
|
+
date: new Date(rawTx.blockTime * 1000),
|
|
1364
|
+
type: xchainClient.TxType.Transfer,
|
|
1365
|
+
hash: rawTx.txid,
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
mapUTXOs(utxos) {
|
|
1369
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1370
|
+
return utxos.flatMap((currentUtxo) => {
|
|
1371
|
+
return [{
|
|
1372
|
+
hash: currentUtxo.txid,
|
|
1373
|
+
index: currentUtxo.vout,
|
|
1374
|
+
value: Number(currentUtxo.value)
|
|
1375
|
+
}];
|
|
1376
|
+
});
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
getRawTransactions(params) {
|
|
1380
|
+
var _a;
|
|
1381
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1382
|
+
if (params === null || params === void 0 ? void 0 : params.startTime) {
|
|
1383
|
+
throw Error('startTime not supported on nownodes provider');
|
|
1384
|
+
}
|
|
1385
|
+
const offset = (_a = params === null || params === void 0 ? void 0 : params.offset) !== null && _a !== void 0 ? _a : 0;
|
|
1386
|
+
const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
|
|
1387
|
+
if (offset + limit > 1000)
|
|
1388
|
+
throw Error('cannot fetch more than last 1000 txs'); // note: Is possible increase the number if necessary
|
|
1389
|
+
if (offset < 0 || limit < 0)
|
|
1390
|
+
throw Error('ofset and limit must be equal or greater than 0');
|
|
1391
|
+
try {
|
|
1392
|
+
const transactions = yield getTxs({
|
|
1393
|
+
apiKey: this._apiKey,
|
|
1394
|
+
baseUrl: this.baseUrl,
|
|
1395
|
+
address: `${params === null || params === void 0 ? void 0 : params.address}`,
|
|
1396
|
+
limit: offset + limit || 1000, // fetch the maximum wihtout pagination
|
|
1397
|
+
});
|
|
1398
|
+
return transactions.slice(offset, offset + limit);
|
|
1399
|
+
}
|
|
1400
|
+
catch (error) {
|
|
1401
|
+
throw error;
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1172
1407
|
exports.BitgoProvider = BitgoProvider;
|
|
1173
1408
|
exports.BlockcypherProvider = BlockcypherProvider;
|
|
1174
1409
|
exports.HaskoinProvider = HaskoinProvider;
|
|
1410
|
+
exports.NownodesProvider = NownodesProvider;
|
|
1175
1411
|
exports.SochainProvider = SochainProvider;
|
|
1176
|
-
exports.broadcastTx = broadcastTx$
|
|
1412
|
+
exports.broadcastTx = broadcastTx$2;
|
|
1177
1413
|
exports.getAccount = getAccount;
|
|
1178
1414
|
exports.getAddress = getAddress;
|
|
1179
|
-
exports.getBalance = getBalance$
|
|
1415
|
+
exports.getBalance = getBalance$2;
|
|
1180
1416
|
exports.getConfirmedTxStatus = getConfirmedTxStatus;
|
|
1181
1417
|
exports.getConfirmedUnspentTxs = getConfirmedUnspentTxs;
|
|
1182
1418
|
exports.getIsTxConfirmed = getIsTxConfirmed;
|
|
1183
|
-
exports.getTx = getTx$
|
|
1184
|
-
exports.getTxs = getTxs$
|
|
1419
|
+
exports.getTx = getTx$2;
|
|
1420
|
+
exports.getTxs = getTxs$2;
|
|
1185
1421
|
exports.getUnspentTxs = getUnspentTxs;
|
package/lib/providers/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export * from './haskoin/haskoin-data-provider';
|
|
|
7
7
|
export * from './blockcypher/blockcypher-data-provider';
|
|
8
8
|
export { BlockcypherNetwork } from './blockcypher/blockcypher-api-types';
|
|
9
9
|
export { BitgoProvider } from './bitgo/bitgo-data-provider';
|
|
10
|
+
export { NownodesProvider } from './nownodes/nownodes-data-provider';
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TxHash } from '@xchainjs/xchain-client';
|
|
2
|
+
import { BaseAmount } from '@xchainjs/xchain-util';
|
|
3
|
+
import { BalanceParams, Transaction, TxHashParams, AddressUTXO } from './nownodes-api-types';
|
|
4
|
+
/**
|
|
5
|
+
* Get transaction by hash.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @param {string} baseUrl The sochain node url.
|
|
9
|
+
* @param {string} hash The transaction hash.
|
|
10
|
+
* @returns {Transactions}
|
|
11
|
+
*/
|
|
12
|
+
export declare const getTx: ({ apiKey, baseUrl, hash }: TxHashParams) => Promise<Transaction>;
|
|
13
|
+
/**
|
|
14
|
+
* Get transactions
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @param {string} baseUrl The sochain node url.
|
|
18
|
+
* @param {string} hash The transaction hash.
|
|
19
|
+
* @returns {Transactions}
|
|
20
|
+
*/
|
|
21
|
+
export declare const getTxs: ({ apiKey, address, baseUrl, limit, }: {
|
|
22
|
+
apiKey?: string | undefined;
|
|
23
|
+
address: string;
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
limit: number;
|
|
26
|
+
}) => Promise<Transaction[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Get UTXOs
|
|
29
|
+
*
|
|
30
|
+
* @param {string} baseUrl The nownodes blockbook URL.
|
|
31
|
+
* @param {string} address address.
|
|
32
|
+
* @returns {Transactions}
|
|
33
|
+
*/
|
|
34
|
+
export declare const getUTXOs: ({ apiKey, address, baseUrl, isConfirmed, }: {
|
|
35
|
+
apiKey: string;
|
|
36
|
+
address: string;
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
isConfirmed: boolean;
|
|
39
|
+
}) => Promise<AddressUTXO[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Get address balance.
|
|
42
|
+
*
|
|
43
|
+
*
|
|
44
|
+
* @param {string} baseUrl The sochain node url.
|
|
45
|
+
* @param {string} address Address
|
|
46
|
+
* @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
|
|
47
|
+
* @returns {number}
|
|
48
|
+
*/
|
|
49
|
+
export declare const getBalance: ({ apiKey, baseUrl, address, confirmedOnly, assetDecimals, }: BalanceParams) => Promise<BaseAmount>;
|
|
50
|
+
export declare const broadcastTx: ({ apiKey, baseUrl, txHex, }: {
|
|
51
|
+
apiKey: string;
|
|
52
|
+
baseUrl: string;
|
|
53
|
+
txHex: string;
|
|
54
|
+
}) => Promise<TxHash>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FeeRates, TxHash, TxHistoryParams } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Address, Asset, Chain } from '@xchainjs/xchain-util';
|
|
3
|
+
import { Balance, Tx, TxsPage, UTXO, UtxoOnlineDataProvider } from '../../types';
|
|
4
|
+
export declare class NownodesProvider implements UtxoOnlineDataProvider {
|
|
5
|
+
private baseUrl;
|
|
6
|
+
private _apiKey;
|
|
7
|
+
private asset;
|
|
8
|
+
private assetDecimals;
|
|
9
|
+
constructor(baseUrl: string | undefined, chain: Chain, asset: Asset, assetDecimals: number, apiKey: string);
|
|
10
|
+
get apiKey(): string;
|
|
11
|
+
set apiKey(value: string);
|
|
12
|
+
broadcastTx(txHex: string): Promise<TxHash>;
|
|
13
|
+
getConfirmedUnspentTxs(address: string): Promise<UTXO[]>;
|
|
14
|
+
getUnspentTxs(address: string): Promise<UTXO[]>;
|
|
15
|
+
getBalance(address: Address, confirmedOnly?: boolean): Promise<Balance[]>;
|
|
16
|
+
getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
|
|
17
|
+
getTransactionData(txId: string): Promise<Tx>;
|
|
18
|
+
getFeeRates(): Promise<FeeRates>;
|
|
19
|
+
private mapTransactionToTx;
|
|
20
|
+
private mapUTXOs;
|
|
21
|
+
private getRawTransactions;
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-utxo-providers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.esm.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@supercharge/promise-pool": "2.4.0",
|
|
32
|
-
"@xchainjs/xchain-client": "
|
|
33
|
-
"@xchainjs/xchain-util": "
|
|
34
|
-
"axios": "1.
|
|
32
|
+
"@xchainjs/xchain-client": "2.0.0",
|
|
33
|
+
"@xchainjs/xchain-util": "2.0.0",
|
|
34
|
+
"axios": "1.8.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"axios-mock-adapter": "1.20.0"
|