@pioneer-platform/maya-network 8.11.0 → 8.11.1

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,2 +1 @@
1
-
2
- $ tsc -p .
1
+ $ tsc -p .
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @pioneer-platform/maya-network
2
2
 
3
+ ## 8.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 3f2da9a: Add ShapeShift MayaChain Unchained API integration with dual broadcast support
8
+
9
+ - Added MayaChain Unchained endpoints to pioneer-nodes seed configuration
10
+ - Implemented dual broadcast in maya-network (MayaNode + ShapeShift Unchained + NowNodes fallbacks)
11
+ - Added endpoint-specific payload formatting (Cosmos vs Unchained API formats)
12
+ - Updated unchained integration tests for MayaChain broadcast validation
13
+
3
14
  ## 8.11.0
4
15
 
5
16
  ### Minor Changes
package/lib/index.d.ts CHANGED
@@ -8,6 +8,8 @@ declare const axiosRetry: any;
8
8
  declare const log: any;
9
9
  declare let URL_THORNODE: string;
10
10
  declare let URL_MIDGARD: string;
11
+ declare const NOWNODES_ENDPOINTS: string[];
12
+ declare const UNCHAINED_ENDPOINT = "https://api.mayachain.shapeshift.com";
11
13
  declare let BASE_THOR: number;
12
14
  /**********************************
13
15
  // Lib
package/lib/index.js CHANGED
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
38
47
  /*
39
48
  const thorMainnetClient: CosmosSDKClient = new CosmosSDKClient({
40
49
  server: 'http://104.248.96.152:1317',
@@ -78,6 +87,13 @@ axiosRetry(axios, {
78
87
  var log = require('@pioneer-platform/loggerdog')();
79
88
  var URL_THORNODE = 'https://mayanode.mayachain.info';
80
89
  var URL_MIDGARD = 'https://midgard.mayachain.info/v2';
90
+ // NowNodes fallback endpoints
91
+ var NOWNODES_ENDPOINTS = [
92
+ 'https://maya.nownodes.io',
93
+ 'https://mayachain.nownodes.io'
94
+ ];
95
+ // ShapeShift Unchained API endpoint
96
+ var UNCHAINED_ENDPOINT = 'https://api.mayachain.shapeshift.com';
81
97
  var BASE_THOR = 10000000000;
82
98
  /**********************************
83
99
  // Module
@@ -317,7 +333,7 @@ var get_transaction = function (txid) {
317
333
  };
318
334
  var broadcast_transaction = function (tx) {
319
335
  return __awaiter(this, void 0, void 0, function () {
320
- var tag, output, payload, urlRemote, result2, errorMsg, e_7, e_8;
336
+ var tag, output, cosmosPayload, unchainedPayload, endpoints, lastError, i, endpoint, urlRemote, headers, payload, result2, errorMsg, e_7, e_8;
321
337
  return __generator(this, function (_a) {
322
338
  switch (_a.label) {
323
339
  case 0:
@@ -325,72 +341,137 @@ var broadcast_transaction = function (tx) {
325
341
  output = {};
326
342
  _a.label = 1;
327
343
  case 1:
328
- _a.trys.push([1, 6, , 7]);
344
+ _a.trys.push([1, 8, , 9]);
329
345
  log.debug(tag, "CHECKPOINT 1");
330
346
  output.success = false;
331
- _a.label = 2;
332
- case 2:
333
- _a.trys.push([2, 4, , 5]);
334
- payload = {
335
- // "tx_bytes": btoa(tx),
336
- // "tx_bytes":broadcastTx,
347
+ cosmosPayload = {
337
348
  "tx_bytes": tx,
338
349
  "mode": "BROADCAST_MODE_SYNC"
339
350
  };
340
- urlRemote = URL_THORNODE + '/cosmos/tx/v1beta1/txs';
341
- // let urlRemote = URL_GAIAD+ '/txs'
342
- log.info(tag, "urlRemote: ", urlRemote);
351
+ unchainedPayload = {
352
+ "rawTx": tx
353
+ };
354
+ endpoints = __spreadArray([
355
+ { url: URL_THORNODE, type: 'cosmos', name: 'MayaNode' },
356
+ { url: UNCHAINED_ENDPOINT, type: 'unchained', name: 'ShapeShift Unchained' }
357
+ ], NOWNODES_ENDPOINTS.map(function (url) { return ({ url: url, type: 'cosmos', name: 'NowNodes' }); }), true);
358
+ lastError = null;
359
+ i = 0;
360
+ _a.label = 2;
361
+ case 2:
362
+ if (!(i < endpoints.length)) return [3 /*break*/, 7];
363
+ endpoint = endpoints[i];
364
+ _a.label = 3;
365
+ case 3:
366
+ _a.trys.push([3, 5, , 6]);
367
+ urlRemote = endpoint.type === 'unchained'
368
+ ? endpoint.url + '/api/v1/send'
369
+ : endpoint.url + '/cosmos/tx/v1beta1/txs';
370
+ log.info(tag, "Attempting broadcast to ".concat(endpoint.name, " (").concat(i + 1, "/").concat(endpoints.length, "): ").concat(urlRemote));
371
+ headers = {
372
+ 'Content-Type': 'application/json'
373
+ };
374
+ // Add NowNodes API key if using NowNodes endpoint
375
+ if (endpoint.url.includes('nownodes.io') && process.env['NOW_NODES_API']) {
376
+ headers['api-key'] = process.env['NOW_NODES_API'];
377
+ }
378
+ payload = endpoint.type === 'unchained' ? unchainedPayload : cosmosPayload;
343
379
  return [4 /*yield*/, axios({
344
380
  url: urlRemote,
345
- headers: {
346
- 'api-key': process.env['NOW_NODES_API'],
347
- 'Content-Type': 'application/json'
348
- },
381
+ headers: headers,
349
382
  method: 'POST',
350
383
  data: payload,
384
+ timeout: 10000 // 10 second timeout
351
385
  })];
352
- case 3:
386
+ case 4:
353
387
  result2 = _a.sent();
354
388
  log.info(tag, '** Broadcast ** REMOTE: result: ', result2.data);
355
389
  log.info(tag, '** Broadcast ** REMOTE: result: ', JSON.stringify(result2.data));
356
- // CRITICAL: Check tx_response.code - Cosmos standard for success/error
357
- // code: 0 = success, any other code = error
358
- if (result2.data.tx_response && result2.data.tx_response.code !== 0) {
359
- errorMsg = result2.data.tx_response.raw_log || 'Transaction failed with unknown error';
360
- log.error(tag, "❌ Broadcast FAILED - code:", result2.data.tx_response.code);
361
- log.error(tag, " Error:", errorMsg);
362
- output.success = false;
363
- output.error = errorMsg;
364
- // Throw error to fail fast - don't let failed transactions proceed
365
- throw new Error("Broadcast failed (code ".concat(result2.data.tx_response.code, "): ").concat(errorMsg));
390
+ // Handle different response formats
391
+ if (endpoint.type === 'unchained') {
392
+ // Unchained API returns { txid: "hash" } on success
393
+ // or throws error with response.data.message on failure
394
+ if (result2.data.txid || result2.data.txHash) {
395
+ output.txid = result2.data.txid || result2.data.txHash;
396
+ output.success = true;
397
+ output.endpoint = endpoint.name;
398
+ log.info(tag, "\u2705 Broadcast SUCCESS via ".concat(endpoint.name, " - txid:"), output.txid);
399
+ return [2 /*return*/, output];
400
+ }
401
+ else if (result2.data.message) {
402
+ // Unchained error response
403
+ throw new Error(result2.data.message);
404
+ }
366
405
  }
367
- // Only set txid if transaction was successful (code === 0)
368
- if (result2.data.txhash)
369
- output.txid = result2.data.txhash;
370
- //tx_response
371
- if (result2.data.tx_response.txhash)
372
- output.txid = result2.data.tx_response.txhash;
373
- output.success = true;
374
- log.info(tag, "✅ Broadcast SUCCESS - txid:", output.txid);
375
- return [2 /*return*/, output];
376
- case 4:
406
+ else {
407
+ // Cosmos standard response format
408
+ // CRITICAL: Check tx_response.code - Cosmos standard for success/error
409
+ // code: 0 = success, any other code = error
410
+ if (result2.data.tx_response && result2.data.tx_response.code !== 0) {
411
+ errorMsg = result2.data.tx_response.raw_log || 'Transaction failed with unknown error';
412
+ log.error(tag, "❌ Broadcast FAILED - code:", result2.data.tx_response.code);
413
+ log.error(tag, " Error:", errorMsg);
414
+ output.success = false;
415
+ output.error = errorMsg;
416
+ // Throw error to fail fast - don't let failed transactions proceed
417
+ throw new Error("Broadcast failed (code ".concat(result2.data.tx_response.code, "): ").concat(errorMsg));
418
+ }
419
+ // Only set txid if transaction was successful (code === 0)
420
+ if (result2.data.txhash)
421
+ output.txid = result2.data.txhash;
422
+ //tx_response
423
+ if (result2.data.tx_response && result2.data.tx_response.txhash)
424
+ output.txid = result2.data.tx_response.txhash;
425
+ output.success = true;
426
+ output.endpoint = endpoint.name;
427
+ log.info(tag, "\u2705 Broadcast SUCCESS via ".concat(endpoint.name, " - txid:"), output.txid);
428
+ return [2 /*return*/, output];
429
+ }
430
+ return [3 /*break*/, 6];
431
+ case 5:
377
432
  e_7 = _a.sent();
378
- //log.error(tag,"failed second broadcast e: ",e.response)
379
- log.error(tag, e_7);
380
- log.error(tag, e_7.response);
381
- log.error(tag, e_7.response.data);
382
- log.error(tag, e_7.response.data.error);
383
- log.error(tag, e_7.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
384
- //throw e
385
- output.success = false;
386
- output.error = e_7.response.data.error;
387
- return [3 /*break*/, 5];
388
- case 5: return [2 /*return*/, output];
433
+ lastError = e_7;
434
+ log.error(tag, "Failed to broadcast via ".concat(endpoint.name, ":"), e_7.message);
435
+ if (e_7.response) {
436
+ log.error(tag, "Response status:", e_7.response.status);
437
+ log.error(tag, "Response data:", e_7.response.data);
438
+ // If this is a transaction validation error (not a network error), don't try other endpoints
439
+ if (e_7.response.data && e_7.response.data.message &&
440
+ (e_7.response.data.message.includes('insufficient') ||
441
+ e_7.response.data.message.includes('invalid'))) {
442
+ output.success = false;
443
+ output.error = e_7.response.data.message || e_7.response.data.error;
444
+ log.error(tag, "Transaction validation error - not retrying other endpoints");
445
+ return [2 /*return*/, output];
446
+ }
447
+ }
448
+ // If not last endpoint, try next one
449
+ if (i < endpoints.length - 1) {
450
+ log.info(tag, "Trying next endpoint...");
451
+ return [3 /*break*/, 6];
452
+ }
453
+ return [3 /*break*/, 6];
389
454
  case 6:
455
+ i++;
456
+ return [3 /*break*/, 2];
457
+ case 7:
458
+ // All endpoints failed
459
+ output.success = false;
460
+ if (lastError && lastError.response && lastError.response.data) {
461
+ output.error = lastError.response.data.error || lastError.response.data.message || lastError.message;
462
+ }
463
+ else {
464
+ output.error = (lastError === null || lastError === void 0 ? void 0 : lastError.message) || 'All broadcast endpoints failed';
465
+ }
466
+ log.error(tag, "❌ All broadcast endpoints failed");
467
+ return [2 /*return*/, output];
468
+ case 8:
390
469
  e_8 = _a.sent();
391
- console.error(tag, "throw error: ", e_8);
470
+ console.error(tag, "Unexpected error in broadcast: ", e_8);
471
+ output.success = false;
472
+ output.error = e_8.message || 'Unexpected broadcast error';
392
473
  return [2 /*return*/, output];
393
- case 7: return [2 /*return*/];
474
+ case 9: return [2 /*return*/];
394
475
  }
395
476
  });
396
477
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/maya-network",
3
- "version": "8.11.0",
3
+ "version": "8.11.1",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {