@pioneer-platform/maya-network 8.12.2 → 8.12.3

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,17 @@
1
1
  # @pioneer-platform/maya-network
2
2
 
3
+ ## 8.12.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Add multi-peer fallback for broadcast and account info
8
+
9
+ - Try 3 different Maya node peers if Unchained API fails
10
+ - Increased timeout from 10s to 15s for direct node broadcasts
11
+ - Comprehensive error messages showing all attempted endpoints
12
+ - Nodes: mayanode, tendermint, rpc (in priority order)
13
+ - Eliminates single point of failure for critical operations
14
+
3
15
  ## 8.12.2
4
16
 
5
17
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -6,7 +6,7 @@ declare const https: any;
6
6
  declare const axiosInstance: any;
7
7
  declare const axiosRetry: any;
8
8
  declare const UNCHAINED_API = "https://api.mayachain.shapeshift.com";
9
- declare const MAYA_NODE = "https://mayanode.mayachain.info";
9
+ declare const MAYA_NODES: string[];
10
10
  declare const MIDGARD_API = "https://midgard.mayachain.info/v2";
11
11
  declare const BASE_MAYA = 10000000000;
12
12
  /**********************************
package/lib/index.js CHANGED
@@ -79,8 +79,12 @@ axiosRetry(axiosInstance, {
79
79
  });
80
80
  // Unchained API endpoint (primary)
81
81
  var UNCHAINED_API = 'https://api.mayachain.shapeshift.com';
82
- // Direct node fallback
83
- var MAYA_NODE = 'https://mayanode.mayachain.info';
82
+ // Multiple direct node peers for fallback (in priority order)
83
+ var MAYA_NODES = [
84
+ 'https://mayanode.mayachain.info',
85
+ 'https://tendermint.mayachain.info',
86
+ 'https://rpc.mayachain.info'
87
+ ];
84
88
  // Fallback to Midgard for pool data (not available in Unchained)
85
89
  var MIDGARD_API = 'https://midgard.mayachain.info/v2';
86
90
  // Base unit conversion (10 decimal places for CACAO)
@@ -164,14 +168,14 @@ var get_info = function () {
164
168
  };
165
169
  var get_account_info = function (address) {
166
170
  return __awaiter(this, void 0, void 0, function () {
167
- var tag, result, unchainedData, unchainedError_1, nodeResult, nodeError_1;
171
+ var tag, result, unchainedData, unchainedError_1, _i, MAYA_NODES_1, nodeUrl, nodeResult, nodeError_1;
168
172
  return __generator(this, function (_a) {
169
173
  switch (_a.label) {
170
174
  case 0:
171
175
  tag = TAG + " | get_account_info | ";
172
176
  _a.label = 1;
173
177
  case 1:
174
- _a.trys.push([1, 3, , 8]);
178
+ _a.trys.push([1, 3, , 10]);
175
179
  return [4 /*yield*/, axiosInstance({
176
180
  method: 'GET',
177
181
  url: "".concat(UNCHAINED_API, "/api/v1/account/").concat(address),
@@ -194,26 +198,38 @@ var get_account_info = function (address) {
194
198
  case 3:
195
199
  unchainedError_1 = _a.sent();
196
200
  log.warn(tag, "Unchained API failed, trying node fallback:", unchainedError_1.message);
201
+ _i = 0, MAYA_NODES_1 = MAYA_NODES;
197
202
  _a.label = 4;
198
203
  case 4:
199
- _a.trys.push([4, 6, , 7]);
204
+ if (!(_i < MAYA_NODES_1.length)) return [3 /*break*/, 9];
205
+ nodeUrl = MAYA_NODES_1[_i];
206
+ _a.label = 5;
207
+ case 5:
208
+ _a.trys.push([5, 7, , 8]);
209
+ log.debug(tag, "Trying node: ".concat(nodeUrl));
200
210
  return [4 /*yield*/, axiosInstance({
201
211
  method: 'GET',
202
- url: "".concat(MAYA_NODE, "/auth/accounts/").concat(address),
203
- timeout: 5000
212
+ url: "".concat(nodeUrl, "/auth/accounts/").concat(address),
213
+ timeout: 10000
204
214
  })
205
215
  // Node returns nested format already
206
216
  ];
207
- case 5:
217
+ case 6:
208
218
  nodeResult = _a.sent();
209
219
  // Node returns nested format already
220
+ log.info(tag, "Account info retrieved from ".concat(nodeUrl));
210
221
  return [2 /*return*/, nodeResult.data];
211
- case 6:
222
+ case 7:
212
223
  nodeError_1 = _a.sent();
213
- log.error(tag, "Both endpoints failed:", nodeError_1.message);
214
- throw nodeError_1;
215
- case 7: return [3 /*break*/, 8];
216
- case 8: return [2 /*return*/];
224
+ log.debug(tag, "Node ".concat(nodeUrl, " failed:"), nodeError_1.message);
225
+ return [3 /*break*/, 8];
226
+ case 8:
227
+ _i++;
228
+ return [3 /*break*/, 4];
229
+ case 9:
230
+ log.error(tag, "All endpoints failed");
231
+ throw new Error("All endpoints failed for account info");
232
+ case 10: return [2 /*return*/];
217
233
  }
218
234
  });
219
235
  });
@@ -357,7 +373,7 @@ var get_transaction = function (txid) {
357
373
  };
358
374
  var broadcast_transaction = function (tx) {
359
375
  return __awaiter(this, void 0, void 0, function () {
360
- var tag, output, payload, result, unchainedError_2, nodeResult, nodeError, nodeError_2, nodeErrorMsg;
376
+ var tag, output, payload, result, unchainedError_2, nodeErrors, _i, MAYA_NODES_2, nodeUrl, nodeResult, nodeError, nodeError_2, nodeErrorMsg;
361
377
  var _a, _b, _c, _d, _e;
362
378
  return __generator(this, function (_f) {
363
379
  switch (_f.label) {
@@ -402,41 +418,56 @@ var broadcast_transaction = function (tx) {
402
418
  }
403
419
  return [3 /*break*/, 4];
404
420
  case 4:
405
- _f.trys.push([4, 6, , 7]);
406
- log.info(tag, "Trying direct Maya node fallback");
421
+ nodeErrors = [];
422
+ _i = 0, MAYA_NODES_2 = MAYA_NODES;
423
+ _f.label = 5;
424
+ case 5:
425
+ if (!(_i < MAYA_NODES_2.length)) return [3 /*break*/, 10];
426
+ nodeUrl = MAYA_NODES_2[_i];
427
+ _f.label = 6;
428
+ case 6:
429
+ _f.trys.push([6, 8, , 9]);
430
+ log.info(tag, "Trying direct Maya node: ".concat(nodeUrl));
407
431
  return [4 /*yield*/, axiosInstance({
408
- url: "".concat(MAYA_NODE, "/txs"),
432
+ url: "".concat(nodeUrl, "/txs"),
409
433
  method: 'POST',
410
434
  data: {
411
435
  tx: tx,
412
436
  mode: 'sync'
413
437
  },
414
- timeout: 10000
438
+ timeout: 15000 // Increased timeout for direct nodes
415
439
  })];
416
- case 5:
440
+ case 7:
417
441
  nodeResult = _f.sent();
418
442
  log.info(tag, 'Node response:', nodeResult.data);
419
443
  // Node returns { txhash: "hash" } on success
420
444
  if (nodeResult.data.txhash || nodeResult.data.hash) {
421
445
  output.txid = nodeResult.data.txhash || nodeResult.data.hash;
422
446
  output.success = true;
423
- output.endpoint = 'MayaNode';
424
- log.info(tag, "\u2705 Broadcast SUCCESS via MayaNode - txid: ".concat(output.txid));
447
+ output.endpoint = nodeUrl;
448
+ log.info(tag, "\u2705 Broadcast SUCCESS via ".concat(nodeUrl, " - txid: ").concat(output.txid));
425
449
  return [2 /*return*/, output];
426
450
  }
427
451
  else if (nodeResult.data.raw_log || nodeResult.data.message) {
428
452
  nodeError = nodeResult.data.raw_log || nodeResult.data.message;
429
- output.error = "Both endpoints failed. Unchained: ".concat(output.error, ". Node: ").concat(nodeError);
430
- log.error(tag, " Both endpoints FAILED");
453
+ nodeErrors.push("".concat(nodeUrl, ": ").concat(nodeError));
454
+ log.warn(tag, "Node ".concat(nodeUrl, " returned error:"), nodeError);
431
455
  }
432
- return [3 /*break*/, 7];
433
- case 6:
456
+ return [3 /*break*/, 9];
457
+ case 8:
434
458
  nodeError_2 = _f.sent();
435
- log.error(tag, "Node broadcast also failed:", nodeError_2.message);
436
459
  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;
437
- output.error = "Both endpoints failed. Unchained: ".concat(output.error, ". Node: ").concat(nodeErrorMsg);
438
- return [3 /*break*/, 7];
439
- case 7: return [2 /*return*/, output];
460
+ nodeErrors.push("".concat(nodeUrl, ": ").concat(nodeErrorMsg));
461
+ log.warn(tag, "Node ".concat(nodeUrl, " failed:"), nodeErrorMsg);
462
+ return [3 /*break*/, 9];
463
+ case 9:
464
+ _i++;
465
+ return [3 /*break*/, 5];
466
+ case 10:
467
+ // All endpoints failed
468
+ output.error = "All endpoints failed. Unchained: ".concat(output.error, ". Nodes: ").concat(nodeErrors.join(' | '));
469
+ log.error(tag, "❌ All endpoints FAILED");
470
+ return [2 /*return*/, output];
440
471
  }
441
472
  });
442
473
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/maya-network",
3
- "version": "8.12.2",
3
+ "version": "8.12.3",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {