@pioneer-platform/maya-network 8.12.0 → 8.12.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 +22 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +124 -49
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @pioneer-platform/maya-network
|
|
2
2
|
|
|
3
|
+
## 8.12.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add dual-endpoint fallback for MayaChain broadcast and account info
|
|
8
|
+
|
|
9
|
+
- Broadcast now tries Unchained API first, falls back to direct Maya node
|
|
10
|
+
- Account info has same fallback logic for reliability
|
|
11
|
+
- Better error messages showing both endpoint results
|
|
12
|
+
- Eliminates single point of failure
|
|
13
|
+
- Logs which endpoint succeeded for debugging
|
|
14
|
+
|
|
15
|
+
## 8.12.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Add backward compatibility wrapper for account info
|
|
20
|
+
|
|
21
|
+
- Wrap Unchained API response in old format (result.value structure)
|
|
22
|
+
- Fix transaction building errors from undefined `value` property
|
|
23
|
+
- Maintains compatibility with existing code expecting old node format
|
|
24
|
+
|
|
3
25
|
## 8.12.0
|
|
4
26
|
|
|
5
27
|
### Minor 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_NODE = "https://mayanode.mayachain.info";
|
|
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
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
Migrated from direct node calls to ShapeShift Unchained API
|
|
6
6
|
API Documentation: https://api.mayachain.shapeshift.com/swagger
|
|
7
7
|
*/
|
|
8
|
+
var __assign = (this && this.__assign) || function () {
|
|
9
|
+
__assign = Object.assign || function(t) {
|
|
10
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
+
s = arguments[i];
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
return __assign.apply(this, arguments);
|
|
18
|
+
};
|
|
8
19
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
20
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
21
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -66,8 +77,10 @@ axiosRetry(axiosInstance, {
|
|
|
66
77
|
log.debug(TAG, "Retry ".concat(retryCount, "/2: ").concat(error.message));
|
|
67
78
|
}
|
|
68
79
|
});
|
|
69
|
-
// Unchained API endpoint
|
|
80
|
+
// Unchained API endpoint (primary)
|
|
70
81
|
var UNCHAINED_API = 'https://api.mayachain.shapeshift.com';
|
|
82
|
+
// Direct node fallback
|
|
83
|
+
var MAYA_NODE = 'https://mayanode.mayachain.info';
|
|
71
84
|
// Fallback to Midgard for pool data (not available in Unchained)
|
|
72
85
|
var MIDGARD_API = 'https://midgard.mayachain.info/v2';
|
|
73
86
|
// Base unit conversion (10 decimal places for CACAO)
|
|
@@ -151,34 +164,63 @@ var get_info = function () {
|
|
|
151
164
|
};
|
|
152
165
|
var get_account_info = function (address) {
|
|
153
166
|
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
-
var tag, result,
|
|
167
|
+
var tag, result, unchainedData, unchainedError_1, nodeResult, nodeError_1;
|
|
155
168
|
return __generator(this, function (_a) {
|
|
156
169
|
switch (_a.label) {
|
|
157
170
|
case 0:
|
|
158
171
|
tag = TAG + " | get_account_info | ";
|
|
159
172
|
_a.label = 1;
|
|
160
173
|
case 1:
|
|
161
|
-
_a.trys.push([1, 3, ,
|
|
174
|
+
_a.trys.push([1, 3, , 8]);
|
|
162
175
|
return [4 /*yield*/, axiosInstance({
|
|
163
176
|
method: 'GET',
|
|
164
177
|
url: "".concat(UNCHAINED_API, "/api/v1/account/").concat(address),
|
|
165
178
|
timeout: 5000
|
|
166
|
-
})
|
|
179
|
+
})
|
|
180
|
+
// Unchained returns flat structure, wrap it for backward compatibility
|
|
181
|
+
];
|
|
167
182
|
case 2:
|
|
168
183
|
result = _a.sent();
|
|
169
|
-
|
|
184
|
+
unchainedData = result.data;
|
|
185
|
+
return [2 /*return*/, __assign({ result: {
|
|
186
|
+
value: {
|
|
187
|
+
account_number: String(unchainedData.accountNumber || '0'),
|
|
188
|
+
sequence: String(unchainedData.sequence || '0'),
|
|
189
|
+
address: unchainedData.pubkey || address,
|
|
190
|
+
coins: unchainedData.assets || [],
|
|
191
|
+
public_key: null // Not provided by Unchained
|
|
192
|
+
}
|
|
193
|
+
} }, unchainedData)];
|
|
170
194
|
case 3:
|
|
171
|
-
|
|
172
|
-
log.
|
|
173
|
-
|
|
174
|
-
case 4:
|
|
195
|
+
unchainedError_1 = _a.sent();
|
|
196
|
+
log.warn(tag, "Unchained API failed, trying node fallback:", unchainedError_1.message);
|
|
197
|
+
_a.label = 4;
|
|
198
|
+
case 4:
|
|
199
|
+
_a.trys.push([4, 6, , 7]);
|
|
200
|
+
return [4 /*yield*/, axiosInstance({
|
|
201
|
+
method: 'GET',
|
|
202
|
+
url: "".concat(MAYA_NODE, "/auth/accounts/").concat(address),
|
|
203
|
+
timeout: 5000
|
|
204
|
+
})
|
|
205
|
+
// Node returns nested format already
|
|
206
|
+
];
|
|
207
|
+
case 5:
|
|
208
|
+
nodeResult = _a.sent();
|
|
209
|
+
// Node returns nested format already
|
|
210
|
+
return [2 /*return*/, nodeResult.data];
|
|
211
|
+
case 6:
|
|
212
|
+
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*/];
|
|
175
217
|
}
|
|
176
218
|
});
|
|
177
219
|
});
|
|
178
220
|
};
|
|
179
221
|
var get_balance = function (address) {
|
|
180
222
|
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
-
var tag, accountInfo, balance,
|
|
223
|
+
var tag, accountInfo, balance, e_2;
|
|
182
224
|
return __generator(this, function (_a) {
|
|
183
225
|
switch (_a.label) {
|
|
184
226
|
case 0:
|
|
@@ -195,9 +237,9 @@ var get_balance = function (address) {
|
|
|
195
237
|
// Convert from base units to CACAO
|
|
196
238
|
return [2 /*return*/, balance / BASE_MAYA];
|
|
197
239
|
case 3:
|
|
198
|
-
|
|
199
|
-
log.error(tag, "Error:",
|
|
200
|
-
throw
|
|
240
|
+
e_2 = _a.sent();
|
|
241
|
+
log.error(tag, "Error:", e_2.message);
|
|
242
|
+
throw e_2;
|
|
201
243
|
case 4: return [2 /*return*/];
|
|
202
244
|
}
|
|
203
245
|
});
|
|
@@ -205,7 +247,7 @@ var get_balance = function (address) {
|
|
|
205
247
|
};
|
|
206
248
|
var get_balances = function (address) {
|
|
207
249
|
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
-
var tag, accountInfo, output, cacaoBalance, _i, _a, asset,
|
|
250
|
+
var tag, accountInfo, output, cacaoBalance, _i, _a, asset, e_3;
|
|
209
251
|
return __generator(this, function (_b) {
|
|
210
252
|
switch (_b.label) {
|
|
211
253
|
case 0:
|
|
@@ -254,9 +296,9 @@ var get_balances = function (address) {
|
|
|
254
296
|
}
|
|
255
297
|
return [2 /*return*/, output];
|
|
256
298
|
case 3:
|
|
257
|
-
|
|
258
|
-
log.error(tag, "Error:",
|
|
259
|
-
throw
|
|
299
|
+
e_3 = _b.sent();
|
|
300
|
+
log.error(tag, "Error:", e_3.message);
|
|
301
|
+
throw e_3;
|
|
260
302
|
case 4: return [2 /*return*/];
|
|
261
303
|
}
|
|
262
304
|
});
|
|
@@ -264,7 +306,7 @@ var get_balances = function (address) {
|
|
|
264
306
|
};
|
|
265
307
|
var get_txs_by_address = function (address_1, cursor_1) {
|
|
266
308
|
return __awaiter(this, arguments, void 0, function (address, cursor, pageSize) {
|
|
267
|
-
var tag, params, result,
|
|
309
|
+
var tag, params, result, e_4;
|
|
268
310
|
if (pageSize === void 0) { pageSize = 50; }
|
|
269
311
|
return __generator(this, function (_a) {
|
|
270
312
|
switch (_a.label) {
|
|
@@ -286,9 +328,9 @@ var get_txs_by_address = function (address_1, cursor_1) {
|
|
|
286
328
|
result = _a.sent();
|
|
287
329
|
return [2 /*return*/, result.data];
|
|
288
330
|
case 3:
|
|
289
|
-
|
|
290
|
-
log.error(tag, "Error:",
|
|
291
|
-
throw
|
|
331
|
+
e_4 = _a.sent();
|
|
332
|
+
log.error(tag, "Error:", e_4.message);
|
|
333
|
+
throw e_4;
|
|
292
334
|
case 4: return [2 /*return*/];
|
|
293
335
|
}
|
|
294
336
|
});
|
|
@@ -315,16 +357,16 @@ var get_transaction = function (txid) {
|
|
|
315
357
|
};
|
|
316
358
|
var broadcast_transaction = function (tx) {
|
|
317
359
|
return __awaiter(this, void 0, void 0, function () {
|
|
318
|
-
var tag, output, payload, result,
|
|
319
|
-
var _a;
|
|
320
|
-
return __generator(this, function (
|
|
321
|
-
switch (
|
|
360
|
+
var tag, output, payload, result, unchainedError_2, nodeResult, nodeError, nodeError_2, nodeErrorMsg;
|
|
361
|
+
var _a, _b, _c, _d, _e;
|
|
362
|
+
return __generator(this, function (_f) {
|
|
363
|
+
switch (_f.label) {
|
|
322
364
|
case 0:
|
|
323
365
|
tag = TAG + " | broadcast_transaction | ";
|
|
324
366
|
output = { success: false };
|
|
325
|
-
|
|
367
|
+
_f.label = 1;
|
|
326
368
|
case 1:
|
|
327
|
-
|
|
369
|
+
_f.trys.push([1, 3, , 4]);
|
|
328
370
|
payload = {
|
|
329
371
|
rawTx: tx
|
|
330
372
|
};
|
|
@@ -336,32 +378,65 @@ var broadcast_transaction = function (tx) {
|
|
|
336
378
|
timeout: 10000
|
|
337
379
|
})];
|
|
338
380
|
case 2:
|
|
339
|
-
result =
|
|
340
|
-
log.info(tag, '
|
|
381
|
+
result = _f.sent();
|
|
382
|
+
log.info(tag, 'Unchained response:', result.data);
|
|
341
383
|
// Unchained returns { txid: "hash" } on success
|
|
342
384
|
if (result.data.txid || result.data.txHash) {
|
|
343
385
|
output.txid = result.data.txid || result.data.txHash;
|
|
344
386
|
output.success = true;
|
|
345
387
|
output.endpoint = 'Unchained';
|
|
346
|
-
log.info(tag, "\u2705 Broadcast SUCCESS - txid: ".concat(output.txid));
|
|
388
|
+
log.info(tag, "\u2705 Broadcast SUCCESS via Unchained - txid: ".concat(output.txid));
|
|
389
|
+
return [2 /*return*/, output];
|
|
347
390
|
}
|
|
348
391
|
else if (result.data.message) {
|
|
349
392
|
output.error = result.data.message;
|
|
350
|
-
log.
|
|
393
|
+
log.warn(tag, "Unchained returned error:", result.data.message);
|
|
351
394
|
}
|
|
352
|
-
return [
|
|
395
|
+
return [3 /*break*/, 4];
|
|
353
396
|
case 3:
|
|
354
|
-
|
|
355
|
-
log.
|
|
356
|
-
if ((_a =
|
|
357
|
-
output.error =
|
|
358
|
-
log.
|
|
397
|
+
unchainedError_2 = _f.sent();
|
|
398
|
+
log.warn(tag, "Unchained API failed:", unchainedError_2.message);
|
|
399
|
+
if ((_a = unchainedError_2.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
400
|
+
output.error = unchainedError_2.response.data.message || unchainedError_2.response.data.error || unchainedError_2.message;
|
|
401
|
+
log.debug(tag, "Unchained error details:", unchainedError_2.response.data);
|
|
359
402
|
}
|
|
360
|
-
|
|
361
|
-
|
|
403
|
+
return [3 /*break*/, 4];
|
|
404
|
+
case 4:
|
|
405
|
+
_f.trys.push([4, 6, , 7]);
|
|
406
|
+
log.info(tag, "Trying direct Maya node fallback");
|
|
407
|
+
return [4 /*yield*/, axiosInstance({
|
|
408
|
+
url: "".concat(MAYA_NODE, "/txs"),
|
|
409
|
+
method: 'POST',
|
|
410
|
+
data: {
|
|
411
|
+
tx: tx,
|
|
412
|
+
mode: 'sync'
|
|
413
|
+
},
|
|
414
|
+
timeout: 10000
|
|
415
|
+
})];
|
|
416
|
+
case 5:
|
|
417
|
+
nodeResult = _f.sent();
|
|
418
|
+
log.info(tag, 'Node response:', nodeResult.data);
|
|
419
|
+
// Node returns { txhash: "hash" } on success
|
|
420
|
+
if (nodeResult.data.txhash || nodeResult.data.hash) {
|
|
421
|
+
output.txid = nodeResult.data.txhash || nodeResult.data.hash;
|
|
422
|
+
output.success = true;
|
|
423
|
+
output.endpoint = 'MayaNode';
|
|
424
|
+
log.info(tag, "\u2705 Broadcast SUCCESS via MayaNode - txid: ".concat(output.txid));
|
|
425
|
+
return [2 /*return*/, output];
|
|
362
426
|
}
|
|
363
|
-
|
|
364
|
-
|
|
427
|
+
else if (nodeResult.data.raw_log || nodeResult.data.message) {
|
|
428
|
+
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");
|
|
431
|
+
}
|
|
432
|
+
return [3 /*break*/, 7];
|
|
433
|
+
case 6:
|
|
434
|
+
nodeError_2 = _f.sent();
|
|
435
|
+
log.error(tag, "Node broadcast also failed:", nodeError_2.message);
|
|
436
|
+
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];
|
|
365
440
|
}
|
|
366
441
|
});
|
|
367
442
|
});
|
|
@@ -369,7 +444,7 @@ var broadcast_transaction = function (tx) {
|
|
|
369
444
|
// Pool endpoints use Midgard (not available in Unchained)
|
|
370
445
|
var get_pool = function (poolId) {
|
|
371
446
|
return __awaiter(this, void 0, void 0, function () {
|
|
372
|
-
var tag, params, result,
|
|
447
|
+
var tag, params, result, e_5;
|
|
373
448
|
return __generator(this, function (_a) {
|
|
374
449
|
switch (_a.label) {
|
|
375
450
|
case 0:
|
|
@@ -391,9 +466,9 @@ var get_pool = function (poolId) {
|
|
|
391
466
|
result = _a.sent();
|
|
392
467
|
return [2 /*return*/, result.data];
|
|
393
468
|
case 3:
|
|
394
|
-
|
|
395
|
-
log.error(tag, "Error:",
|
|
396
|
-
throw
|
|
469
|
+
e_5 = _a.sent();
|
|
470
|
+
log.error(tag, "Error:", e_5.message);
|
|
471
|
+
throw e_5;
|
|
397
472
|
case 4: return [2 /*return*/];
|
|
398
473
|
}
|
|
399
474
|
});
|
|
@@ -401,7 +476,7 @@ var get_pool = function (poolId) {
|
|
|
401
476
|
};
|
|
402
477
|
var get_pools = function () {
|
|
403
478
|
return __awaiter(this, void 0, void 0, function () {
|
|
404
|
-
var tag, result,
|
|
479
|
+
var tag, result, e_6;
|
|
405
480
|
return __generator(this, function (_a) {
|
|
406
481
|
switch (_a.label) {
|
|
407
482
|
case 0:
|
|
@@ -418,9 +493,9 @@ var get_pools = function () {
|
|
|
418
493
|
result = _a.sent();
|
|
419
494
|
return [2 /*return*/, result.data];
|
|
420
495
|
case 3:
|
|
421
|
-
|
|
422
|
-
log.error(tag, "Error:",
|
|
423
|
-
throw
|
|
496
|
+
e_6 = _a.sent();
|
|
497
|
+
log.error(tag, "Error:", e_6.message);
|
|
498
|
+
throw e_6;
|
|
424
499
|
case 4: return [2 /*return*/];
|
|
425
500
|
}
|
|
426
501
|
});
|