@pioneer-platform/maya-network 8.13.19 → 8.13.21
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/.turbo/turbo-build.log +5 -1
- package/CHANGELOG.md +20 -0
- package/LICENSE +674 -0
- package/build.sh +0 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +163 -50
- package/package.json +11 -11
- package/lib/index.js.map +0 -107
package/lib/index.js
CHANGED
|
@@ -91,11 +91,11 @@ var UNCHAINED_API = 'https://api.mayachain.shapeshift.com';
|
|
|
91
91
|
// Multiple direct node peers for fallback (in priority order)
|
|
92
92
|
// Using verified public endpoints from Maya Protocol
|
|
93
93
|
var MAYA_NODES = [
|
|
94
|
-
'https://maya.ninerealms.com',
|
|
95
94
|
'https://mayanode.mayachain.info',
|
|
96
95
|
'https://tendermint.mayachain.info'
|
|
97
96
|
// Note: Most public Maya nodes are experiencing issues
|
|
98
97
|
// If broadcast fails, it's likely due to network congestion (mempool full)
|
|
98
|
+
// Removed: https://maya.ninerealms.com (DNS resolution failing)
|
|
99
99
|
];
|
|
100
100
|
// Fallback to Midgard for pool data (not available in Unchained)
|
|
101
101
|
var MIDGARD_API = 'https://midgard.mayachain.info/v2';
|
|
@@ -147,6 +147,9 @@ module.exports = {
|
|
|
147
147
|
broadcast: function (tx) {
|
|
148
148
|
return broadcast_transaction(tx);
|
|
149
149
|
},
|
|
150
|
+
getBlockHeight: function () {
|
|
151
|
+
return get_block_height();
|
|
152
|
+
},
|
|
150
153
|
};
|
|
151
154
|
/**********************************
|
|
152
155
|
// Implementation
|
|
@@ -180,7 +183,7 @@ var get_info = function () {
|
|
|
180
183
|
};
|
|
181
184
|
var get_account_info = function (address) {
|
|
182
185
|
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
-
var tag, allEndpoints, results, successfulResults, mostRecentAccount, cacaoCoin, cacaoBalance;
|
|
186
|
+
var tag, allEndpoints, results, successfulResults, errors, mostRecentAccount, cacaoCoin, cacaoBalance;
|
|
184
187
|
var _this = this;
|
|
185
188
|
return __generator(this, function (_a) {
|
|
186
189
|
switch (_a.label) {
|
|
@@ -190,16 +193,19 @@ var get_account_info = function (address) {
|
|
|
190
193
|
{
|
|
191
194
|
name: 'Unchained',
|
|
192
195
|
fetch: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
193
|
-
var result, data;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
196
|
+
var result, data, e_2;
|
|
197
|
+
var _a;
|
|
198
|
+
return __generator(this, function (_b) {
|
|
199
|
+
switch (_b.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
_b.trys.push([0, 2, , 3]);
|
|
202
|
+
return [4 /*yield*/, axiosInstance({
|
|
203
|
+
method: 'GET',
|
|
204
|
+
url: "".concat(UNCHAINED_API, "/api/v1/account/").concat(address),
|
|
205
|
+
timeout: 5000
|
|
206
|
+
})];
|
|
201
207
|
case 1:
|
|
202
|
-
result =
|
|
208
|
+
result = _b.sent();
|
|
203
209
|
data = result.data;
|
|
204
210
|
return [2 /*return*/, {
|
|
205
211
|
account_number: String(data.accountNumber || '0'),
|
|
@@ -209,6 +215,22 @@ var get_account_info = function (address) {
|
|
|
209
215
|
public_key: null,
|
|
210
216
|
source: 'Unchained'
|
|
211
217
|
}];
|
|
218
|
+
case 2:
|
|
219
|
+
e_2 = _b.sent();
|
|
220
|
+
// 404 means account doesn't exist on chain yet (zero balance)
|
|
221
|
+
if (((_a = e_2.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
222
|
+
log.debug(tag, "Account not found on Unchained (404) - treating as zero balance");
|
|
223
|
+
return [2 /*return*/, {
|
|
224
|
+
account_number: '0',
|
|
225
|
+
sequence: 0,
|
|
226
|
+
address: address,
|
|
227
|
+
coins: [],
|
|
228
|
+
public_key: null,
|
|
229
|
+
source: 'Unchained'
|
|
230
|
+
}];
|
|
231
|
+
}
|
|
232
|
+
throw e_2;
|
|
233
|
+
case 3: return [2 /*return*/];
|
|
212
234
|
}
|
|
213
235
|
});
|
|
214
236
|
}); }
|
|
@@ -216,33 +238,39 @@ var get_account_info = function (address) {
|
|
|
216
238
|
], MAYA_NODES.map(function (nodeUrl) { return ({
|
|
217
239
|
name: nodeUrl,
|
|
218
240
|
fetch: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
219
|
-
var accountResult, accountData, coins, balanceResult,
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
241
|
+
var accountResult, accountData, coins, balanceResult, e_3, e_4;
|
|
242
|
+
var _a, _b;
|
|
243
|
+
return __generator(this, function (_c) {
|
|
244
|
+
switch (_c.label) {
|
|
245
|
+
case 0:
|
|
246
|
+
_c.trys.push([0, 6, , 7]);
|
|
247
|
+
return [4 /*yield*/, axiosInstance({
|
|
248
|
+
method: 'GET',
|
|
249
|
+
url: "".concat(nodeUrl, "/cosmos/auth/v1beta1/accounts/").concat(address),
|
|
250
|
+
timeout: 8000
|
|
251
|
+
})];
|
|
227
252
|
case 1:
|
|
228
|
-
accountResult =
|
|
253
|
+
accountResult = _c.sent();
|
|
229
254
|
accountData = accountResult.data.account || accountResult.data;
|
|
230
255
|
coins = [];
|
|
231
|
-
|
|
256
|
+
_c.label = 2;
|
|
232
257
|
case 2:
|
|
233
|
-
|
|
258
|
+
_c.trys.push([2, 4, , 5]);
|
|
234
259
|
return [4 /*yield*/, axiosInstance({
|
|
235
260
|
method: 'GET',
|
|
236
261
|
url: "".concat(nodeUrl, "/cosmos/bank/v1beta1/balances/").concat(address),
|
|
237
262
|
timeout: 8000
|
|
238
263
|
})];
|
|
239
264
|
case 3:
|
|
240
|
-
balanceResult =
|
|
265
|
+
balanceResult = _c.sent();
|
|
241
266
|
coins = balanceResult.data.balances || [];
|
|
242
267
|
return [3 /*break*/, 5];
|
|
243
268
|
case 4:
|
|
244
|
-
|
|
245
|
-
|
|
269
|
+
e_3 = _c.sent();
|
|
270
|
+
// 404 on balances is OK - means zero balance
|
|
271
|
+
if (((_a = e_3.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
|
|
272
|
+
log.warn(tag, "Failed to fetch balances from ".concat(nodeUrl, ": ").concat(e_3.message));
|
|
273
|
+
}
|
|
246
274
|
return [3 /*break*/, 5];
|
|
247
275
|
case 5: return [2 /*return*/, {
|
|
248
276
|
account_number: String(accountData.account_number || '0'),
|
|
@@ -252,6 +280,22 @@ var get_account_info = function (address) {
|
|
|
252
280
|
public_key: accountData.pub_key || null,
|
|
253
281
|
source: nodeUrl
|
|
254
282
|
}];
|
|
283
|
+
case 6:
|
|
284
|
+
e_4 = _c.sent();
|
|
285
|
+
// 404 means account doesn't exist on chain yet (zero balance)
|
|
286
|
+
if (((_b = e_4.response) === null || _b === void 0 ? void 0 : _b.status) === 404) {
|
|
287
|
+
log.debug(tag, "Account not found on ".concat(nodeUrl, " (404) - treating as zero balance"));
|
|
288
|
+
return [2 /*return*/, {
|
|
289
|
+
account_number: '0',
|
|
290
|
+
sequence: 0,
|
|
291
|
+
address: address,
|
|
292
|
+
coins: [],
|
|
293
|
+
public_key: null,
|
|
294
|
+
source: nodeUrl
|
|
295
|
+
}];
|
|
296
|
+
}
|
|
297
|
+
throw e_4;
|
|
298
|
+
case 7: return [2 /*return*/];
|
|
255
299
|
}
|
|
256
300
|
});
|
|
257
301
|
}); }
|
|
@@ -259,7 +303,7 @@ var get_account_info = function (address) {
|
|
|
259
303
|
return [4 /*yield*/, Promise.allSettled(allEndpoints.map(function (endpoint) {
|
|
260
304
|
return endpoint.fetch().then(function (data) { return (__assign(__assign({}, data), { endpoint: endpoint.name })); });
|
|
261
305
|
}))
|
|
262
|
-
// Extract successful responses
|
|
306
|
+
// Extract successful responses (including 404s which we handle as zero balance)
|
|
263
307
|
];
|
|
264
308
|
case 1:
|
|
265
309
|
results = _a.sent();
|
|
@@ -267,7 +311,11 @@ var get_account_info = function (address) {
|
|
|
267
311
|
.filter(function (result) { return result.status === 'fulfilled'; })
|
|
268
312
|
.map(function (result) { return result.value; });
|
|
269
313
|
if (successfulResults.length === 0) {
|
|
270
|
-
|
|
314
|
+
errors = results
|
|
315
|
+
.filter(function (result) { return result.status === 'rejected'; })
|
|
316
|
+
.map(function (result) { var _a; return ((_a = result.reason) === null || _a === void 0 ? void 0 : _a.message) || String(result.reason); });
|
|
317
|
+
log.error(tag, "All endpoints failed:", errors.join(', '));
|
|
318
|
+
// If all endpoints failed with actual errors (not 404s), throw
|
|
271
319
|
throw new Error("All endpoints failed for account info");
|
|
272
320
|
}
|
|
273
321
|
// Log all results for debugging
|
|
@@ -326,7 +374,7 @@ var get_account_info = function (address) {
|
|
|
326
374
|
};
|
|
327
375
|
var get_balance = function (address) {
|
|
328
376
|
return __awaiter(this, void 0, void 0, function () {
|
|
329
|
-
var tag, accountInfo, balance,
|
|
377
|
+
var tag, accountInfo, balance, e_5;
|
|
330
378
|
return __generator(this, function (_a) {
|
|
331
379
|
switch (_a.label) {
|
|
332
380
|
case 0:
|
|
@@ -343,9 +391,9 @@ var get_balance = function (address) {
|
|
|
343
391
|
// Convert from base units to CACAO
|
|
344
392
|
return [2 /*return*/, balance / BASE_MAYA];
|
|
345
393
|
case 3:
|
|
346
|
-
|
|
347
|
-
log.error(tag, "Error:",
|
|
348
|
-
throw
|
|
394
|
+
e_5 = _a.sent();
|
|
395
|
+
log.error(tag, "Error:", e_5.message);
|
|
396
|
+
throw e_5;
|
|
349
397
|
case 4: return [2 /*return*/];
|
|
350
398
|
}
|
|
351
399
|
});
|
|
@@ -353,7 +401,7 @@ var get_balance = function (address) {
|
|
|
353
401
|
};
|
|
354
402
|
var get_balances = function (address) {
|
|
355
403
|
return __awaiter(this, void 0, void 0, function () {
|
|
356
|
-
var tag, accountInfo, output, addedDenoms, _i, _a, asset, cacaoBalance,
|
|
404
|
+
var tag, accountInfo, output, addedDenoms, _i, _a, asset, cacaoBalance, e_6;
|
|
357
405
|
return __generator(this, function (_b) {
|
|
358
406
|
switch (_b.label) {
|
|
359
407
|
case 0:
|
|
@@ -414,9 +462,9 @@ var get_balances = function (address) {
|
|
|
414
462
|
}
|
|
415
463
|
return [2 /*return*/, output];
|
|
416
464
|
case 3:
|
|
417
|
-
|
|
418
|
-
log.error(tag, "Error:",
|
|
419
|
-
throw
|
|
465
|
+
e_6 = _b.sent();
|
|
466
|
+
log.error(tag, "Error:", e_6.message);
|
|
467
|
+
throw e_6;
|
|
420
468
|
case 4: return [2 /*return*/];
|
|
421
469
|
}
|
|
422
470
|
});
|
|
@@ -424,7 +472,7 @@ var get_balances = function (address) {
|
|
|
424
472
|
};
|
|
425
473
|
var get_txs_by_address = function (address_1, cursor_1) {
|
|
426
474
|
return __awaiter(this, arguments, void 0, function (address, cursor, pageSize) {
|
|
427
|
-
var tag, params, result,
|
|
475
|
+
var tag, params, result, e_7;
|
|
428
476
|
if (pageSize === void 0) { pageSize = 50; }
|
|
429
477
|
return __generator(this, function (_a) {
|
|
430
478
|
switch (_a.label) {
|
|
@@ -446,9 +494,9 @@ var get_txs_by_address = function (address_1, cursor_1) {
|
|
|
446
494
|
result = _a.sent();
|
|
447
495
|
return [2 /*return*/, result.data];
|
|
448
496
|
case 3:
|
|
449
|
-
|
|
450
|
-
log.error(tag, "Error:",
|
|
451
|
-
throw
|
|
497
|
+
e_7 = _a.sent();
|
|
498
|
+
log.error(tag, "Error:", e_7.message);
|
|
499
|
+
throw e_7;
|
|
452
500
|
case 4: return [2 /*return*/];
|
|
453
501
|
}
|
|
454
502
|
});
|
|
@@ -456,7 +504,7 @@ var get_txs_by_address = function (address_1, cursor_1) {
|
|
|
456
504
|
};
|
|
457
505
|
var get_transaction = function (txid) {
|
|
458
506
|
return __awaiter(this, void 0, void 0, function () {
|
|
459
|
-
var tag, _i, MAYA_NODES_1, nodeUrl, result,
|
|
507
|
+
var tag, _i, MAYA_NODES_1, nodeUrl, result, e_8, errorMsg;
|
|
460
508
|
return __generator(this, function (_a) {
|
|
461
509
|
switch (_a.label) {
|
|
462
510
|
case 0:
|
|
@@ -480,8 +528,8 @@ var get_transaction = function (txid) {
|
|
|
480
528
|
log.info(tag, "Successfully fetched tx from ".concat(nodeUrl));
|
|
481
529
|
return [2 /*return*/, result.data];
|
|
482
530
|
case 4:
|
|
483
|
-
|
|
484
|
-
log.warn(tag, "Failed to fetch tx from ".concat(nodeUrl, ": ").concat(
|
|
531
|
+
e_8 = _a.sent();
|
|
532
|
+
log.warn(tag, "Failed to fetch tx from ".concat(nodeUrl, ": ").concat(e_8.message));
|
|
485
533
|
return [3 /*break*/, 5];
|
|
486
534
|
case 5:
|
|
487
535
|
_i++;
|
|
@@ -631,7 +679,7 @@ var broadcast_transaction = function (tx) {
|
|
|
631
679
|
// Pool endpoints use Midgard (not available in Unchained)
|
|
632
680
|
var get_pool = function (poolId) {
|
|
633
681
|
return __awaiter(this, void 0, void 0, function () {
|
|
634
|
-
var tag, params, result,
|
|
682
|
+
var tag, params, result, e_9;
|
|
635
683
|
return __generator(this, function (_a) {
|
|
636
684
|
switch (_a.label) {
|
|
637
685
|
case 0:
|
|
@@ -653,9 +701,9 @@ var get_pool = function (poolId) {
|
|
|
653
701
|
result = _a.sent();
|
|
654
702
|
return [2 /*return*/, result.data];
|
|
655
703
|
case 3:
|
|
656
|
-
|
|
657
|
-
log.error(tag, "Error:",
|
|
658
|
-
throw
|
|
704
|
+
e_9 = _a.sent();
|
|
705
|
+
log.error(tag, "Error:", e_9.message);
|
|
706
|
+
throw e_9;
|
|
659
707
|
case 4: return [2 /*return*/];
|
|
660
708
|
}
|
|
661
709
|
});
|
|
@@ -663,7 +711,7 @@ var get_pool = function (poolId) {
|
|
|
663
711
|
};
|
|
664
712
|
var get_pools = function () {
|
|
665
713
|
return __awaiter(this, void 0, void 0, function () {
|
|
666
|
-
var tag, result,
|
|
714
|
+
var tag, result, e_10;
|
|
667
715
|
return __generator(this, function (_a) {
|
|
668
716
|
switch (_a.label) {
|
|
669
717
|
case 0:
|
|
@@ -680,9 +728,9 @@ var get_pools = function () {
|
|
|
680
728
|
result = _a.sent();
|
|
681
729
|
return [2 /*return*/, result.data];
|
|
682
730
|
case 3:
|
|
683
|
-
|
|
684
|
-
log.error(tag, "Error:",
|
|
685
|
-
throw
|
|
731
|
+
e_10 = _a.sent();
|
|
732
|
+
log.error(tag, "Error:", e_10.message);
|
|
733
|
+
throw e_10;
|
|
686
734
|
case 4: return [2 /*return*/];
|
|
687
735
|
}
|
|
688
736
|
});
|
|
@@ -706,3 +754,68 @@ var get_pool_addresses = function () {
|
|
|
706
754
|
});
|
|
707
755
|
});
|
|
708
756
|
};
|
|
757
|
+
var get_block_height = function () {
|
|
758
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
759
|
+
var tag, result, e_11, _i, MAYA_NODES_3, nodeUrl, result, height, e_12, errorMsg;
|
|
760
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
761
|
+
return __generator(this, function (_h) {
|
|
762
|
+
switch (_h.label) {
|
|
763
|
+
case 0:
|
|
764
|
+
tag = TAG + " | get_block_height | ";
|
|
765
|
+
_h.label = 1;
|
|
766
|
+
case 1:
|
|
767
|
+
_h.trys.push([1, 3, , 4]);
|
|
768
|
+
return [4 /*yield*/, axiosInstance({
|
|
769
|
+
method: 'GET',
|
|
770
|
+
url: "".concat(UNCHAINED_API, "/api/v1/info"),
|
|
771
|
+
timeout: 5000
|
|
772
|
+
})
|
|
773
|
+
// Unchained API returns block height in the info response
|
|
774
|
+
];
|
|
775
|
+
case 2:
|
|
776
|
+
result = _h.sent();
|
|
777
|
+
// Unchained API returns block height in the info response
|
|
778
|
+
if (result.data.blockHeight) {
|
|
779
|
+
return [2 /*return*/, parseInt(result.data.blockHeight)];
|
|
780
|
+
}
|
|
781
|
+
return [3 /*break*/, 4];
|
|
782
|
+
case 3:
|
|
783
|
+
e_11 = _h.sent();
|
|
784
|
+
log.warn(tag, "Unchained API failed, trying Maya nodes:", e_11.message);
|
|
785
|
+
return [3 /*break*/, 4];
|
|
786
|
+
case 4:
|
|
787
|
+
_i = 0, MAYA_NODES_3 = MAYA_NODES;
|
|
788
|
+
_h.label = 5;
|
|
789
|
+
case 5:
|
|
790
|
+
if (!(_i < MAYA_NODES_3.length)) return [3 /*break*/, 10];
|
|
791
|
+
nodeUrl = MAYA_NODES_3[_i];
|
|
792
|
+
_h.label = 6;
|
|
793
|
+
case 6:
|
|
794
|
+
_h.trys.push([6, 8, , 9]);
|
|
795
|
+
return [4 /*yield*/, axiosInstance({
|
|
796
|
+
method: 'GET',
|
|
797
|
+
url: "".concat(nodeUrl, "/blocks/latest"),
|
|
798
|
+
timeout: 8000
|
|
799
|
+
})];
|
|
800
|
+
case 7:
|
|
801
|
+
result = _h.sent();
|
|
802
|
+
height = ((_c = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.block) === null || _b === void 0 ? void 0 : _b.header) === null || _c === void 0 ? void 0 : _c.height) || ((_g = (_f = (_e = (_d = result.data) === null || _d === void 0 ? void 0 : _d.result) === null || _e === void 0 ? void 0 : _e.block) === null || _f === void 0 ? void 0 : _f.header) === null || _g === void 0 ? void 0 : _g.height);
|
|
803
|
+
if (height) {
|
|
804
|
+
return [2 /*return*/, parseInt(height)];
|
|
805
|
+
}
|
|
806
|
+
return [3 /*break*/, 9];
|
|
807
|
+
case 8:
|
|
808
|
+
e_12 = _h.sent();
|
|
809
|
+
log.warn(tag, "Failed to get block height from ".concat(nodeUrl, ":"), e_12.message);
|
|
810
|
+
return [3 /*break*/, 9];
|
|
811
|
+
case 9:
|
|
812
|
+
_i++;
|
|
813
|
+
return [3 /*break*/, 5];
|
|
814
|
+
case 10:
|
|
815
|
+
errorMsg = "Failed to get block height from all Maya endpoints";
|
|
816
|
+
log.error(tag, errorMsg);
|
|
817
|
+
throw new Error(errorMsg);
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
});
|
|
821
|
+
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/maya-network",
|
|
3
|
-
"version": "8.13.
|
|
3
|
+
"version": "8.13.21",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"create": "pnpm run build && pnpm run test",
|
|
8
|
-
"build": "tsc -p .",
|
|
9
|
-
"test": "pnpm run build && node __tests__/test-module.js",
|
|
10
|
-
"prepublish": "pnpm run build",
|
|
11
|
-
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
12
|
-
},
|
|
13
6
|
"dependencies": {
|
|
14
|
-
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
15
7
|
"axios-retry": "^3.3.1",
|
|
16
8
|
"bech32": "^1.1.4",
|
|
17
9
|
"bip32": "^2.0.5",
|
|
@@ -25,7 +17,15 @@
|
|
|
25
17
|
"prettyjson": "^1.2.5",
|
|
26
18
|
"secp256k1": "^3.8.0",
|
|
27
19
|
"ts-node": "^8.10.2",
|
|
28
|
-
"typescript": "^5.0.4"
|
|
20
|
+
"typescript": "^5.0.4",
|
|
21
|
+
"@pioneer-platform/loggerdog": "8.11.0"
|
|
29
22
|
},
|
|
30
|
-
"gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
|
|
23
|
+
"gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"create": "pnpm run build && pnpm run test",
|
|
26
|
+
"build": "tsc -p .",
|
|
27
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
28
|
+
"prepublish": "pnpm run build",
|
|
29
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
30
|
+
}
|
|
31
31
|
}
|