@pioneer-platform/thor-network 8.1.35 → 8.1.36
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 -0
- package/lib/index.js +59 -32
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare let BASE_THOR: number;
|
|
|
10
10
|
/**********************************
|
|
11
11
|
// Lib
|
|
12
12
|
//**********************************/
|
|
13
|
+
declare let get_block_height: () => Promise<any>;
|
|
13
14
|
declare let get_transaction: (txid: string) => Promise<any>;
|
|
14
15
|
declare let broadcast_transaction: (tx: string) => Promise<any>;
|
|
15
16
|
declare let get_account_info: (address: string) => Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -97,6 +97,9 @@ module.exports = {
|
|
|
97
97
|
getAccount: function (address) {
|
|
98
98
|
return get_account_info(address);
|
|
99
99
|
},
|
|
100
|
+
getBlockHeight: function () {
|
|
101
|
+
return get_block_height();
|
|
102
|
+
},
|
|
100
103
|
getAccountInfo: function (address) {
|
|
101
104
|
return get_account_info(address);
|
|
102
105
|
},
|
|
@@ -116,9 +119,33 @@ module.exports = {
|
|
|
116
119
|
/**********************************
|
|
117
120
|
// Lib
|
|
118
121
|
//**********************************/
|
|
122
|
+
var get_block_height = function () {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var tag, lastBlock, e_1;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
tag = TAG + " | get_block_height | ";
|
|
129
|
+
_a.label = 1;
|
|
130
|
+
case 1:
|
|
131
|
+
_a.trys.push([1, 3, , 4]);
|
|
132
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
|
|
133
|
+
case 2:
|
|
134
|
+
lastBlock = _a.sent();
|
|
135
|
+
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
136
|
+
return [2 /*return*/, lastBlock.data.block.header.height];
|
|
137
|
+
case 3:
|
|
138
|
+
e_1 = _a.sent();
|
|
139
|
+
log.error(tag, "e: ", e_1);
|
|
140
|
+
throw e_1;
|
|
141
|
+
case 4: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
119
146
|
var get_transaction = function (txid) {
|
|
120
147
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var tag, txInfo,
|
|
148
|
+
var tag, txInfo, e_2, output;
|
|
122
149
|
return __generator(this, function (_a) {
|
|
123
150
|
switch (_a.label) {
|
|
124
151
|
case 0:
|
|
@@ -132,17 +159,17 @@ var get_transaction = function (txid) {
|
|
|
132
159
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
133
160
|
return [2 /*return*/, txInfo.data];
|
|
134
161
|
case 3:
|
|
135
|
-
|
|
162
|
+
e_2 = _a.sent();
|
|
136
163
|
// log.error(tag,e.response.data)
|
|
137
164
|
// log.error(tag,e.response.data.error)
|
|
138
|
-
if (
|
|
165
|
+
if (e_2.response.status === 404) {
|
|
139
166
|
output = {};
|
|
140
167
|
output.success = false;
|
|
141
|
-
output.error =
|
|
168
|
+
output.error = e_2.response.data.error;
|
|
142
169
|
return [2 /*return*/, output];
|
|
143
170
|
}
|
|
144
171
|
else {
|
|
145
|
-
throw Error(
|
|
172
|
+
throw Error(e_2);
|
|
146
173
|
}
|
|
147
174
|
return [3 /*break*/, 4];
|
|
148
175
|
case 4: return [2 /*return*/];
|
|
@@ -152,7 +179,7 @@ var get_transaction = function (txid) {
|
|
|
152
179
|
};
|
|
153
180
|
var broadcast_transaction = function (tx) {
|
|
154
181
|
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
-
var tag, output, urlRemote, result2, logSend,
|
|
182
|
+
var tag, output, urlRemote, result2, logSend, e_3, e_4;
|
|
156
183
|
return __generator(this, function (_a) {
|
|
157
184
|
switch (_a.label) {
|
|
158
185
|
case 0:
|
|
@@ -194,21 +221,21 @@ var broadcast_transaction = function (tx) {
|
|
|
194
221
|
output.raw = result2.data;
|
|
195
222
|
return [3 /*break*/, 5];
|
|
196
223
|
case 4:
|
|
197
|
-
|
|
224
|
+
e_3 = _a.sent();
|
|
198
225
|
//log.error(tag,"failed second broadcast e: ",e.response)
|
|
199
|
-
log.error(tag,
|
|
200
|
-
log.error(tag,
|
|
201
|
-
log.error(tag,
|
|
202
|
-
log.error(tag,
|
|
203
|
-
log.error(tag,
|
|
226
|
+
log.error(tag, e_3);
|
|
227
|
+
log.error(tag, e_3.response);
|
|
228
|
+
log.error(tag, e_3.response.data);
|
|
229
|
+
log.error(tag, e_3.response.data.error);
|
|
230
|
+
log.error(tag, e_3.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
|
|
204
231
|
//throw e
|
|
205
232
|
output.success = false;
|
|
206
|
-
output.error =
|
|
233
|
+
output.error = e_3.response.data.error;
|
|
207
234
|
return [3 /*break*/, 5];
|
|
208
235
|
case 5: return [2 /*return*/, output];
|
|
209
236
|
case 6:
|
|
210
|
-
|
|
211
|
-
console.error(tag, "throw error: ",
|
|
237
|
+
e_4 = _a.sent();
|
|
238
|
+
console.error(tag, "throw error: ", e_4);
|
|
212
239
|
return [2 /*return*/, output];
|
|
213
240
|
case 7: return [2 /*return*/];
|
|
214
241
|
}
|
|
@@ -217,7 +244,7 @@ var broadcast_transaction = function (tx) {
|
|
|
217
244
|
};
|
|
218
245
|
var get_account_info = function (address) {
|
|
219
246
|
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
-
var tag, txInfo,
|
|
247
|
+
var tag, txInfo, e_5;
|
|
221
248
|
return __generator(this, function (_a) {
|
|
222
249
|
switch (_a.label) {
|
|
223
250
|
case 0:
|
|
@@ -233,9 +260,9 @@ var get_account_info = function (address) {
|
|
|
233
260
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
234
261
|
return [2 /*return*/, txInfo.data];
|
|
235
262
|
case 3:
|
|
236
|
-
|
|
237
|
-
log.error(tag, "e: ",
|
|
238
|
-
throw
|
|
263
|
+
e_5 = _a.sent();
|
|
264
|
+
log.error(tag, "e: ", e_5);
|
|
265
|
+
throw e_5;
|
|
239
266
|
case 4: return [2 /*return*/];
|
|
240
267
|
}
|
|
241
268
|
});
|
|
@@ -313,7 +340,7 @@ var normalize_tx = function (tx, address) {
|
|
|
313
340
|
};
|
|
314
341
|
var get_txs_by_address = function (address) {
|
|
315
342
|
return __awaiter(this, void 0, void 0, function () {
|
|
316
|
-
var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx,
|
|
343
|
+
var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx, e_6;
|
|
317
344
|
return __generator(this, function (_a) {
|
|
318
345
|
switch (_a.label) {
|
|
319
346
|
case 0:
|
|
@@ -363,9 +390,9 @@ var get_txs_by_address = function (address) {
|
|
|
363
390
|
}
|
|
364
391
|
return [2 /*return*/, output];
|
|
365
392
|
case 4:
|
|
366
|
-
|
|
367
|
-
log.error(tag, "e: ",
|
|
368
|
-
throw
|
|
393
|
+
e_6 = _a.sent();
|
|
394
|
+
log.error(tag, "e: ", e_6);
|
|
395
|
+
throw e_6;
|
|
369
396
|
case 5: return [2 /*return*/];
|
|
370
397
|
}
|
|
371
398
|
});
|
|
@@ -374,7 +401,7 @@ var get_txs_by_address = function (address) {
|
|
|
374
401
|
var get_balance = function (address) {
|
|
375
402
|
var _a;
|
|
376
403
|
return __awaiter(this, void 0, void 0, function () {
|
|
377
|
-
var tag, output, accountInfo, i, entry,
|
|
404
|
+
var tag, output, accountInfo, i, entry, e_7, e_8;
|
|
378
405
|
return __generator(this, function (_b) {
|
|
379
406
|
switch (_b.label) {
|
|
380
407
|
case 0:
|
|
@@ -402,13 +429,13 @@ var get_balance = function (address) {
|
|
|
402
429
|
output = output / BASE_THOR;
|
|
403
430
|
return [3 /*break*/, 5];
|
|
404
431
|
case 4:
|
|
405
|
-
|
|
432
|
+
e_7 = _b.sent();
|
|
406
433
|
return [3 /*break*/, 5];
|
|
407
434
|
case 5: return [2 /*return*/, output];
|
|
408
435
|
case 6:
|
|
409
|
-
|
|
410
|
-
log.error(tag, "e: ",
|
|
411
|
-
throw
|
|
436
|
+
e_8 = _b.sent();
|
|
437
|
+
log.error(tag, "e: ", e_8);
|
|
438
|
+
throw e_8;
|
|
412
439
|
case 7: return [2 /*return*/];
|
|
413
440
|
}
|
|
414
441
|
});
|
|
@@ -416,7 +443,7 @@ var get_balance = function (address) {
|
|
|
416
443
|
};
|
|
417
444
|
var get_node_info_verbose = function () {
|
|
418
445
|
return __awaiter(this, void 0, void 0, function () {
|
|
419
|
-
var tag, output, syncInfo, nodeInfo, lastBlock,
|
|
446
|
+
var tag, output, syncInfo, nodeInfo, lastBlock, e_9;
|
|
420
447
|
return __generator(this, function (_a) {
|
|
421
448
|
switch (_a.label) {
|
|
422
449
|
case 0:
|
|
@@ -443,9 +470,9 @@ var get_node_info_verbose = function () {
|
|
|
443
470
|
output.height = lastBlock.data.block.header.height;
|
|
444
471
|
return [2 /*return*/, output];
|
|
445
472
|
case 5:
|
|
446
|
-
|
|
447
|
-
log.error(tag, "e: ",
|
|
448
|
-
throw
|
|
473
|
+
e_9 = _a.sent();
|
|
474
|
+
log.error(tag, "e: ", e_9);
|
|
475
|
+
throw e_9;
|
|
449
476
|
case 6: return [2 /*return*/];
|
|
450
477
|
}
|
|
451
478
|
});
|