@pioneer-platform/blockbook 8.3.12 → 8.3.15
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.d.ts +1 -5
- package/lib/index.js +90 -61
- package/package.json +3 -2
package/lib/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ declare const Axios: any;
|
|
|
6
6
|
declare const https: any;
|
|
7
7
|
declare const nodes: any;
|
|
8
8
|
declare const axios: any;
|
|
9
|
-
declare const axiosRetry: any;
|
|
10
9
|
declare let NOW_NODES_API: string | undefined;
|
|
11
10
|
declare let BLOCKBOOK_URLS: any;
|
|
12
11
|
declare let BLOCKBOOK_SOCKETS: any;
|
|
@@ -16,10 +15,7 @@ declare let get_info_by_pubkey: (coin: string, pubkey: string, page?: string | u
|
|
|
16
15
|
declare let get_txids_by_address: (coin: string, address: string, page?: number) => Promise<any>;
|
|
17
16
|
declare let get_info_by_address: (coin: string, address: string, filter?: string) => Promise<any>;
|
|
18
17
|
declare let get_txs_by_xpub: (coin: string, xpub: string) => Promise<any>;
|
|
19
|
-
declare let broadcast_transaction: (coin: string, hex: string) => Promise<
|
|
20
|
-
txid: any;
|
|
21
|
-
success: boolean;
|
|
22
|
-
}>;
|
|
18
|
+
declare let broadcast_transaction: (coin: string, hex: string) => Promise<any>;
|
|
23
19
|
declare let get_transaction: (coin: string, txid: string) => Promise<any>;
|
|
24
20
|
declare let get_utxos_by_xpub: (coin: string, xpub: string) => Promise<any>;
|
|
25
21
|
declare let get_balance_by_xpub: (coin: string, xpub: any) => Promise<number>;
|
package/lib/index.js
CHANGED
|
@@ -52,22 +52,21 @@ var axios = Axios.create({
|
|
|
52
52
|
}),
|
|
53
53
|
timeout: 30000 // 10 seconds
|
|
54
54
|
});
|
|
55
|
-
|
|
55
|
+
// const axiosRetry = require('axios-retry');
|
|
56
56
|
var NOW_NODES_API = process.env['NOW_NODES_API'];
|
|
57
|
-
axiosRetry(axios, {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
57
|
+
// axiosRetry(axios, {
|
|
58
|
+
// retries: 3, // number of retries
|
|
59
|
+
// retryDelay: (retryCount: number) => {
|
|
60
|
+
// log.error(TAG,`retry attempt: ${retryCount}`);
|
|
61
|
+
// return retryCount * 2000; // time interval between retries
|
|
62
|
+
// },
|
|
63
|
+
// retryCondition: (error: { response: { status: number; }; }) => {
|
|
64
|
+
// log.error(TAG,error)
|
|
65
|
+
// //@TODO mark node offline, and punish
|
|
66
|
+
// // if retry condition is not specified, by default idempotent requests are retried
|
|
67
|
+
// return error?.response?.status === 503;
|
|
68
|
+
// },
|
|
69
|
+
// });
|
|
71
70
|
var BLOCKBOOK_URLS = {};
|
|
72
71
|
var BLOCKBOOK_SOCKETS = {};
|
|
73
72
|
module.exports = {
|
|
@@ -352,61 +351,91 @@ var get_txs_by_xpub = function (coin, xpub) {
|
|
|
352
351
|
};
|
|
353
352
|
var broadcast_transaction = function (coin, hex) {
|
|
354
353
|
return __awaiter(this, void 0, void 0, function () {
|
|
355
|
-
var tag, url, body, resp, e_7;
|
|
356
|
-
|
|
357
|
-
|
|
354
|
+
var tag, url, data, body, output, resp, e_7, errorMessage, statusCode, e_8;
|
|
355
|
+
var _a;
|
|
356
|
+
return __generator(this, function (_b) {
|
|
357
|
+
switch (_b.label) {
|
|
358
358
|
case 0:
|
|
359
359
|
tag = TAG + " | broadcast_transaction | ";
|
|
360
|
-
|
|
360
|
+
_b.label = 1;
|
|
361
361
|
case 1:
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
throw new Error("No blockbook URL configured for coin: ".concat(coin));
|
|
366
|
-
}
|
|
367
|
-
url = BLOCKBOOK_URLS[coin.toUpperCase()] + "/api/v2/sendtx";
|
|
368
|
-
log.debug(tag, "Broadcasting to URL:", url);
|
|
362
|
+
_b.trys.push([1, 6, , 7]);
|
|
363
|
+
url = BLOCKBOOK_URLS[coin.toUpperCase()] + "/api/v2/sendtx/";
|
|
364
|
+
data = hex;
|
|
369
365
|
body = {
|
|
370
|
-
method: 'POST',
|
|
371
366
|
url: url,
|
|
372
367
|
headers: {
|
|
373
|
-
'
|
|
368
|
+
'content-type': 'application/json',
|
|
374
369
|
'User-Agent': fakeUa()
|
|
375
370
|
},
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
371
|
+
method: 'POST',
|
|
372
|
+
json: false,
|
|
373
|
+
data: data,
|
|
379
374
|
};
|
|
380
|
-
|
|
375
|
+
output = {
|
|
376
|
+
success: false
|
|
377
|
+
};
|
|
378
|
+
resp = void 0;
|
|
379
|
+
_b.label = 2;
|
|
381
380
|
case 2:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
381
|
+
_b.trys.push([2, 4, , 5]);
|
|
382
|
+
return [4 /*yield*/, axios(body)];
|
|
383
|
+
case 3:
|
|
384
|
+
resp = _b.sent();
|
|
385
|
+
output.resp = resp;
|
|
386
|
+
output.success = true;
|
|
387
|
+
return [3 /*break*/, 5];
|
|
388
|
+
case 4:
|
|
389
|
+
e_7 = _b.sent();
|
|
390
|
+
log.error(tag, "Broadcast error: ", e_7.message || e_7);
|
|
391
|
+
errorMessage = 'Unknown error occurred';
|
|
392
|
+
statusCode = null;
|
|
393
|
+
if (e_7.response) {
|
|
394
|
+
statusCode = e_7.response.status;
|
|
395
|
+
log.debug(tag, "HTTP Status: ", statusCode);
|
|
396
|
+
log.debug(tag, "Response headers: ", e_7.response.headers);
|
|
397
|
+
if (e_7.response.data) {
|
|
398
|
+
log.debug(tag, "Response data: ", e_7.response.data);
|
|
399
|
+
if (e_7.response.data.error) {
|
|
400
|
+
errorMessage = e_7.response.data.error;
|
|
401
|
+
log.error(tag, "API Error: ", errorMessage);
|
|
402
|
+
}
|
|
403
|
+
else if (typeof e_7.response.data === 'string') {
|
|
404
|
+
errorMessage = e_7.response.data;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
errorMessage = "HTTP ".concat(statusCode, ": ").concat(e_7.response.statusText || 'Request failed');
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
errorMessage = "HTTP ".concat(statusCode, ": ").concat(e_7.response.statusText || 'Request failed');
|
|
412
|
+
}
|
|
390
413
|
}
|
|
391
|
-
else if (
|
|
392
|
-
|
|
414
|
+
else if (e_7.request) {
|
|
415
|
+
// Request was made but no response received
|
|
416
|
+
errorMessage = 'Network error: No response received';
|
|
417
|
+
log.debug(tag, "Request config: ", (_a = e_7.config) === null || _a === void 0 ? void 0 : _a.url);
|
|
393
418
|
}
|
|
394
419
|
else {
|
|
395
|
-
|
|
420
|
+
// Something else happened
|
|
421
|
+
errorMessage = e_7.message || 'Request setup error';
|
|
396
422
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
423
|
+
output.error = errorMessage;
|
|
424
|
+
output.statusCode = statusCode;
|
|
425
|
+
return [3 /*break*/, 5];
|
|
426
|
+
case 5: return [2 /*return*/, output];
|
|
427
|
+
case 6:
|
|
428
|
+
e_8 = _b.sent();
|
|
429
|
+
console.error(tag, 'error: ', e_8);
|
|
430
|
+
throw e_8;
|
|
431
|
+
case 7: return [2 /*return*/];
|
|
403
432
|
}
|
|
404
433
|
});
|
|
405
434
|
});
|
|
406
435
|
};
|
|
407
436
|
var get_transaction = function (coin, txid) {
|
|
408
437
|
return __awaiter(this, void 0, void 0, function () {
|
|
409
|
-
var tag, url, body, resp,
|
|
438
|
+
var tag, url, body, resp, e_9;
|
|
410
439
|
return __generator(this, function (_a) {
|
|
411
440
|
switch (_a.label) {
|
|
412
441
|
case 0:
|
|
@@ -429,9 +458,9 @@ var get_transaction = function (coin, txid) {
|
|
|
429
458
|
resp = _a.sent();
|
|
430
459
|
return [2 /*return*/, resp.data];
|
|
431
460
|
case 3:
|
|
432
|
-
|
|
433
|
-
console.error(tag,
|
|
434
|
-
throw
|
|
461
|
+
e_9 = _a.sent();
|
|
462
|
+
console.error(tag, e_9);
|
|
463
|
+
throw e_9;
|
|
435
464
|
case 4: return [2 /*return*/];
|
|
436
465
|
}
|
|
437
466
|
});
|
|
@@ -439,7 +468,7 @@ var get_transaction = function (coin, txid) {
|
|
|
439
468
|
};
|
|
440
469
|
var get_utxos_by_xpub = function (coin, xpub) {
|
|
441
470
|
return __awaiter(this, void 0, void 0, function () {
|
|
442
|
-
var tag, url, body, resp,
|
|
471
|
+
var tag, url, body, resp, e_10;
|
|
443
472
|
return __generator(this, function (_a) {
|
|
444
473
|
switch (_a.label) {
|
|
445
474
|
case 0:
|
|
@@ -464,9 +493,9 @@ var get_utxos_by_xpub = function (coin, xpub) {
|
|
|
464
493
|
resp = _a.sent();
|
|
465
494
|
return [2 /*return*/, resp.data];
|
|
466
495
|
case 3:
|
|
467
|
-
|
|
468
|
-
console.error(tag,
|
|
469
|
-
throw
|
|
496
|
+
e_10 = _a.sent();
|
|
497
|
+
console.error(tag, e_10);
|
|
498
|
+
throw e_10;
|
|
470
499
|
case 4: return [2 /*return*/];
|
|
471
500
|
}
|
|
472
501
|
});
|
|
@@ -474,7 +503,7 @@ var get_utxos_by_xpub = function (coin, xpub) {
|
|
|
474
503
|
};
|
|
475
504
|
var get_balance_by_xpub = function (coin, xpub) {
|
|
476
505
|
return __awaiter(this, void 0, void 0, function () {
|
|
477
|
-
var tag, output, balance, i, uxto,
|
|
506
|
+
var tag, output, balance, i, uxto, e_11;
|
|
478
507
|
return __generator(this, function (_a) {
|
|
479
508
|
switch (_a.label) {
|
|
480
509
|
case 0:
|
|
@@ -496,9 +525,9 @@ var get_balance_by_xpub = function (coin, xpub) {
|
|
|
496
525
|
}
|
|
497
526
|
return [2 /*return*/, balance / 100000000];
|
|
498
527
|
case 3:
|
|
499
|
-
|
|
500
|
-
console.error(tag,
|
|
501
|
-
throw
|
|
528
|
+
e_11 = _a.sent();
|
|
529
|
+
console.error(tag, e_11);
|
|
530
|
+
throw e_11;
|
|
502
531
|
case 4: return [2 /*return*/];
|
|
503
532
|
}
|
|
504
533
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/blockbook",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.15",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
15
15
|
"@pioneer-platform/nodes": "^8.3.1",
|
|
16
|
+
"@pioneer-platform/pioneer-caip": "^9.2.38",
|
|
16
17
|
"@types/request-promise-native": "^1.0.17",
|
|
17
18
|
"axiom": "^0.1.6",
|
|
18
19
|
"axios": "^1.6.0",
|
|
19
20
|
"axios-retry": "^3.8.0",
|
|
20
|
-
"blockbook-client": "^
|
|
21
|
+
"blockbook-client": "^0.7.8",
|
|
21
22
|
"fake-useragent": "^1.0.1",
|
|
22
23
|
"long": "^5.2.3",
|
|
23
24
|
"request": "^2.88.2",
|