@pioneer-platform/thor-network 8.1.33 → 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 +2 -0
- package/lib/index.js +90 -33
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ declare let BASE_THOR: number;
|
|
|
10
10
|
/**********************************
|
|
11
11
|
// Lib
|
|
12
12
|
//**********************************/
|
|
13
|
+
declare let get_last_block: () => Promise<any>;
|
|
14
|
+
declare let get_block_height: () => Promise<any>;
|
|
13
15
|
declare let get_transaction: (txid: string) => Promise<any>;
|
|
14
16
|
declare let broadcast_transaction: (tx: string) => Promise<any>;
|
|
15
17
|
declare let get_account_info: (address: string) => Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -97,6 +97,12 @@ 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
|
+
},
|
|
103
|
+
getBlockHeight: function () {
|
|
104
|
+
return get_block_height();
|
|
105
|
+
},
|
|
100
106
|
getAccountInfo: function (address) {
|
|
101
107
|
return get_account_info(address);
|
|
102
108
|
},
|
|
@@ -116,9 +122,57 @@ module.exports = {
|
|
|
116
122
|
/**********************************
|
|
117
123
|
// Lib
|
|
118
124
|
//**********************************/
|
|
125
|
+
var get_last_block = function () {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
var tag, lastBlock, e_1;
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
tag = TAG + " | get_last_block | ";
|
|
132
|
+
_a.label = 1;
|
|
133
|
+
case 1:
|
|
134
|
+
_a.trys.push([1, 3, , 4]);
|
|
135
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
|
|
136
|
+
case 2:
|
|
137
|
+
lastBlock = _a.sent();
|
|
138
|
+
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
139
|
+
return [2 /*return*/, lastBlock.data.block];
|
|
140
|
+
case 3:
|
|
141
|
+
e_1 = _a.sent();
|
|
142
|
+
log.error(tag, "e: ", e_1);
|
|
143
|
+
throw e_1;
|
|
144
|
+
case 4: return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
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
|
+
};
|
|
119
173
|
var get_transaction = function (txid) {
|
|
120
174
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var tag, txInfo,
|
|
175
|
+
var tag, txInfo, e_3, output;
|
|
122
176
|
return __generator(this, function (_a) {
|
|
123
177
|
switch (_a.label) {
|
|
124
178
|
case 0:
|
|
@@ -132,17 +186,17 @@ var get_transaction = function (txid) {
|
|
|
132
186
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
133
187
|
return [2 /*return*/, txInfo.data];
|
|
134
188
|
case 3:
|
|
135
|
-
|
|
189
|
+
e_3 = _a.sent();
|
|
136
190
|
// log.error(tag,e.response.data)
|
|
137
191
|
// log.error(tag,e.response.data.error)
|
|
138
|
-
if (
|
|
192
|
+
if (e_3.response.status === 404) {
|
|
139
193
|
output = {};
|
|
140
194
|
output.success = false;
|
|
141
|
-
output.error =
|
|
195
|
+
output.error = e_3.response.data.error;
|
|
142
196
|
return [2 /*return*/, output];
|
|
143
197
|
}
|
|
144
198
|
else {
|
|
145
|
-
throw Error(
|
|
199
|
+
throw Error(e_3);
|
|
146
200
|
}
|
|
147
201
|
return [3 /*break*/, 4];
|
|
148
202
|
case 4: return [2 /*return*/];
|
|
@@ -152,7 +206,7 @@ var get_transaction = function (txid) {
|
|
|
152
206
|
};
|
|
153
207
|
var broadcast_transaction = function (tx) {
|
|
154
208
|
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
-
var tag, output, urlRemote, result2, logSend,
|
|
209
|
+
var tag, output, urlRemote, result2, logSend, e_4, e_5;
|
|
156
210
|
return __generator(this, function (_a) {
|
|
157
211
|
switch (_a.label) {
|
|
158
212
|
case 0:
|
|
@@ -179,33 +233,36 @@ var broadcast_transaction = function (tx) {
|
|
|
179
233
|
if (result2 && result2.data && result2.data.txhash)
|
|
180
234
|
output.txid = result2.data.txhash;
|
|
181
235
|
//verify success
|
|
182
|
-
if (result2.data.raw_log) {
|
|
236
|
+
if (result2.data.raw_log && result2.data.raw_log !== '[]') {
|
|
183
237
|
logSend = result2.data.raw_log;
|
|
184
238
|
log.info(tag, "logSend: ", logSend);
|
|
185
239
|
output.success = false;
|
|
186
240
|
output.error = logSend;
|
|
187
241
|
}
|
|
242
|
+
else {
|
|
243
|
+
output.success = true;
|
|
244
|
+
}
|
|
188
245
|
output.height = result2.height;
|
|
189
246
|
output.gas_wanted = result2.gas_wanted;
|
|
190
247
|
output.gas_used = result2.gas_used;
|
|
191
248
|
output.raw = result2.data;
|
|
192
249
|
return [3 /*break*/, 5];
|
|
193
250
|
case 4:
|
|
194
|
-
|
|
251
|
+
e_4 = _a.sent();
|
|
195
252
|
//log.error(tag,"failed second broadcast e: ",e.response)
|
|
196
|
-
log.error(tag,
|
|
197
|
-
log.error(tag,
|
|
198
|
-
log.error(tag,
|
|
199
|
-
log.error(tag,
|
|
200
|
-
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'));
|
|
201
258
|
//throw e
|
|
202
259
|
output.success = false;
|
|
203
|
-
output.error =
|
|
260
|
+
output.error = e_4.response.data.error;
|
|
204
261
|
return [3 /*break*/, 5];
|
|
205
262
|
case 5: return [2 /*return*/, output];
|
|
206
263
|
case 6:
|
|
207
|
-
|
|
208
|
-
console.error(tag, "throw error: ",
|
|
264
|
+
e_5 = _a.sent();
|
|
265
|
+
console.error(tag, "throw error: ", e_5);
|
|
209
266
|
return [2 /*return*/, output];
|
|
210
267
|
case 7: return [2 /*return*/];
|
|
211
268
|
}
|
|
@@ -214,7 +271,7 @@ var broadcast_transaction = function (tx) {
|
|
|
214
271
|
};
|
|
215
272
|
var get_account_info = function (address) {
|
|
216
273
|
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
-
var tag, txInfo,
|
|
274
|
+
var tag, txInfo, e_6;
|
|
218
275
|
return __generator(this, function (_a) {
|
|
219
276
|
switch (_a.label) {
|
|
220
277
|
case 0:
|
|
@@ -230,9 +287,9 @@ var get_account_info = function (address) {
|
|
|
230
287
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
231
288
|
return [2 /*return*/, txInfo.data];
|
|
232
289
|
case 3:
|
|
233
|
-
|
|
234
|
-
log.error(tag, "e: ",
|
|
235
|
-
throw
|
|
290
|
+
e_6 = _a.sent();
|
|
291
|
+
log.error(tag, "e: ", e_6);
|
|
292
|
+
throw e_6;
|
|
236
293
|
case 4: return [2 /*return*/];
|
|
237
294
|
}
|
|
238
295
|
});
|
|
@@ -310,7 +367,7 @@ var normalize_tx = function (tx, address) {
|
|
|
310
367
|
};
|
|
311
368
|
var get_txs_by_address = function (address) {
|
|
312
369
|
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
-
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;
|
|
314
371
|
return __generator(this, function (_a) {
|
|
315
372
|
switch (_a.label) {
|
|
316
373
|
case 0:
|
|
@@ -360,9 +417,9 @@ var get_txs_by_address = function (address) {
|
|
|
360
417
|
}
|
|
361
418
|
return [2 /*return*/, output];
|
|
362
419
|
case 4:
|
|
363
|
-
|
|
364
|
-
log.error(tag, "e: ",
|
|
365
|
-
throw
|
|
420
|
+
e_7 = _a.sent();
|
|
421
|
+
log.error(tag, "e: ", e_7);
|
|
422
|
+
throw e_7;
|
|
366
423
|
case 5: return [2 /*return*/];
|
|
367
424
|
}
|
|
368
425
|
});
|
|
@@ -371,7 +428,7 @@ var get_txs_by_address = function (address) {
|
|
|
371
428
|
var get_balance = function (address) {
|
|
372
429
|
var _a;
|
|
373
430
|
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
-
var tag, output, accountInfo, i, entry,
|
|
431
|
+
var tag, output, accountInfo, i, entry, e_8, e_9;
|
|
375
432
|
return __generator(this, function (_b) {
|
|
376
433
|
switch (_b.label) {
|
|
377
434
|
case 0:
|
|
@@ -399,13 +456,13 @@ var get_balance = function (address) {
|
|
|
399
456
|
output = output / BASE_THOR;
|
|
400
457
|
return [3 /*break*/, 5];
|
|
401
458
|
case 4:
|
|
402
|
-
|
|
459
|
+
e_8 = _b.sent();
|
|
403
460
|
return [3 /*break*/, 5];
|
|
404
461
|
case 5: return [2 /*return*/, output];
|
|
405
462
|
case 6:
|
|
406
|
-
|
|
407
|
-
log.error(tag, "e: ",
|
|
408
|
-
throw
|
|
463
|
+
e_9 = _b.sent();
|
|
464
|
+
log.error(tag, "e: ", e_9);
|
|
465
|
+
throw e_9;
|
|
409
466
|
case 7: return [2 /*return*/];
|
|
410
467
|
}
|
|
411
468
|
});
|
|
@@ -413,7 +470,7 @@ var get_balance = function (address) {
|
|
|
413
470
|
};
|
|
414
471
|
var get_node_info_verbose = function () {
|
|
415
472
|
return __awaiter(this, void 0, void 0, function () {
|
|
416
|
-
var tag, output, syncInfo, nodeInfo, lastBlock,
|
|
473
|
+
var tag, output, syncInfo, nodeInfo, lastBlock, e_10;
|
|
417
474
|
return __generator(this, function (_a) {
|
|
418
475
|
switch (_a.label) {
|
|
419
476
|
case 0:
|
|
@@ -440,9 +497,9 @@ var get_node_info_verbose = function () {
|
|
|
440
497
|
output.height = lastBlock.data.block.header.height;
|
|
441
498
|
return [2 /*return*/, output];
|
|
442
499
|
case 5:
|
|
443
|
-
|
|
444
|
-
log.error(tag, "e: ",
|
|
445
|
-
throw
|
|
500
|
+
e_10 = _a.sent();
|
|
501
|
+
log.error(tag, "e: ", e_10);
|
|
502
|
+
throw e_10;
|
|
446
503
|
case 6: return [2 /*return*/];
|
|
447
504
|
}
|
|
448
505
|
});
|