@pioneer-platform/maya-network 8.3.3 → 8.3.5
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 +3 -0
- package/lib/index.js +148 -41
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ declare let BASE_THOR: number;
|
|
|
11
11
|
/**********************************
|
|
12
12
|
// Lib
|
|
13
13
|
//**********************************/
|
|
14
|
+
declare const get_pool: (poolId: string) => Promise<any>;
|
|
15
|
+
declare const get_pools: () => Promise<any>;
|
|
16
|
+
declare const get_pool_addresses: () => Promise<any>;
|
|
14
17
|
declare let get_last_block: () => Promise<any>;
|
|
15
18
|
declare let get_block_height: () => Promise<any>;
|
|
16
19
|
declare let get_transaction: (txid: string) => Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -76,7 +76,7 @@ axiosRetry(axios, {
|
|
|
76
76
|
});
|
|
77
77
|
var log = require('@pioneer-platform/loggerdog')();
|
|
78
78
|
var URL_THORNODE = 'https://mayanode.mayachain.info';
|
|
79
|
-
var URL_MIDGARD = 'https://midgard.mayachain.info/v2
|
|
79
|
+
var URL_MIDGARD = 'https://midgard.mayachain.info/v2';
|
|
80
80
|
var BASE_THOR = 100000000;
|
|
81
81
|
/**********************************
|
|
82
82
|
// Module
|
|
@@ -106,6 +106,15 @@ module.exports = {
|
|
|
106
106
|
getAccountInfo: function (address) {
|
|
107
107
|
return get_account_info(address);
|
|
108
108
|
},
|
|
109
|
+
getPools: function () {
|
|
110
|
+
return get_pools();
|
|
111
|
+
},
|
|
112
|
+
getPool: function (poolId) {
|
|
113
|
+
return get_pool(poolId);
|
|
114
|
+
},
|
|
115
|
+
getPoolAddress: function () {
|
|
116
|
+
return get_pool_addresses();
|
|
117
|
+
},
|
|
109
118
|
txs: function (address) {
|
|
110
119
|
return get_txs_by_address(address);
|
|
111
120
|
},
|
|
@@ -122,9 +131,107 @@ module.exports = {
|
|
|
122
131
|
/**********************************
|
|
123
132
|
// Lib
|
|
124
133
|
//**********************************/
|
|
134
|
+
var get_pool = function (poolId) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var tag, params, body, resp, e_1;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
switch (_a.label) {
|
|
139
|
+
case 0:
|
|
140
|
+
tag = TAG + " | get_pool | ";
|
|
141
|
+
_a.label = 1;
|
|
142
|
+
case 1:
|
|
143
|
+
_a.trys.push([1, 3, , 4]);
|
|
144
|
+
params = {
|
|
145
|
+
view: "full",
|
|
146
|
+
asset: poolId
|
|
147
|
+
};
|
|
148
|
+
body = {
|
|
149
|
+
method: 'GET',
|
|
150
|
+
url: URL_MIDGARD + "/pools/detail",
|
|
151
|
+
headers: { 'content-type': 'application/json' },
|
|
152
|
+
params: params
|
|
153
|
+
};
|
|
154
|
+
log.debug(body);
|
|
155
|
+
return [4 /*yield*/, axios(body)];
|
|
156
|
+
case 2:
|
|
157
|
+
resp = _a.sent();
|
|
158
|
+
return [2 /*return*/, resp.data];
|
|
159
|
+
case 3:
|
|
160
|
+
e_1 = _a.sent();
|
|
161
|
+
log.error(tag, "e: ", e_1);
|
|
162
|
+
throw e_1;
|
|
163
|
+
case 4: return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
var get_pools = function () {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
170
|
+
var tag, body, resp, e_2;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
tag = TAG + " | get_pools | ";
|
|
175
|
+
_a.label = 1;
|
|
176
|
+
case 1:
|
|
177
|
+
_a.trys.push([1, 3, , 4]);
|
|
178
|
+
body = {
|
|
179
|
+
method: 'GET',
|
|
180
|
+
url: URL_MIDGARD + "/pools",
|
|
181
|
+
headers: { 'content-type': 'application/json' },
|
|
182
|
+
// body: {account_name: actor},
|
|
183
|
+
// json: true
|
|
184
|
+
};
|
|
185
|
+
log.debug(body.url);
|
|
186
|
+
return [4 /*yield*/, axios(body)];
|
|
187
|
+
case 2:
|
|
188
|
+
resp = _a.sent();
|
|
189
|
+
return [2 /*return*/, resp.data];
|
|
190
|
+
case 3:
|
|
191
|
+
e_2 = _a.sent();
|
|
192
|
+
log.error(tag, "e: ", e_2);
|
|
193
|
+
throw e_2;
|
|
194
|
+
case 4: return [2 /*return*/];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
//https://testnet.thornode.thorchain.info/thorchain/inbound_addresses
|
|
200
|
+
var get_pool_addresses = function () {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
+
var tag, output, body, resp, e_3;
|
|
203
|
+
return __generator(this, function (_a) {
|
|
204
|
+
switch (_a.label) {
|
|
205
|
+
case 0:
|
|
206
|
+
tag = TAG + " | get_pool_addresses | ";
|
|
207
|
+
_a.label = 1;
|
|
208
|
+
case 1:
|
|
209
|
+
_a.trys.push([1, 3, , 4]);
|
|
210
|
+
output = {};
|
|
211
|
+
body = {
|
|
212
|
+
method: 'GET',
|
|
213
|
+
url: URL_THORNODE + "/thorchain/inbound_addresses",
|
|
214
|
+
headers: { 'content-type': 'application/json' },
|
|
215
|
+
// body: {account_name: actor},
|
|
216
|
+
// json: true
|
|
217
|
+
};
|
|
218
|
+
log.debug(body);
|
|
219
|
+
return [4 /*yield*/, axios(body)];
|
|
220
|
+
case 2:
|
|
221
|
+
resp = _a.sent();
|
|
222
|
+
return [2 /*return*/, resp.data];
|
|
223
|
+
case 3:
|
|
224
|
+
e_3 = _a.sent();
|
|
225
|
+
log.error(tag, "e: ", e_3);
|
|
226
|
+
return [3 /*break*/, 4];
|
|
227
|
+
case 4: return [2 /*return*/];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
};
|
|
125
232
|
var get_last_block = function () {
|
|
126
233
|
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
-
var tag, lastBlock,
|
|
234
|
+
var tag, lastBlock, e_4;
|
|
128
235
|
return __generator(this, function (_a) {
|
|
129
236
|
switch (_a.label) {
|
|
130
237
|
case 0:
|
|
@@ -138,9 +245,9 @@ var get_last_block = function () {
|
|
|
138
245
|
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
139
246
|
return [2 /*return*/, lastBlock.data.block];
|
|
140
247
|
case 3:
|
|
141
|
-
|
|
142
|
-
log.error(tag, "e: ",
|
|
143
|
-
throw
|
|
248
|
+
e_4 = _a.sent();
|
|
249
|
+
log.error(tag, "e: ", e_4);
|
|
250
|
+
throw e_4;
|
|
144
251
|
case 4: return [2 /*return*/];
|
|
145
252
|
}
|
|
146
253
|
});
|
|
@@ -148,7 +255,7 @@ var get_last_block = function () {
|
|
|
148
255
|
};
|
|
149
256
|
var get_block_height = function () {
|
|
150
257
|
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
var tag, lastBlock,
|
|
258
|
+
var tag, lastBlock, e_5;
|
|
152
259
|
return __generator(this, function (_a) {
|
|
153
260
|
switch (_a.label) {
|
|
154
261
|
case 0:
|
|
@@ -162,9 +269,9 @@ var get_block_height = function () {
|
|
|
162
269
|
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
163
270
|
return [2 /*return*/, lastBlock.data.block.header.height];
|
|
164
271
|
case 3:
|
|
165
|
-
|
|
166
|
-
log.error(tag, "e: ",
|
|
167
|
-
throw
|
|
272
|
+
e_5 = _a.sent();
|
|
273
|
+
log.error(tag, "e: ", e_5);
|
|
274
|
+
throw e_5;
|
|
168
275
|
case 4: return [2 /*return*/];
|
|
169
276
|
}
|
|
170
277
|
});
|
|
@@ -172,7 +279,7 @@ var get_block_height = function () {
|
|
|
172
279
|
};
|
|
173
280
|
var get_transaction = function (txid) {
|
|
174
281
|
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
-
var tag, txInfo,
|
|
282
|
+
var tag, txInfo, e_6, output;
|
|
176
283
|
return __generator(this, function (_a) {
|
|
177
284
|
switch (_a.label) {
|
|
178
285
|
case 0:
|
|
@@ -186,17 +293,17 @@ var get_transaction = function (txid) {
|
|
|
186
293
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
187
294
|
return [2 /*return*/, txInfo.data];
|
|
188
295
|
case 3:
|
|
189
|
-
|
|
296
|
+
e_6 = _a.sent();
|
|
190
297
|
// log.error(tag,e.response.data)
|
|
191
298
|
// log.error(tag,e.response.data.error)
|
|
192
|
-
if (
|
|
299
|
+
if (e_6.response.status === 404) {
|
|
193
300
|
output = {};
|
|
194
301
|
output.success = false;
|
|
195
|
-
output.error =
|
|
302
|
+
output.error = e_6.response.data.error;
|
|
196
303
|
return [2 /*return*/, output];
|
|
197
304
|
}
|
|
198
305
|
else {
|
|
199
|
-
throw Error(
|
|
306
|
+
throw Error(e_6);
|
|
200
307
|
}
|
|
201
308
|
return [3 /*break*/, 4];
|
|
202
309
|
case 4: return [2 /*return*/];
|
|
@@ -206,7 +313,7 @@ var get_transaction = function (txid) {
|
|
|
206
313
|
};
|
|
207
314
|
var broadcast_transaction = function (tx) {
|
|
208
315
|
return __awaiter(this, void 0, void 0, function () {
|
|
209
|
-
var tag, output, payload, urlRemote, result2,
|
|
316
|
+
var tag, output, payload, urlRemote, result2, e_7, e_8;
|
|
210
317
|
return __generator(this, function (_a) {
|
|
211
318
|
switch (_a.label) {
|
|
212
319
|
case 0:
|
|
@@ -246,21 +353,21 @@ var broadcast_transaction = function (tx) {
|
|
|
246
353
|
output.txid = result2.data.txhash;
|
|
247
354
|
return [3 /*break*/, 5];
|
|
248
355
|
case 4:
|
|
249
|
-
|
|
356
|
+
e_7 = _a.sent();
|
|
250
357
|
//log.error(tag,"failed second broadcast e: ",e.response)
|
|
251
|
-
log.error(tag,
|
|
252
|
-
log.error(tag,
|
|
253
|
-
log.error(tag,
|
|
254
|
-
log.error(tag,
|
|
255
|
-
log.error(tag,
|
|
358
|
+
log.error(tag, e_7);
|
|
359
|
+
log.error(tag, e_7.response);
|
|
360
|
+
log.error(tag, e_7.response.data);
|
|
361
|
+
log.error(tag, e_7.response.data.error);
|
|
362
|
+
log.error(tag, e_7.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
|
|
256
363
|
//throw e
|
|
257
364
|
output.success = false;
|
|
258
|
-
output.error =
|
|
365
|
+
output.error = e_7.response.data.error;
|
|
259
366
|
return [3 /*break*/, 5];
|
|
260
367
|
case 5: return [2 /*return*/, output];
|
|
261
368
|
case 6:
|
|
262
|
-
|
|
263
|
-
console.error(tag, "throw error: ",
|
|
369
|
+
e_8 = _a.sent();
|
|
370
|
+
console.error(tag, "throw error: ", e_8);
|
|
264
371
|
return [2 /*return*/, output];
|
|
265
372
|
case 7: return [2 /*return*/];
|
|
266
373
|
}
|
|
@@ -269,7 +376,7 @@ var broadcast_transaction = function (tx) {
|
|
|
269
376
|
};
|
|
270
377
|
var get_account_info = function (address) {
|
|
271
378
|
return __awaiter(this, void 0, void 0, function () {
|
|
272
|
-
var tag, txInfo,
|
|
379
|
+
var tag, txInfo, e_9;
|
|
273
380
|
return __generator(this, function (_a) {
|
|
274
381
|
switch (_a.label) {
|
|
275
382
|
case 0:
|
|
@@ -285,9 +392,9 @@ var get_account_info = function (address) {
|
|
|
285
392
|
log.debug(tag, "txInfo: ", txInfo.data);
|
|
286
393
|
return [2 /*return*/, txInfo.data];
|
|
287
394
|
case 3:
|
|
288
|
-
|
|
289
|
-
log.error(tag, "e: ",
|
|
290
|
-
throw
|
|
395
|
+
e_9 = _a.sent();
|
|
396
|
+
log.error(tag, "e: ", e_9);
|
|
397
|
+
throw e_9;
|
|
291
398
|
case 4: return [2 /*return*/];
|
|
292
399
|
}
|
|
293
400
|
});
|
|
@@ -365,7 +472,7 @@ var normalize_tx = function (tx, address) {
|
|
|
365
472
|
};
|
|
366
473
|
var get_txs_by_address = function (address) {
|
|
367
474
|
return __awaiter(this, void 0, void 0, function () {
|
|
368
|
-
var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx,
|
|
475
|
+
var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx, e_10;
|
|
369
476
|
return __generator(this, function (_a) {
|
|
370
477
|
switch (_a.label) {
|
|
371
478
|
case 0:
|
|
@@ -415,9 +522,9 @@ var get_txs_by_address = function (address) {
|
|
|
415
522
|
}
|
|
416
523
|
return [2 /*return*/, output];
|
|
417
524
|
case 4:
|
|
418
|
-
|
|
419
|
-
log.error(tag, "e: ",
|
|
420
|
-
throw
|
|
525
|
+
e_10 = _a.sent();
|
|
526
|
+
log.error(tag, "e: ", e_10);
|
|
527
|
+
throw e_10;
|
|
421
528
|
case 5: return [2 /*return*/];
|
|
422
529
|
}
|
|
423
530
|
});
|
|
@@ -426,7 +533,7 @@ var get_txs_by_address = function (address) {
|
|
|
426
533
|
var get_balance = function (address) {
|
|
427
534
|
var _a;
|
|
428
535
|
return __awaiter(this, void 0, void 0, function () {
|
|
429
|
-
var tag, output, accountInfo, i, entry,
|
|
536
|
+
var tag, output, accountInfo, i, entry, e_11, e_12;
|
|
430
537
|
return __generator(this, function (_b) {
|
|
431
538
|
switch (_b.label) {
|
|
432
539
|
case 0:
|
|
@@ -454,13 +561,13 @@ var get_balance = function (address) {
|
|
|
454
561
|
output = output / BASE_THOR;
|
|
455
562
|
return [3 /*break*/, 5];
|
|
456
563
|
case 4:
|
|
457
|
-
|
|
564
|
+
e_11 = _b.sent();
|
|
458
565
|
return [3 /*break*/, 5];
|
|
459
566
|
case 5: return [2 /*return*/, output];
|
|
460
567
|
case 6:
|
|
461
|
-
|
|
462
|
-
log.error(tag, "e: ",
|
|
463
|
-
throw
|
|
568
|
+
e_12 = _b.sent();
|
|
569
|
+
log.error(tag, "e: ", e_12);
|
|
570
|
+
throw e_12;
|
|
464
571
|
case 7: return [2 /*return*/];
|
|
465
572
|
}
|
|
466
573
|
});
|
|
@@ -468,7 +575,7 @@ var get_balance = function (address) {
|
|
|
468
575
|
};
|
|
469
576
|
var get_node_info_verbose = function () {
|
|
470
577
|
return __awaiter(this, void 0, void 0, function () {
|
|
471
|
-
var tag, output, syncInfo, nodeInfo, lastBlock,
|
|
578
|
+
var tag, output, syncInfo, nodeInfo, lastBlock, e_13;
|
|
472
579
|
return __generator(this, function (_a) {
|
|
473
580
|
switch (_a.label) {
|
|
474
581
|
case 0:
|
|
@@ -495,9 +602,9 @@ var get_node_info_verbose = function () {
|
|
|
495
602
|
output.height = lastBlock.data.block.header.height;
|
|
496
603
|
return [2 /*return*/, output];
|
|
497
604
|
case 5:
|
|
498
|
-
|
|
499
|
-
log.error(tag, "e: ",
|
|
500
|
-
throw
|
|
605
|
+
e_13 = _a.sent();
|
|
606
|
+
log.error(tag, "e: ", e_13);
|
|
607
|
+
throw e_13;
|
|
501
608
|
case 6: return [2 /*return*/];
|
|
502
609
|
}
|
|
503
610
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/maya-network",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.5",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"ts-node": "^8.10.2",
|
|
28
28
|
"typescript": "^5.0.2"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "4c12b840606a82a8dabf03389e9c32c44d1efda6"
|
|
31
31
|
}
|