@pioneer-platform/maya-network 8.12.1 → 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,29 @@
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
+
15
+ ## 8.12.2
16
+
17
+ ### Patch Changes
18
+
19
+ - Add dual-endpoint fallback for MayaChain broadcast and account info
20
+
21
+ - Broadcast now tries Unchained API first, falls back to direct Maya node
22
+ - Account info has same fallback logic for reliability
23
+ - Better error messages showing both endpoint results
24
+ - Eliminates single point of failure
25
+ - Logs which endpoint succeeded for debugging
26
+
3
27
  ## 8.12.1
4
28
 
5
29
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -6,6 +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_NODES: string[];
9
10
  declare const MIDGARD_API = "https://midgard.mayachain.info/v2";
10
11
  declare const BASE_MAYA = 10000000000;
11
12
  /**********************************
package/lib/index.js CHANGED
@@ -77,8 +77,14 @@ axiosRetry(axiosInstance, {
77
77
  log.debug(TAG, "Retry ".concat(retryCount, "/2: ").concat(error.message));
78
78
  }
79
79
  });
80
- // Unchained API endpoint
80
+ // Unchained API endpoint (primary)
81
81
  var UNCHAINED_API = 'https://api.mayachain.shapeshift.com';
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
+ ];
82
88
  // Fallback to Midgard for pool data (not available in Unchained)
83
89
  var MIDGARD_API = 'https://midgard.mayachain.info/v2';
84
90
  // Base unit conversion (10 decimal places for CACAO)
@@ -162,22 +168,20 @@ var get_info = function () {
162
168
  };
163
169
  var get_account_info = function (address) {
164
170
  return __awaiter(this, void 0, void 0, function () {
165
- var tag, result, unchainedData, e_2;
171
+ var tag, result, unchainedData, unchainedError_1, _i, MAYA_NODES_1, nodeUrl, nodeResult, nodeError_1;
166
172
  return __generator(this, function (_a) {
167
173
  switch (_a.label) {
168
174
  case 0:
169
175
  tag = TAG + " | get_account_info | ";
170
176
  _a.label = 1;
171
177
  case 1:
172
- _a.trys.push([1, 3, , 4]);
178
+ _a.trys.push([1, 3, , 10]);
173
179
  return [4 /*yield*/, axiosInstance({
174
180
  method: 'GET',
175
181
  url: "".concat(UNCHAINED_API, "/api/v1/account/").concat(address),
176
182
  timeout: 5000
177
183
  })
178
184
  // Unchained returns flat structure, wrap it for backward compatibility
179
- // Old format: { result: { value: { account_number, sequence, ... } } }
180
- // New format: { accountNumber, sequence, balance, ... }
181
185
  ];
182
186
  case 2:
183
187
  result = _a.sent();
@@ -192,17 +196,47 @@ var get_account_info = function (address) {
192
196
  }
193
197
  } }, unchainedData)];
194
198
  case 3:
195
- e_2 = _a.sent();
196
- log.error(tag, "Error:", e_2.message);
197
- throw e_2;
198
- case 4: return [2 /*return*/];
199
+ unchainedError_1 = _a.sent();
200
+ log.warn(tag, "Unchained API failed, trying node fallback:", unchainedError_1.message);
201
+ _i = 0, MAYA_NODES_1 = MAYA_NODES;
202
+ _a.label = 4;
203
+ case 4:
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));
210
+ return [4 /*yield*/, axiosInstance({
211
+ method: 'GET',
212
+ url: "".concat(nodeUrl, "/auth/accounts/").concat(address),
213
+ timeout: 10000
214
+ })
215
+ // Node returns nested format already
216
+ ];
217
+ case 6:
218
+ nodeResult = _a.sent();
219
+ // Node returns nested format already
220
+ log.info(tag, "Account info retrieved from ".concat(nodeUrl));
221
+ return [2 /*return*/, nodeResult.data];
222
+ case 7:
223
+ nodeError_1 = _a.sent();
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*/];
199
233
  }
200
234
  });
201
235
  });
202
236
  };
203
237
  var get_balance = function (address) {
204
238
  return __awaiter(this, void 0, void 0, function () {
205
- var tag, accountInfo, balance, e_3;
239
+ var tag, accountInfo, balance, e_2;
206
240
  return __generator(this, function (_a) {
207
241
  switch (_a.label) {
208
242
  case 0:
@@ -219,9 +253,9 @@ var get_balance = function (address) {
219
253
  // Convert from base units to CACAO
220
254
  return [2 /*return*/, balance / BASE_MAYA];
221
255
  case 3:
222
- e_3 = _a.sent();
223
- log.error(tag, "Error:", e_3.message);
224
- throw e_3;
256
+ e_2 = _a.sent();
257
+ log.error(tag, "Error:", e_2.message);
258
+ throw e_2;
225
259
  case 4: return [2 /*return*/];
226
260
  }
227
261
  });
@@ -229,7 +263,7 @@ var get_balance = function (address) {
229
263
  };
230
264
  var get_balances = function (address) {
231
265
  return __awaiter(this, void 0, void 0, function () {
232
- var tag, accountInfo, output, cacaoBalance, _i, _a, asset, e_4;
266
+ var tag, accountInfo, output, cacaoBalance, _i, _a, asset, e_3;
233
267
  return __generator(this, function (_b) {
234
268
  switch (_b.label) {
235
269
  case 0:
@@ -278,9 +312,9 @@ var get_balances = function (address) {
278
312
  }
279
313
  return [2 /*return*/, output];
280
314
  case 3:
281
- e_4 = _b.sent();
282
- log.error(tag, "Error:", e_4.message);
283
- throw e_4;
315
+ e_3 = _b.sent();
316
+ log.error(tag, "Error:", e_3.message);
317
+ throw e_3;
284
318
  case 4: return [2 /*return*/];
285
319
  }
286
320
  });
@@ -288,7 +322,7 @@ var get_balances = function (address) {
288
322
  };
289
323
  var get_txs_by_address = function (address_1, cursor_1) {
290
324
  return __awaiter(this, arguments, void 0, function (address, cursor, pageSize) {
291
- var tag, params, result, e_5;
325
+ var tag, params, result, e_4;
292
326
  if (pageSize === void 0) { pageSize = 50; }
293
327
  return __generator(this, function (_a) {
294
328
  switch (_a.label) {
@@ -310,9 +344,9 @@ var get_txs_by_address = function (address_1, cursor_1) {
310
344
  result = _a.sent();
311
345
  return [2 /*return*/, result.data];
312
346
  case 3:
313
- e_5 = _a.sent();
314
- log.error(tag, "Error:", e_5.message);
315
- throw e_5;
347
+ e_4 = _a.sent();
348
+ log.error(tag, "Error:", e_4.message);
349
+ throw e_4;
316
350
  case 4: return [2 /*return*/];
317
351
  }
318
352
  });
@@ -339,16 +373,16 @@ var get_transaction = function (txid) {
339
373
  };
340
374
  var broadcast_transaction = function (tx) {
341
375
  return __awaiter(this, void 0, void 0, function () {
342
- var tag, output, payload, result, e_6;
343
- var _a;
344
- return __generator(this, function (_b) {
345
- switch (_b.label) {
376
+ var tag, output, payload, result, unchainedError_2, nodeErrors, _i, MAYA_NODES_2, nodeUrl, nodeResult, nodeError, nodeError_2, nodeErrorMsg;
377
+ var _a, _b, _c, _d, _e;
378
+ return __generator(this, function (_f) {
379
+ switch (_f.label) {
346
380
  case 0:
347
381
  tag = TAG + " | broadcast_transaction | ";
348
382
  output = { success: false };
349
- _b.label = 1;
383
+ _f.label = 1;
350
384
  case 1:
351
- _b.trys.push([1, 3, , 4]);
385
+ _f.trys.push([1, 3, , 4]);
352
386
  payload = {
353
387
  rawTx: tx
354
388
  };
@@ -360,32 +394,80 @@ var broadcast_transaction = function (tx) {
360
394
  timeout: 10000
361
395
  })];
362
396
  case 2:
363
- result = _b.sent();
364
- log.info(tag, 'Broadcast response:', result.data);
397
+ result = _f.sent();
398
+ log.info(tag, 'Unchained response:', result.data);
365
399
  // Unchained returns { txid: "hash" } on success
366
400
  if (result.data.txid || result.data.txHash) {
367
401
  output.txid = result.data.txid || result.data.txHash;
368
402
  output.success = true;
369
403
  output.endpoint = 'Unchained';
370
- log.info(tag, "\u2705 Broadcast SUCCESS - txid: ".concat(output.txid));
404
+ log.info(tag, "\u2705 Broadcast SUCCESS via Unchained - txid: ".concat(output.txid));
405
+ return [2 /*return*/, output];
371
406
  }
372
407
  else if (result.data.message) {
373
408
  output.error = result.data.message;
374
- log.error(tag, " Broadcast FAILED:", result.data.message);
409
+ log.warn(tag, "Unchained returned error:", result.data.message);
375
410
  }
376
- return [2 /*return*/, output];
411
+ return [3 /*break*/, 4];
377
412
  case 3:
378
- e_6 = _b.sent();
379
- log.error(tag, "Broadcast error:", e_6.message);
380
- if ((_a = e_6.response) === null || _a === void 0 ? void 0 : _a.data) {
381
- output.error = e_6.response.data.message || e_6.response.data.error || e_6.message;
382
- log.error(tag, "Response data:", e_6.response.data);
413
+ unchainedError_2 = _f.sent();
414
+ log.warn(tag, "Unchained API failed:", unchainedError_2.message);
415
+ if ((_a = unchainedError_2.response) === null || _a === void 0 ? void 0 : _a.data) {
416
+ output.error = unchainedError_2.response.data.message || unchainedError_2.response.data.error || unchainedError_2.message;
417
+ log.debug(tag, "Unchained error details:", unchainedError_2.response.data);
383
418
  }
384
- else {
385
- output.error = e_6.message || 'Broadcast failed';
419
+ return [3 /*break*/, 4];
420
+ case 4:
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));
431
+ return [4 /*yield*/, axiosInstance({
432
+ url: "".concat(nodeUrl, "/txs"),
433
+ method: 'POST',
434
+ data: {
435
+ tx: tx,
436
+ mode: 'sync'
437
+ },
438
+ timeout: 15000 // Increased timeout for direct nodes
439
+ })];
440
+ case 7:
441
+ nodeResult = _f.sent();
442
+ log.info(tag, 'Node response:', nodeResult.data);
443
+ // Node returns { txhash: "hash" } on success
444
+ if (nodeResult.data.txhash || nodeResult.data.hash) {
445
+ output.txid = nodeResult.data.txhash || nodeResult.data.hash;
446
+ output.success = true;
447
+ output.endpoint = nodeUrl;
448
+ log.info(tag, "\u2705 Broadcast SUCCESS via ".concat(nodeUrl, " - txid: ").concat(output.txid));
449
+ return [2 /*return*/, output];
450
+ }
451
+ else if (nodeResult.data.raw_log || nodeResult.data.message) {
452
+ nodeError = nodeResult.data.raw_log || nodeResult.data.message;
453
+ nodeErrors.push("".concat(nodeUrl, ": ").concat(nodeError));
454
+ log.warn(tag, "Node ".concat(nodeUrl, " returned error:"), nodeError);
386
455
  }
456
+ return [3 /*break*/, 9];
457
+ case 8:
458
+ nodeError_2 = _f.sent();
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;
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");
387
470
  return [2 /*return*/, output];
388
- case 4: return [2 /*return*/];
389
471
  }
390
472
  });
391
473
  });
@@ -393,7 +475,7 @@ var broadcast_transaction = function (tx) {
393
475
  // Pool endpoints use Midgard (not available in Unchained)
394
476
  var get_pool = function (poolId) {
395
477
  return __awaiter(this, void 0, void 0, function () {
396
- var tag, params, result, e_7;
478
+ var tag, params, result, e_5;
397
479
  return __generator(this, function (_a) {
398
480
  switch (_a.label) {
399
481
  case 0:
@@ -415,9 +497,9 @@ var get_pool = function (poolId) {
415
497
  result = _a.sent();
416
498
  return [2 /*return*/, result.data];
417
499
  case 3:
418
- e_7 = _a.sent();
419
- log.error(tag, "Error:", e_7.message);
420
- throw e_7;
500
+ e_5 = _a.sent();
501
+ log.error(tag, "Error:", e_5.message);
502
+ throw e_5;
421
503
  case 4: return [2 /*return*/];
422
504
  }
423
505
  });
@@ -425,7 +507,7 @@ var get_pool = function (poolId) {
425
507
  };
426
508
  var get_pools = function () {
427
509
  return __awaiter(this, void 0, void 0, function () {
428
- var tag, result, e_8;
510
+ var tag, result, e_6;
429
511
  return __generator(this, function (_a) {
430
512
  switch (_a.label) {
431
513
  case 0:
@@ -442,9 +524,9 @@ var get_pools = function () {
442
524
  result = _a.sent();
443
525
  return [2 /*return*/, result.data];
444
526
  case 3:
445
- e_8 = _a.sent();
446
- log.error(tag, "Error:", e_8.message);
447
- throw e_8;
527
+ e_6 = _a.sent();
528
+ log.error(tag, "Error:", e_6.message);
529
+ throw e_6;
448
530
  case 4: return [2 /*return*/];
449
531
  }
450
532
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/maya-network",
3
- "version": "8.12.1",
3
+ "version": "8.12.3",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {