@pioneer-platform/thor-network 8.1.36 → 8.1.37
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 +62 -35
- 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_last_block: () => Promise<any>;
|
|
13
14
|
declare let get_block_height: () => Promise<any>;
|
|
14
15
|
declare let get_transaction: (txid: string) => Promise<any>;
|
|
15
16
|
declare let broadcast_transaction: (tx: 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
|
+
getLastBlock: function () {
|
|
101
|
+
return get_last_block();
|
|
102
|
+
},
|
|
100
103
|
getBlockHeight: function () {
|
|
101
104
|
return get_block_height();
|
|
102
105
|
},
|
|
@@ -119,13 +122,13 @@ module.exports = {
|
|
|
119
122
|
/**********************************
|
|
120
123
|
// Lib
|
|
121
124
|
//**********************************/
|
|
122
|
-
var
|
|
125
|
+
var get_last_block = function () {
|
|
123
126
|
return __awaiter(this, void 0, void 0, function () {
|
|
124
127
|
var tag, lastBlock, e_1;
|
|
125
128
|
return __generator(this, function (_a) {
|
|
126
129
|
switch (_a.label) {
|
|
127
130
|
case 0:
|
|
128
|
-
tag = TAG + " |
|
|
131
|
+
tag = TAG + " | get_last_block | ";
|
|
129
132
|
_a.label = 1;
|
|
130
133
|
case 1:
|
|
131
134
|
_a.trys.push([1, 3, , 4]);
|
|
@@ -133,7 +136,7 @@ var get_block_height = function () {
|
|
|
133
136
|
case 2:
|
|
134
137
|
lastBlock = _a.sent();
|
|
135
138
|
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
136
|
-
return [2 /*return*/, lastBlock.data.block
|
|
139
|
+
return [2 /*return*/, lastBlock.data.block];
|
|
137
140
|
case 3:
|
|
138
141
|
e_1 = _a.sent();
|
|
139
142
|
log.error(tag, "e: ", e_1);
|
|
@@ -143,9 +146,33 @@ var get_block_height = function () {
|
|
|
143
146
|
});
|
|
144
147
|
});
|
|
145
148
|
};
|
|
149
|
+
var get_block_height = function () {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var tag, lastBlock, e_2;
|
|
152
|
+
return __generator(this, function (_a) {
|
|
153
|
+
switch (_a.label) {
|
|
154
|
+
case 0:
|
|
155
|
+
tag = TAG + " | get_block_height | ";
|
|
156
|
+
_a.label = 1;
|
|
157
|
+
case 1:
|
|
158
|
+
_a.trys.push([1, 3, , 4]);
|
|
159
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
|
|
160
|
+
case 2:
|
|
161
|
+
lastBlock = _a.sent();
|
|
162
|
+
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
163
|
+
return [2 /*return*/, lastBlock.data.block.header.height];
|
|
164
|
+
case 3:
|
|
165
|
+
e_2 = _a.sent();
|
|
166
|
+
log.error(tag, "e: ", e_2);
|
|
167
|
+
throw e_2;
|
|
168
|
+
case 4: return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
146
173
|
var get_transaction = function (txid) {
|
|
147
174
|
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
-
var tag, txInfo,
|
|
175
|
+
var tag, txInfo, e_3, output;
|
|
149
176
|
return __generator(this, function (_a) {
|
|
150
177
|
switch (_a.label) {
|
|
151
178
|
case 0:
|
|
@@ -159,17 +186,17 @@ var get_transaction = function (txid) {
|
|
|
159
186
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
160
187
|
return [2 /*return*/, txInfo.data];
|
|
161
188
|
case 3:
|
|
162
|
-
|
|
189
|
+
e_3 = _a.sent();
|
|
163
190
|
// log.error(tag,e.response.data)
|
|
164
191
|
// log.error(tag,e.response.data.error)
|
|
165
|
-
if (
|
|
192
|
+
if (e_3.response.status === 404) {
|
|
166
193
|
output = {};
|
|
167
194
|
output.success = false;
|
|
168
|
-
output.error =
|
|
195
|
+
output.error = e_3.response.data.error;
|
|
169
196
|
return [2 /*return*/, output];
|
|
170
197
|
}
|
|
171
198
|
else {
|
|
172
|
-
throw Error(
|
|
199
|
+
throw Error(e_3);
|
|
173
200
|
}
|
|
174
201
|
return [3 /*break*/, 4];
|
|
175
202
|
case 4: return [2 /*return*/];
|
|
@@ -179,7 +206,7 @@ var get_transaction = function (txid) {
|
|
|
179
206
|
};
|
|
180
207
|
var broadcast_transaction = function (tx) {
|
|
181
208
|
return __awaiter(this, void 0, void 0, function () {
|
|
182
|
-
var tag, output, urlRemote, result2, logSend,
|
|
209
|
+
var tag, output, urlRemote, result2, logSend, e_4, e_5;
|
|
183
210
|
return __generator(this, function (_a) {
|
|
184
211
|
switch (_a.label) {
|
|
185
212
|
case 0:
|
|
@@ -221,21 +248,21 @@ var broadcast_transaction = function (tx) {
|
|
|
221
248
|
output.raw = result2.data;
|
|
222
249
|
return [3 /*break*/, 5];
|
|
223
250
|
case 4:
|
|
224
|
-
|
|
251
|
+
e_4 = _a.sent();
|
|
225
252
|
//log.error(tag,"failed second broadcast e: ",e.response)
|
|
226
|
-
log.error(tag,
|
|
227
|
-
log.error(tag,
|
|
228
|
-
log.error(tag,
|
|
229
|
-
log.error(tag,
|
|
230
|
-
log.error(tag,
|
|
253
|
+
log.error(tag, e_4);
|
|
254
|
+
log.error(tag, e_4.response);
|
|
255
|
+
log.error(tag, e_4.response.data);
|
|
256
|
+
log.error(tag, e_4.response.data.error);
|
|
257
|
+
log.error(tag, e_4.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
|
|
231
258
|
//throw e
|
|
232
259
|
output.success = false;
|
|
233
|
-
output.error =
|
|
260
|
+
output.error = e_4.response.data.error;
|
|
234
261
|
return [3 /*break*/, 5];
|
|
235
262
|
case 5: return [2 /*return*/, output];
|
|
236
263
|
case 6:
|
|
237
|
-
|
|
238
|
-
console.error(tag, "throw error: ",
|
|
264
|
+
e_5 = _a.sent();
|
|
265
|
+
console.error(tag, "throw error: ", e_5);
|
|
239
266
|
return [2 /*return*/, output];
|
|
240
267
|
case 7: return [2 /*return*/];
|
|
241
268
|
}
|
|
@@ -244,7 +271,7 @@ var broadcast_transaction = function (tx) {
|
|
|
244
271
|
};
|
|
245
272
|
var get_account_info = function (address) {
|
|
246
273
|
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
-
var tag, txInfo,
|
|
274
|
+
var tag, txInfo, e_6;
|
|
248
275
|
return __generator(this, function (_a) {
|
|
249
276
|
switch (_a.label) {
|
|
250
277
|
case 0:
|
|
@@ -260,9 +287,9 @@ var get_account_info = function (address) {
|
|
|
260
287
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
261
288
|
return [2 /*return*/, txInfo.data];
|
|
262
289
|
case 3:
|
|
263
|
-
|
|
264
|
-
log.error(tag, "e: ",
|
|
265
|
-
throw
|
|
290
|
+
e_6 = _a.sent();
|
|
291
|
+
log.error(tag, "e: ", e_6);
|
|
292
|
+
throw e_6;
|
|
266
293
|
case 4: return [2 /*return*/];
|
|
267
294
|
}
|
|
268
295
|
});
|
|
@@ -340,7 +367,7 @@ var normalize_tx = function (tx, address) {
|
|
|
340
367
|
};
|
|
341
368
|
var get_txs_by_address = function (address) {
|
|
342
369
|
return __awaiter(this, void 0, void 0, function () {
|
|
343
|
-
var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx,
|
|
370
|
+
var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx, e_7;
|
|
344
371
|
return __generator(this, function (_a) {
|
|
345
372
|
switch (_a.label) {
|
|
346
373
|
case 0:
|
|
@@ -390,9 +417,9 @@ var get_txs_by_address = function (address) {
|
|
|
390
417
|
}
|
|
391
418
|
return [2 /*return*/, output];
|
|
392
419
|
case 4:
|
|
393
|
-
|
|
394
|
-
log.error(tag, "e: ",
|
|
395
|
-
throw
|
|
420
|
+
e_7 = _a.sent();
|
|
421
|
+
log.error(tag, "e: ", e_7);
|
|
422
|
+
throw e_7;
|
|
396
423
|
case 5: return [2 /*return*/];
|
|
397
424
|
}
|
|
398
425
|
});
|
|
@@ -401,7 +428,7 @@ var get_txs_by_address = function (address) {
|
|
|
401
428
|
var get_balance = function (address) {
|
|
402
429
|
var _a;
|
|
403
430
|
return __awaiter(this, void 0, void 0, function () {
|
|
404
|
-
var tag, output, accountInfo, i, entry,
|
|
431
|
+
var tag, output, accountInfo, i, entry, e_8, e_9;
|
|
405
432
|
return __generator(this, function (_b) {
|
|
406
433
|
switch (_b.label) {
|
|
407
434
|
case 0:
|
|
@@ -429,13 +456,13 @@ var get_balance = function (address) {
|
|
|
429
456
|
output = output / BASE_THOR;
|
|
430
457
|
return [3 /*break*/, 5];
|
|
431
458
|
case 4:
|
|
432
|
-
|
|
459
|
+
e_8 = _b.sent();
|
|
433
460
|
return [3 /*break*/, 5];
|
|
434
461
|
case 5: return [2 /*return*/, output];
|
|
435
462
|
case 6:
|
|
436
|
-
|
|
437
|
-
log.error(tag, "e: ",
|
|
438
|
-
throw
|
|
463
|
+
e_9 = _b.sent();
|
|
464
|
+
log.error(tag, "e: ", e_9);
|
|
465
|
+
throw e_9;
|
|
439
466
|
case 7: return [2 /*return*/];
|
|
440
467
|
}
|
|
441
468
|
});
|
|
@@ -443,7 +470,7 @@ var get_balance = function (address) {
|
|
|
443
470
|
};
|
|
444
471
|
var get_node_info_verbose = function () {
|
|
445
472
|
return __awaiter(this, void 0, void 0, function () {
|
|
446
|
-
var tag, output, syncInfo, nodeInfo, lastBlock,
|
|
473
|
+
var tag, output, syncInfo, nodeInfo, lastBlock, e_10;
|
|
447
474
|
return __generator(this, function (_a) {
|
|
448
475
|
switch (_a.label) {
|
|
449
476
|
case 0:
|
|
@@ -470,9 +497,9 @@ var get_node_info_verbose = function () {
|
|
|
470
497
|
output.height = lastBlock.data.block.header.height;
|
|
471
498
|
return [2 /*return*/, output];
|
|
472
499
|
case 5:
|
|
473
|
-
|
|
474
|
-
log.error(tag, "e: ",
|
|
475
|
-
throw
|
|
500
|
+
e_10 = _a.sent();
|
|
501
|
+
log.error(tag, "e: ", e_10);
|
|
502
|
+
throw e_10;
|
|
476
503
|
case 6: return [2 /*return*/];
|
|
477
504
|
}
|
|
478
505
|
});
|