@pioneer-platform/maya-network 8.13.1 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 8.13.1
4
10
 
5
11
  ### Patch 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');
@@ -171,77 +180,102 @@ var get_info = function () {
171
180
  };
172
181
  var get_account_info = function (address) {
173
182
  return __awaiter(this, void 0, void 0, function () {
174
- var tag, result, unchainedData, unchainedError_1, _i, MAYA_NODES_1, nodeUrl, nodeResult, accountData, nodeError_1;
175
- return __generator(this, function (_a) {
176
- 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) {
177
188
  case 0:
178
189
  tag = TAG + " | get_account_info | ";
179
- _a.label = 1;
180
- case 1:
181
- _a.trys.push([1, 3, , 10]);
182
- return [4 /*yield*/, axiosInstance({
183
- method: 'GET',
184
- url: "".concat(UNCHAINED_API, "/api/v1/account/").concat(address),
185
- timeout: 5000
186
- })
187
- // Unchained returns flat structure, wrap it for backward compatibility
188
- ];
189
- case 2:
190
- result = _a.sent();
191
- unchainedData = result.data;
192
- return [2 /*return*/, __assign({ result: {
193
- value: {
194
- account_number: String(unchainedData.accountNumber || '0'),
195
- sequence: String(unchainedData.sequence || '0'),
196
- address: unchainedData.pubkey || address,
197
- coins: unchainedData.assets || [],
198
- 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
+ }];
199
239
  }
200
- } }, unchainedData)];
201
- case 3:
202
- unchainedError_1 = _a.sent();
203
- log.warn(tag, "Unchained API failed, trying node fallback:", unchainedError_1.message);
204
- _i = 0, MAYA_NODES_1 = MAYA_NODES;
205
- _a.label = 4;
206
- case 4:
207
- if (!(_i < MAYA_NODES_1.length)) return [3 /*break*/, 9];
208
- nodeUrl = MAYA_NODES_1[_i];
209
- _a.label = 5;
210
- case 5:
211
- _a.trys.push([5, 7, , 8]);
212
- log.debug(tag, "Trying node: ".concat(nodeUrl));
213
- return [4 /*yield*/, axiosInstance({
214
- method: 'GET',
215
- url: "".concat(nodeUrl, "/cosmos/auth/v1beta1/accounts/").concat(address),
216
- timeout: 10000
217
- })
218
- // 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
219
247
  ];
220
- case 6:
221
- nodeResult = _a.sent();
222
- accountData = nodeResult.data.account || nodeResult.data;
223
- log.info(tag, "Account info retrieved from ".concat(nodeUrl));
224
- // Convert Cosmos SDK format to our expected format
225
- 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: {
226
266
  value: {
227
- account_number: String(accountData.account_number || '0'),
228
- sequence: String(accountData.sequence || '0'),
229
- address: accountData.address || address,
230
- coins: accountData.coins || [],
231
- 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
232
272
  }
233
- } }, accountData)];
234
- case 7:
235
- nodeError_1 = _a.sent();
236
- log.debug(tag, "Node ".concat(nodeUrl, " failed:"), nodeError_1.message);
237
- return [3 /*break*/, 8];
238
- case 8:
239
- _i++;
240
- return [3 /*break*/, 4];
241
- case 9:
242
- log.error(tag, "All endpoints failed");
243
- throw new Error("All endpoints failed for account info");
244
- 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
+ }];
245
279
  }
246
280
  });
247
281
  });
@@ -385,7 +419,7 @@ var get_transaction = function (txid) {
385
419
  };
386
420
  var broadcast_transaction = function (tx) {
387
421
  return __awaiter(this, void 0, void 0, function () {
388
- var tag, output, payload, result, unchainedError_2, nodeErrors, _i, MAYA_NODES_2, nodeUrl, nodeResult, txResponse, nodeError, nodeError_2, errorTxResponse, nodeErrorMsg;
422
+ var tag, output, payload, result, unchainedError_1, nodeErrors, _i, MAYA_NODES_1, nodeUrl, nodeResult, txResponse, nodeError, nodeError_1, errorTxResponse, nodeErrorMsg;
389
423
  var _a, _b, _c, _d, _e, _f;
390
424
  return __generator(this, function (_g) {
391
425
  switch (_g.label) {
@@ -422,32 +456,32 @@ var broadcast_transaction = function (tx) {
422
456
  }
423
457
  return [3 /*break*/, 4];
424
458
  case 3:
425
- unchainedError_2 = _g.sent();
426
- log.warn(tag, "Unchained API failed:", unchainedError_2.message);
427
- if ((_a = unchainedError_2.response) === null || _a === void 0 ? void 0 : _a.data) {
428
- log.error(tag, "Unchained FULL response data:", JSON.stringify(unchainedError_2.response.data, null, 2));
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));
429
463
  // Check if error response contains a txhash - means broadcast succeeded despite error
430
- if (unchainedError_2.response.data.txid || unchainedError_2.response.data.txHash) {
431
- output.txid = unchainedError_2.response.data.txid || unchainedError_2.response.data.txHash;
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;
432
466
  output.success = true;
433
467
  output.endpoint = 'Unchained';
434
- log.warn(tag, "\u26A0\uFE0F Broadcast succeeded despite error: ".concat(unchainedError_2.response.data.message || unchainedError_2.message));
468
+ log.warn(tag, "\u26A0\uFE0F Broadcast succeeded despite error: ".concat(unchainedError_1.response.data.message || unchainedError_1.message));
435
469
  log.info(tag, "\u2705 Broadcast SUCCESS via Unchained - txid: ".concat(output.txid));
436
470
  return [2 /*return*/, output];
437
471
  }
438
- output.error = unchainedError_2.response.data.message || unchainedError_2.response.data.error || unchainedError_2.message;
472
+ output.error = unchainedError_1.response.data.message || unchainedError_1.response.data.error || unchainedError_1.message;
439
473
  }
440
474
  else {
441
- output.error = unchainedError_2.message;
475
+ output.error = unchainedError_1.message;
442
476
  }
443
477
  return [3 /*break*/, 4];
444
478
  case 4:
445
479
  nodeErrors = [];
446
- _i = 0, MAYA_NODES_2 = MAYA_NODES;
480
+ _i = 0, MAYA_NODES_1 = MAYA_NODES;
447
481
  _g.label = 5;
448
482
  case 5:
449
- if (!(_i < MAYA_NODES_2.length)) return [3 /*break*/, 10];
450
- nodeUrl = MAYA_NODES_2[_i];
483
+ if (!(_i < MAYA_NODES_1.length)) return [3 /*break*/, 10];
484
+ nodeUrl = MAYA_NODES_1[_i];
451
485
  _g.label = 6;
452
486
  case 6:
453
487
  _g.trys.push([6, 8, , 9]);
@@ -486,22 +520,22 @@ var broadcast_transaction = function (tx) {
486
520
  }
487
521
  return [3 /*break*/, 9];
488
522
  case 8:
489
- nodeError_2 = _g.sent();
523
+ nodeError_1 = _g.sent();
490
524
  // Log the full response for debugging
491
- if ((_b = nodeError_2.response) === null || _b === void 0 ? void 0 : _b.data) {
492
- log.error(tag, "Node ".concat(nodeUrl, " FULL response data:"), JSON.stringify(nodeError_2.response.data, null, 2));
493
- errorTxResponse = nodeError_2.response.data.tx_response || nodeError_2.response.data;
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;
494
528
  if (errorTxResponse.txhash || errorTxResponse.hash) {
495
529
  output.txid = errorTxResponse.txhash || errorTxResponse.hash;
496
530
  output.success = true;
497
531
  output.endpoint = nodeUrl;
498
532
  output.code = errorTxResponse.code;
499
- log.warn(tag, "\u26A0\uFE0F Broadcast succeeded despite error (code ".concat(errorTxResponse.code, "): ").concat(errorTxResponse.raw_log || nodeError_2.message));
533
+ log.warn(tag, "\u26A0\uFE0F Broadcast succeeded despite error (code ".concat(errorTxResponse.code, "): ").concat(errorTxResponse.raw_log || nodeError_1.message));
500
534
  log.info(tag, "\u2705 Broadcast SUCCESS via ".concat(nodeUrl, " - txid: ").concat(output.txid));
501
535
  return [2 /*return*/, output];
502
536
  }
503
537
  }
504
- nodeErrorMsg = ((_d = (_c = nodeError_2.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.raw_log) || ((_f = (_e = nodeError_2.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message) || nodeError_2.message;
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;
505
539
  nodeErrors.push("".concat(nodeUrl, ": ").concat(nodeErrorMsg));
506
540
  log.warn(tag, "Node ".concat(nodeUrl, " failed:"), nodeErrorMsg);
507
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.1",
3
+ "version": "8.13.2",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {