@pioneer-platform/maya-network 8.13.0 → 8.13.2

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.
@@ -1 +1,2 @@
1
- $ tsc -p .
1
+
2
+ $ tsc -p .
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pioneer-platform/maya-network
2
2
 
3
+ ## 8.13.2
4
+
5
+ ### Patch Changes
6
+
7
+ - fix(mayachain): implement consensus-based account sequence from all nodes
8
+
9
+ ## 8.13.1
10
+
11
+ ### Patch Changes
12
+
13
+ - publish
14
+
3
15
  ## 8.13.0
4
16
 
5
17
  ### Minor Changes
package/lib/index.d.ts CHANGED
@@ -13,7 +13,21 @@ declare const BASE_MAYA = 10000000000;
13
13
  // Implementation
14
14
  //**********************************/
15
15
  declare const get_info: () => Promise<any>;
16
- declare const get_account_info: (address: string) => Promise<any>;
16
+ declare const get_account_info: (address: string) => Promise<{
17
+ result: {
18
+ value: {
19
+ account_number: any;
20
+ sequence: string;
21
+ address: any;
22
+ coins: any;
23
+ public_key: any;
24
+ };
25
+ };
26
+ accountNumber: any;
27
+ sequence: string;
28
+ balance: any;
29
+ assets: any;
30
+ }>;
17
31
  declare const get_balance: (address: string) => Promise<number>;
18
32
  declare const get_balances: (address: string) => Promise<any[]>;
19
33
  declare const get_txs_by_address: (address: string, cursor?: string, pageSize?: number) => Promise<any>;
package/lib/index.js CHANGED
@@ -52,6 +52,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
52
52
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
53
53
  }
54
54
  };
55
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
56
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
57
+ if (ar || !(i in from)) {
58
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
59
+ ar[i] = from[i];
60
+ }
61
+ }
62
+ return to.concat(ar || Array.prototype.slice.call(from));
63
+ };
55
64
  var TAG = " | mayachain-api | ";
56
65
  var log = require('@pioneer-platform/loggerdog')();
57
66
  var axiosLib = require('axios');
@@ -82,6 +91,7 @@ var UNCHAINED_API = 'https://api.mayachain.shapeshift.com';
82
91
  // Multiple direct node peers for fallback (in priority order)
83
92
  // Using verified public endpoints from Maya Protocol
84
93
  var MAYA_NODES = [
94
+ 'https://maya.ninerealms.com',
85
95
  'https://mayanode.mayachain.info',
86
96
  'https://tendermint.mayachain.info'
87
97
  // Note: Most public Maya nodes are experiencing issues
@@ -170,77 +180,102 @@ var get_info = function () {
170
180
  };
171
181
  var get_account_info = function (address) {
172
182
  return __awaiter(this, void 0, void 0, function () {
173
- var tag, result, unchainedData, unchainedError_1, _i, MAYA_NODES_1, nodeUrl, nodeResult, accountData, nodeError_1;
174
- return __generator(this, function (_a) {
175
- switch (_a.label) {
183
+ var tag, allEndpoints, results, successfulResults, mostRecentAccount;
184
+ var _this = this;
185
+ var _a, _b;
186
+ return __generator(this, function (_c) {
187
+ switch (_c.label) {
176
188
  case 0:
177
189
  tag = TAG + " | get_account_info | ";
178
- _a.label = 1;
179
- case 1:
180
- _a.trys.push([1, 3, , 10]);
181
- return [4 /*yield*/, axiosInstance({
182
- method: 'GET',
183
- url: "".concat(UNCHAINED_API, "/api/v1/account/").concat(address),
184
- timeout: 5000
185
- })
186
- // Unchained returns flat structure, wrap it for backward compatibility
187
- ];
188
- case 2:
189
- result = _a.sent();
190
- unchainedData = result.data;
191
- return [2 /*return*/, __assign({ result: {
192
- value: {
193
- account_number: String(unchainedData.accountNumber || '0'),
194
- sequence: String(unchainedData.sequence || '0'),
195
- address: unchainedData.pubkey || address,
196
- coins: unchainedData.assets || [],
197
- public_key: null // Not provided by Unchained
190
+ allEndpoints = __spreadArray([
191
+ {
192
+ name: 'Unchained',
193
+ fetch: function () { return __awaiter(_this, void 0, void 0, function () {
194
+ var result, data;
195
+ return __generator(this, function (_a) {
196
+ switch (_a.label) {
197
+ case 0: return [4 /*yield*/, axiosInstance({
198
+ method: 'GET',
199
+ url: "".concat(UNCHAINED_API, "/api/v1/account/").concat(address),
200
+ timeout: 5000
201
+ })];
202
+ case 1:
203
+ result = _a.sent();
204
+ data = result.data;
205
+ return [2 /*return*/, {
206
+ account_number: String(data.accountNumber || '0'),
207
+ sequence: parseInt(data.sequence || '0'),
208
+ address: data.pubkey || address,
209
+ coins: data.assets || [],
210
+ public_key: null,
211
+ source: 'Unchained'
212
+ }];
213
+ }
214
+ });
215
+ }); }
216
+ }
217
+ ], MAYA_NODES.map(function (nodeUrl) { return ({
218
+ name: nodeUrl,
219
+ fetch: function () { return __awaiter(_this, void 0, void 0, function () {
220
+ var result, accountData;
221
+ return __generator(this, function (_a) {
222
+ switch (_a.label) {
223
+ case 0: return [4 /*yield*/, axiosInstance({
224
+ method: 'GET',
225
+ url: "".concat(nodeUrl, "/cosmos/auth/v1beta1/accounts/").concat(address),
226
+ timeout: 8000
227
+ })];
228
+ case 1:
229
+ result = _a.sent();
230
+ accountData = result.data.account || result.data;
231
+ return [2 /*return*/, {
232
+ account_number: String(accountData.account_number || '0'),
233
+ sequence: parseInt(accountData.sequence || '0'),
234
+ address: accountData.address || address,
235
+ coins: accountData.coins || [],
236
+ public_key: accountData.pub_key || null,
237
+ source: nodeUrl
238
+ }];
198
239
  }
199
- } }, unchainedData)];
200
- case 3:
201
- unchainedError_1 = _a.sent();
202
- log.warn(tag, "Unchained API failed, trying node fallback:", unchainedError_1.message);
203
- _i = 0, MAYA_NODES_1 = MAYA_NODES;
204
- _a.label = 4;
205
- case 4:
206
- if (!(_i < MAYA_NODES_1.length)) return [3 /*break*/, 9];
207
- nodeUrl = MAYA_NODES_1[_i];
208
- _a.label = 5;
209
- case 5:
210
- _a.trys.push([5, 7, , 8]);
211
- log.debug(tag, "Trying node: ".concat(nodeUrl));
212
- return [4 /*yield*/, axiosInstance({
213
- method: 'GET',
214
- url: "".concat(nodeUrl, "/cosmos/auth/v1beta1/accounts/").concat(address),
215
- timeout: 10000
216
- })
217
- // Cosmos SDK returns { account: {...} } - wrap for compatibility
240
+ });
241
+ }); }
242
+ }); }), true);
243
+ return [4 /*yield*/, Promise.allSettled(allEndpoints.map(function (endpoint) {
244
+ return endpoint.fetch().then(function (data) { return (__assign(__assign({}, data), { endpoint: endpoint.name })); });
245
+ }))
246
+ // Extract successful responses
218
247
  ];
219
- case 6:
220
- nodeResult = _a.sent();
221
- accountData = nodeResult.data.account || nodeResult.data;
222
- log.info(tag, "Account info retrieved from ".concat(nodeUrl));
223
- // Convert Cosmos SDK format to our expected format
224
- return [2 /*return*/, __assign({ result: {
248
+ case 1:
249
+ results = _c.sent();
250
+ successfulResults = results
251
+ .filter(function (result) { return result.status === 'fulfilled'; })
252
+ .map(function (result) { return result.value; });
253
+ if (successfulResults.length === 0) {
254
+ log.error(tag, "All endpoints failed");
255
+ throw new Error("All endpoints failed for account info");
256
+ }
257
+ // Log all sequence numbers for debugging
258
+ log.info(tag, "Sequence numbers from all nodes:", successfulResults.map(function (r) { return "".concat(r.source, ": ").concat(r.sequence); }).join(', '));
259
+ mostRecentAccount = successfulResults.reduce(function (max, current) {
260
+ return current.sequence > max.sequence ? current : max;
261
+ });
262
+ log.info(tag, "Using account info from ".concat(mostRecentAccount.source, " with sequence ").concat(mostRecentAccount.sequence));
263
+ // Return in expected format
264
+ return [2 /*return*/, {
265
+ result: {
225
266
  value: {
226
- account_number: String(accountData.account_number || '0'),
227
- sequence: String(accountData.sequence || '0'),
228
- address: accountData.address || address,
229
- coins: accountData.coins || [],
230
- public_key: accountData.pub_key || null
267
+ account_number: mostRecentAccount.account_number,
268
+ sequence: String(mostRecentAccount.sequence),
269
+ address: mostRecentAccount.address,
270
+ coins: mostRecentAccount.coins,
271
+ public_key: mostRecentAccount.public_key
231
272
  }
232
- } }, accountData)];
233
- case 7:
234
- nodeError_1 = _a.sent();
235
- log.debug(tag, "Node ".concat(nodeUrl, " failed:"), nodeError_1.message);
236
- return [3 /*break*/, 8];
237
- case 8:
238
- _i++;
239
- return [3 /*break*/, 4];
240
- case 9:
241
- log.error(tag, "All endpoints failed");
242
- throw new Error("All endpoints failed for account info");
243
- case 10: return [2 /*return*/];
273
+ },
274
+ accountNumber: mostRecentAccount.account_number,
275
+ sequence: String(mostRecentAccount.sequence),
276
+ balance: ((_b = (_a = mostRecentAccount.coins) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.amount) || '0',
277
+ assets: mostRecentAccount.coins || []
278
+ }];
244
279
  }
245
280
  });
246
281
  });
@@ -384,16 +419,16 @@ var get_transaction = function (txid) {
384
419
  };
385
420
  var broadcast_transaction = function (tx) {
386
421
  return __awaiter(this, void 0, void 0, function () {
387
- var tag, output, payload, result, unchainedError_2, nodeErrors, _i, MAYA_NODES_2, nodeUrl, nodeResult, txResponse, nodeError, nodeError, nodeError_2, nodeErrorMsg;
388
- var _a, _b, _c, _d, _e;
389
- return __generator(this, function (_f) {
390
- switch (_f.label) {
422
+ var tag, output, payload, result, unchainedError_1, nodeErrors, _i, MAYA_NODES_1, nodeUrl, nodeResult, txResponse, nodeError, nodeError_1, errorTxResponse, nodeErrorMsg;
423
+ var _a, _b, _c, _d, _e, _f;
424
+ return __generator(this, function (_g) {
425
+ switch (_g.label) {
391
426
  case 0:
392
427
  tag = TAG + " | broadcast_transaction | ";
393
428
  output = { success: false };
394
- _f.label = 1;
429
+ _g.label = 1;
395
430
  case 1:
396
- _f.trys.push([1, 3, , 4]);
431
+ _g.trys.push([1, 3, , 4]);
397
432
  payload = {
398
433
  rawTx: tx
399
434
  };
@@ -405,7 +440,7 @@ var broadcast_transaction = function (tx) {
405
440
  timeout: 10000
406
441
  })];
407
442
  case 2:
408
- result = _f.sent();
443
+ result = _g.sent();
409
444
  log.info(tag, 'Unchained response:', result.data);
410
445
  // Unchained returns { txid: "hash" } on success
411
446
  if (result.data.txid || result.data.txHash) {
@@ -421,23 +456,35 @@ var broadcast_transaction = function (tx) {
421
456
  }
422
457
  return [3 /*break*/, 4];
423
458
  case 3:
424
- unchainedError_2 = _f.sent();
425
- log.warn(tag, "Unchained API failed:", unchainedError_2.message);
426
- if ((_a = unchainedError_2.response) === null || _a === void 0 ? void 0 : _a.data) {
427
- output.error = unchainedError_2.response.data.message || unchainedError_2.response.data.error || unchainedError_2.message;
428
- log.debug(tag, "Unchained error details:", unchainedError_2.response.data);
459
+ unchainedError_1 = _g.sent();
460
+ log.warn(tag, "Unchained API failed:", unchainedError_1.message);
461
+ if ((_a = unchainedError_1.response) === null || _a === void 0 ? void 0 : _a.data) {
462
+ log.error(tag, "Unchained FULL response data:", JSON.stringify(unchainedError_1.response.data, null, 2));
463
+ // Check if error response contains a txhash - means broadcast succeeded despite error
464
+ if (unchainedError_1.response.data.txid || unchainedError_1.response.data.txHash) {
465
+ output.txid = unchainedError_1.response.data.txid || unchainedError_1.response.data.txHash;
466
+ output.success = true;
467
+ output.endpoint = 'Unchained';
468
+ log.warn(tag, "\u26A0\uFE0F Broadcast succeeded despite error: ".concat(unchainedError_1.response.data.message || unchainedError_1.message));
469
+ log.info(tag, "\u2705 Broadcast SUCCESS via Unchained - txid: ".concat(output.txid));
470
+ return [2 /*return*/, output];
471
+ }
472
+ output.error = unchainedError_1.response.data.message || unchainedError_1.response.data.error || unchainedError_1.message;
473
+ }
474
+ else {
475
+ output.error = unchainedError_1.message;
429
476
  }
430
477
  return [3 /*break*/, 4];
431
478
  case 4:
432
479
  nodeErrors = [];
433
- _i = 0, MAYA_NODES_2 = MAYA_NODES;
434
- _f.label = 5;
480
+ _i = 0, MAYA_NODES_1 = MAYA_NODES;
481
+ _g.label = 5;
435
482
  case 5:
436
- if (!(_i < MAYA_NODES_2.length)) return [3 /*break*/, 10];
437
- nodeUrl = MAYA_NODES_2[_i];
438
- _f.label = 6;
483
+ if (!(_i < MAYA_NODES_1.length)) return [3 /*break*/, 10];
484
+ nodeUrl = MAYA_NODES_1[_i];
485
+ _g.label = 6;
439
486
  case 6:
440
- _f.trys.push([6, 8, , 9]);
487
+ _g.trys.push([6, 8, , 9]);
441
488
  log.info(tag, "Trying direct Maya node: ".concat(nodeUrl));
442
489
  return [4 /*yield*/, axiosInstance({
443
490
  url: "".concat(nodeUrl, "/cosmos/tx/v1beta1/txs"),
@@ -449,22 +496,23 @@ var broadcast_transaction = function (tx) {
449
496
  timeout: 15000 // Increased timeout for direct nodes
450
497
  })];
451
498
  case 7:
452
- nodeResult = _f.sent();
499
+ nodeResult = _g.sent();
453
500
  log.info(tag, 'Node response:', nodeResult.data);
454
501
  txResponse = nodeResult.data.tx_response || nodeResult.data;
455
- // Code 0 means success, any other code is an error
456
- if (txResponse.code === 0 && (txResponse.txhash || txResponse.hash)) {
502
+ // If we got a txhash, the transaction was successfully broadcast
503
+ // The error code just indicates validation status, but the tx is in the network
504
+ if (txResponse.txhash || txResponse.hash) {
457
505
  output.txid = txResponse.txhash || txResponse.hash;
458
506
  output.success = true;
459
507
  output.endpoint = nodeUrl;
508
+ output.code = txResponse.code;
509
+ // Log warning if code !== 0 but still mark as success
510
+ if (txResponse.code !== 0) {
511
+ log.warn(tag, "\u26A0\uFE0F Transaction broadcast with non-zero code ".concat(txResponse.code, ": ").concat(txResponse.raw_log || txResponse.message || 'Unknown validation issue'));
512
+ }
460
513
  log.info(tag, "\u2705 Broadcast SUCCESS via ".concat(nodeUrl, " - txid: ").concat(output.txid));
461
514
  return [2 /*return*/, output];
462
515
  }
463
- else if (txResponse.txhash || txResponse.hash) {
464
- nodeError = "Transaction rejected (code ".concat(txResponse.code, "): ").concat(txResponse.raw_log || txResponse.message || 'Unknown error');
465
- nodeErrors.push("".concat(nodeUrl, ": ").concat(nodeError));
466
- log.warn(tag, "Node ".concat(nodeUrl, " rejected transaction:"), nodeError);
467
- }
468
516
  else if (txResponse.raw_log || txResponse.message || nodeResult.data.message) {
469
517
  nodeError = txResponse.raw_log || txResponse.message || nodeResult.data.message;
470
518
  nodeErrors.push("".concat(nodeUrl, ": ").concat(nodeError));
@@ -472,8 +520,22 @@ var broadcast_transaction = function (tx) {
472
520
  }
473
521
  return [3 /*break*/, 9];
474
522
  case 8:
475
- nodeError_2 = _f.sent();
476
- nodeErrorMsg = ((_c = (_b = nodeError_2.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.raw_log) || ((_e = (_d = nodeError_2.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.message) || nodeError_2.message;
523
+ nodeError_1 = _g.sent();
524
+ // Log the full response for debugging
525
+ if ((_b = nodeError_1.response) === null || _b === void 0 ? void 0 : _b.data) {
526
+ log.error(tag, "Node ".concat(nodeUrl, " FULL response data:"), JSON.stringify(nodeError_1.response.data, null, 2));
527
+ errorTxResponse = nodeError_1.response.data.tx_response || nodeError_1.response.data;
528
+ if (errorTxResponse.txhash || errorTxResponse.hash) {
529
+ output.txid = errorTxResponse.txhash || errorTxResponse.hash;
530
+ output.success = true;
531
+ output.endpoint = nodeUrl;
532
+ output.code = errorTxResponse.code;
533
+ log.warn(tag, "\u26A0\uFE0F Broadcast succeeded despite error (code ".concat(errorTxResponse.code, "): ").concat(errorTxResponse.raw_log || nodeError_1.message));
534
+ log.info(tag, "\u2705 Broadcast SUCCESS via ".concat(nodeUrl, " - txid: ").concat(output.txid));
535
+ return [2 /*return*/, output];
536
+ }
537
+ }
538
+ nodeErrorMsg = ((_d = (_c = nodeError_1.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.raw_log) || ((_f = (_e = nodeError_1.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message) || nodeError_1.message;
477
539
  nodeErrors.push("".concat(nodeUrl, ": ").concat(nodeErrorMsg));
478
540
  log.warn(tag, "Node ".concat(nodeUrl, " failed:"), nodeErrorMsg);
479
541
  return [3 /*break*/, 9];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/maya-network",
3
- "version": "8.13.0",
3
+ "version": "8.13.2",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {