@pioneer-platform/maya-network 8.5.0 → 8.6.0
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/.turbo/turbo-build.log +2 -0
- package/CHANGELOG.md +11 -0
- package/build.sh +22 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.js +683 -0
- package/lib/index.js.map +107 -0
- package/package.json +2 -2
package/lib/index.js
ADDED
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/*
|
|
39
|
+
const thorMainnetClient: CosmosSDKClient = new CosmosSDKClient({
|
|
40
|
+
server: 'http://104.248.96.152:1317',
|
|
41
|
+
chainId: 'thorchain',
|
|
42
|
+
prefix: 'thor',
|
|
43
|
+
derive_path: "44'/931'/0'/0/0",
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
get nodes
|
|
48
|
+
curl https://testnet-seed.thorchain.info
|
|
49
|
+
|
|
50
|
+
//testnet
|
|
51
|
+
https://main.d3mbd42yfy75lz.amplifyapp.com/#/nodes
|
|
52
|
+
|
|
53
|
+
*/
|
|
54
|
+
var TAG = " | thorchain-api | ";
|
|
55
|
+
var prettyjson = require('prettyjson');
|
|
56
|
+
require("dotenv").config({ path: '../../../.env' });
|
|
57
|
+
var axiosLib = require('axios');
|
|
58
|
+
var Axios = axiosLib.default || axiosLib;
|
|
59
|
+
var https = require('https');
|
|
60
|
+
var axios = Axios.create({
|
|
61
|
+
httpsAgent: new https.Agent({
|
|
62
|
+
rejectUnauthorized: false
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
var axiosRetry = require('axios-retry');
|
|
66
|
+
axiosRetry(axios, {
|
|
67
|
+
retries: 3, // number of retries
|
|
68
|
+
retryDelay: function (retryCount) {
|
|
69
|
+
console.log("retry attempt: ".concat(retryCount));
|
|
70
|
+
return retryCount * 2000; // time interval between retries
|
|
71
|
+
},
|
|
72
|
+
retryCondition: function (error) {
|
|
73
|
+
console.error(error);
|
|
74
|
+
// if retry condition is not specified, by default idempotent requests are retried
|
|
75
|
+
return error.response.status === 503;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
var log = require('@pioneer-platform/loggerdog')();
|
|
79
|
+
var URL_THORNODE = 'https://mayanode.mayachain.info';
|
|
80
|
+
var URL_MIDGARD = 'https://midgard.mayachain.info/v2';
|
|
81
|
+
var BASE_THOR = 10000000000;
|
|
82
|
+
/**********************************
|
|
83
|
+
// Module
|
|
84
|
+
//**********************************/
|
|
85
|
+
module.exports = {
|
|
86
|
+
init: function (url, settings) {
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
isOnline: function () {
|
|
90
|
+
return true;
|
|
91
|
+
},
|
|
92
|
+
info: function () {
|
|
93
|
+
return get_node_info_verbose();
|
|
94
|
+
},
|
|
95
|
+
getBalance: function (address) {
|
|
96
|
+
return get_balance(address);
|
|
97
|
+
},
|
|
98
|
+
getBalances: function (address) {
|
|
99
|
+
return get_balances(address);
|
|
100
|
+
},
|
|
101
|
+
getAccount: function (address) {
|
|
102
|
+
return get_account_info(address);
|
|
103
|
+
},
|
|
104
|
+
getLastBlock: function () {
|
|
105
|
+
return get_last_block();
|
|
106
|
+
},
|
|
107
|
+
getBlockHeight: function () {
|
|
108
|
+
return get_block_height();
|
|
109
|
+
},
|
|
110
|
+
getAccountInfo: function (address) {
|
|
111
|
+
return get_account_info(address);
|
|
112
|
+
},
|
|
113
|
+
getPools: function () {
|
|
114
|
+
return get_pools();
|
|
115
|
+
},
|
|
116
|
+
getPool: function (poolId) {
|
|
117
|
+
return get_pool(poolId);
|
|
118
|
+
},
|
|
119
|
+
getPoolAddress: function () {
|
|
120
|
+
return get_pool_addresses();
|
|
121
|
+
},
|
|
122
|
+
txs: function (address) {
|
|
123
|
+
return get_txs_by_address(address);
|
|
124
|
+
},
|
|
125
|
+
getTransaction: function (txid) {
|
|
126
|
+
return get_transaction(txid);
|
|
127
|
+
},
|
|
128
|
+
transaction: function (txid) {
|
|
129
|
+
return get_transaction(txid);
|
|
130
|
+
},
|
|
131
|
+
broadcast: function (tx) {
|
|
132
|
+
return broadcast_transaction(tx);
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
/**********************************
|
|
136
|
+
// Lib
|
|
137
|
+
//**********************************/
|
|
138
|
+
var get_pool = function (poolId) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var tag, params, body, resp, e_1;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
switch (_a.label) {
|
|
143
|
+
case 0:
|
|
144
|
+
tag = TAG + " | get_pool | ";
|
|
145
|
+
_a.label = 1;
|
|
146
|
+
case 1:
|
|
147
|
+
_a.trys.push([1, 3, , 4]);
|
|
148
|
+
params = {
|
|
149
|
+
view: "full",
|
|
150
|
+
asset: poolId
|
|
151
|
+
};
|
|
152
|
+
body = {
|
|
153
|
+
method: 'GET',
|
|
154
|
+
url: URL_MIDGARD + "/pools/detail",
|
|
155
|
+
headers: { 'content-type': 'application/json' },
|
|
156
|
+
params: params
|
|
157
|
+
};
|
|
158
|
+
log.debug(body);
|
|
159
|
+
return [4 /*yield*/, axios(body)];
|
|
160
|
+
case 2:
|
|
161
|
+
resp = _a.sent();
|
|
162
|
+
return [2 /*return*/, resp.data];
|
|
163
|
+
case 3:
|
|
164
|
+
e_1 = _a.sent();
|
|
165
|
+
log.error(tag, "e: ", e_1);
|
|
166
|
+
throw e_1;
|
|
167
|
+
case 4: return [2 /*return*/];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
var get_pools = function () {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
var tag, body, resp, e_2;
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
tag = TAG + " | get_pools | ";
|
|
179
|
+
_a.label = 1;
|
|
180
|
+
case 1:
|
|
181
|
+
_a.trys.push([1, 3, , 4]);
|
|
182
|
+
body = {
|
|
183
|
+
method: 'GET',
|
|
184
|
+
url: URL_MIDGARD + "/pools",
|
|
185
|
+
headers: { 'content-type': 'application/json' },
|
|
186
|
+
// body: {account_name: actor},
|
|
187
|
+
// json: true
|
|
188
|
+
};
|
|
189
|
+
log.debug(body.url);
|
|
190
|
+
return [4 /*yield*/, axios(body)];
|
|
191
|
+
case 2:
|
|
192
|
+
resp = _a.sent();
|
|
193
|
+
return [2 /*return*/, resp.data];
|
|
194
|
+
case 3:
|
|
195
|
+
e_2 = _a.sent();
|
|
196
|
+
log.error(tag, "e: ", e_2);
|
|
197
|
+
throw e_2;
|
|
198
|
+
case 4: return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
//https://testnet.thornode.thorchain.info/thorchain/inbound_addresses
|
|
204
|
+
var get_pool_addresses = function () {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
var tag, output, body, resp, e_3;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
tag = TAG + " | get_pool_addresses | ";
|
|
211
|
+
_a.label = 1;
|
|
212
|
+
case 1:
|
|
213
|
+
_a.trys.push([1, 3, , 4]);
|
|
214
|
+
output = {};
|
|
215
|
+
body = {
|
|
216
|
+
method: 'GET',
|
|
217
|
+
url: URL_THORNODE + "/thorchain/inbound_addresses",
|
|
218
|
+
headers: { 'content-type': 'application/json' },
|
|
219
|
+
// body: {account_name: actor},
|
|
220
|
+
// json: true
|
|
221
|
+
};
|
|
222
|
+
log.debug(body);
|
|
223
|
+
return [4 /*yield*/, axios(body)];
|
|
224
|
+
case 2:
|
|
225
|
+
resp = _a.sent();
|
|
226
|
+
return [2 /*return*/, resp.data];
|
|
227
|
+
case 3:
|
|
228
|
+
e_3 = _a.sent();
|
|
229
|
+
log.error(tag, "e: ", e_3);
|
|
230
|
+
return [3 /*break*/, 4];
|
|
231
|
+
case 4: return [2 /*return*/];
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
var get_last_block = function () {
|
|
237
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
+
var tag, lastBlock, e_4;
|
|
239
|
+
return __generator(this, function (_a) {
|
|
240
|
+
switch (_a.label) {
|
|
241
|
+
case 0:
|
|
242
|
+
tag = TAG + " | get_last_block | ";
|
|
243
|
+
_a.label = 1;
|
|
244
|
+
case 1:
|
|
245
|
+
_a.trys.push([1, 3, , 4]);
|
|
246
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
|
|
247
|
+
case 2:
|
|
248
|
+
lastBlock = _a.sent();
|
|
249
|
+
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
250
|
+
return [2 /*return*/, lastBlock.data.block];
|
|
251
|
+
case 3:
|
|
252
|
+
e_4 = _a.sent();
|
|
253
|
+
log.error(tag, "e: ", e_4);
|
|
254
|
+
throw e_4;
|
|
255
|
+
case 4: return [2 /*return*/];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
var get_block_height = function () {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
262
|
+
var tag, lastBlock, e_5;
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
switch (_a.label) {
|
|
265
|
+
case 0:
|
|
266
|
+
tag = TAG + " | get_block_height | ";
|
|
267
|
+
_a.label = 1;
|
|
268
|
+
case 1:
|
|
269
|
+
_a.trys.push([1, 3, , 4]);
|
|
270
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
|
|
271
|
+
case 2:
|
|
272
|
+
lastBlock = _a.sent();
|
|
273
|
+
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
274
|
+
return [2 /*return*/, lastBlock.data.block.header.height];
|
|
275
|
+
case 3:
|
|
276
|
+
e_5 = _a.sent();
|
|
277
|
+
log.error(tag, "e: ", e_5);
|
|
278
|
+
throw e_5;
|
|
279
|
+
case 4: return [2 /*return*/];
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
var get_transaction = function (txid) {
|
|
285
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
286
|
+
var tag, txInfo, e_6, output;
|
|
287
|
+
return __generator(this, function (_a) {
|
|
288
|
+
switch (_a.label) {
|
|
289
|
+
case 0:
|
|
290
|
+
tag = TAG + " | get_transaction | ";
|
|
291
|
+
_a.label = 1;
|
|
292
|
+
case 1:
|
|
293
|
+
_a.trys.push([1, 3, , 4]);
|
|
294
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/txs/' + txid })];
|
|
295
|
+
case 2:
|
|
296
|
+
txInfo = _a.sent();
|
|
297
|
+
log.debug(tag, "txInfo: ", txInfo.data);
|
|
298
|
+
return [2 /*return*/, txInfo.data];
|
|
299
|
+
case 3:
|
|
300
|
+
e_6 = _a.sent();
|
|
301
|
+
// log.error(tag,e.response.data)
|
|
302
|
+
// log.error(tag,e.response.data.error)
|
|
303
|
+
if (e_6.response.status === 404) {
|
|
304
|
+
output = {};
|
|
305
|
+
output.success = false;
|
|
306
|
+
output.error = e_6.response.data.error;
|
|
307
|
+
return [2 /*return*/, output];
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
throw Error(e_6);
|
|
311
|
+
}
|
|
312
|
+
return [3 /*break*/, 4];
|
|
313
|
+
case 4: return [2 /*return*/];
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
var broadcast_transaction = function (tx) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
320
|
+
var tag, output, payload, urlRemote, result2, logSend, e_7, e_8;
|
|
321
|
+
return __generator(this, function (_a) {
|
|
322
|
+
switch (_a.label) {
|
|
323
|
+
case 0:
|
|
324
|
+
tag = TAG + " | broadcast_transaction | ";
|
|
325
|
+
output = {};
|
|
326
|
+
_a.label = 1;
|
|
327
|
+
case 1:
|
|
328
|
+
_a.trys.push([1, 6, , 7]);
|
|
329
|
+
log.debug(tag, "CHECKPOINT 1");
|
|
330
|
+
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,
|
|
337
|
+
"tx_bytes": tx,
|
|
338
|
+
"mode": "BROADCAST_MODE_SYNC"
|
|
339
|
+
};
|
|
340
|
+
urlRemote = URL_THORNODE + '/cosmos/tx/v1beta1/txs';
|
|
341
|
+
// let urlRemote = URL_GAIAD+ '/txs'
|
|
342
|
+
log.info(tag, "urlRemote: ", urlRemote);
|
|
343
|
+
return [4 /*yield*/, axios({
|
|
344
|
+
url: urlRemote,
|
|
345
|
+
headers: {
|
|
346
|
+
'api-key': process.env['NOW_NODES_API'],
|
|
347
|
+
'Content-Type': 'application/json'
|
|
348
|
+
},
|
|
349
|
+
method: 'POST',
|
|
350
|
+
data: payload,
|
|
351
|
+
})];
|
|
352
|
+
case 3:
|
|
353
|
+
result2 = _a.sent();
|
|
354
|
+
log.info(tag, '** Broadcast ** REMOTE: result: ', result2.data);
|
|
355
|
+
log.info(tag, '** Broadcast ** REMOTE: result: ', JSON.stringify(result2.data));
|
|
356
|
+
if (result2.data.txhash)
|
|
357
|
+
output.txid = result2.data.txhash;
|
|
358
|
+
//tx_response
|
|
359
|
+
if (result2.data.tx_response.txhash)
|
|
360
|
+
output.txid = result2.data.tx_response.txhash;
|
|
361
|
+
if (result2.data.tx_response.raw_log && result2.data.tx_response.raw_log !== '[]') {
|
|
362
|
+
logSend = result2.data.tx_response.raw_log;
|
|
363
|
+
log.debug(tag, "logSend: ", logSend);
|
|
364
|
+
output.success = false;
|
|
365
|
+
output.error = logSend;
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
output.success = true;
|
|
369
|
+
}
|
|
370
|
+
return [2 /*return*/, output];
|
|
371
|
+
case 4:
|
|
372
|
+
e_7 = _a.sent();
|
|
373
|
+
//log.error(tag,"failed second broadcast e: ",e.response)
|
|
374
|
+
log.error(tag, e_7);
|
|
375
|
+
log.error(tag, e_7.response);
|
|
376
|
+
log.error(tag, e_7.response.data);
|
|
377
|
+
log.error(tag, e_7.response.data.error);
|
|
378
|
+
log.error(tag, e_7.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
|
|
379
|
+
//throw e
|
|
380
|
+
output.success = false;
|
|
381
|
+
output.error = e_7.response.data.error;
|
|
382
|
+
return [3 /*break*/, 5];
|
|
383
|
+
case 5: return [2 /*return*/, output];
|
|
384
|
+
case 6:
|
|
385
|
+
e_8 = _a.sent();
|
|
386
|
+
console.error(tag, "throw error: ", e_8);
|
|
387
|
+
return [2 /*return*/, output];
|
|
388
|
+
case 7: return [2 /*return*/];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
var get_account_info = function (address) {
|
|
394
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
395
|
+
var tag, txInfo, e_9;
|
|
396
|
+
return __generator(this, function (_a) {
|
|
397
|
+
switch (_a.label) {
|
|
398
|
+
case 0:
|
|
399
|
+
tag = TAG + " | get_account_info | ";
|
|
400
|
+
_a.label = 1;
|
|
401
|
+
case 1:
|
|
402
|
+
_a.trys.push([1, 3, , 4]);
|
|
403
|
+
//
|
|
404
|
+
console.log("URL ", URL_THORNODE + '/auth/accounts/' + address);
|
|
405
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/auth/accounts/' + address })];
|
|
406
|
+
case 2:
|
|
407
|
+
txInfo = _a.sent();
|
|
408
|
+
log.debug(tag, "txInfo: ", txInfo.data);
|
|
409
|
+
return [2 /*return*/, txInfo.data];
|
|
410
|
+
case 3:
|
|
411
|
+
e_9 = _a.sent();
|
|
412
|
+
log.error(tag, "e: ", e_9);
|
|
413
|
+
throw e_9;
|
|
414
|
+
case 4: return [2 /*return*/];
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
var normalize_tx = function (tx, address) {
|
|
420
|
+
var tag = TAG + " | normalize_tx | ";
|
|
421
|
+
try {
|
|
422
|
+
var output = {};
|
|
423
|
+
var sender = void 0;
|
|
424
|
+
var receiver = void 0;
|
|
425
|
+
var memo = void 0;
|
|
426
|
+
var amount = void 0;
|
|
427
|
+
var rawlog = JSON.parse(tx.raw_log);
|
|
428
|
+
rawlog = rawlog;
|
|
429
|
+
//log.debug("rawlog: ",rawlog)
|
|
430
|
+
//txTypes
|
|
431
|
+
var txTypes = [
|
|
432
|
+
'send',
|
|
433
|
+
'receive',
|
|
434
|
+
'governence',
|
|
435
|
+
'swap',
|
|
436
|
+
'other'
|
|
437
|
+
];
|
|
438
|
+
for (var i = 0; i < rawlog.length; i++) {
|
|
439
|
+
var txEvents = rawlog[i];
|
|
440
|
+
//log.debug(tag,"txEvents: ",txEvents)
|
|
441
|
+
txEvents = txEvents.events;
|
|
442
|
+
for (var j = 0; j < txEvents.length; j++) {
|
|
443
|
+
var event_1 = txEvents[j];
|
|
444
|
+
//
|
|
445
|
+
//log.debug(tag,"event: ",event)
|
|
446
|
+
//log.debug(tag,"attributes: ",prettyjson.render(event.attributes))
|
|
447
|
+
//detect event type
|
|
448
|
+
log.debug(tag, "type: ", event_1.type);
|
|
449
|
+
switch (event_1.type) {
|
|
450
|
+
case 'message':
|
|
451
|
+
// ignore
|
|
452
|
+
break;
|
|
453
|
+
case 'transfer':
|
|
454
|
+
log.debug(tag, "attributes: ", event_1.attributes);
|
|
455
|
+
for (var k = 0; k < event_1.attributes.length; k++) {
|
|
456
|
+
var attribute = event_1.attributes[k];
|
|
457
|
+
if (attribute.key === 'recipient') {
|
|
458
|
+
receiver = attribute.value;
|
|
459
|
+
output.receiver = receiver;
|
|
460
|
+
if (receiver === address)
|
|
461
|
+
output.type = txTypes[1];
|
|
462
|
+
}
|
|
463
|
+
if (attribute.key === 'sender') {
|
|
464
|
+
sender = attribute.value;
|
|
465
|
+
output.sender = sender;
|
|
466
|
+
if (sender === address)
|
|
467
|
+
output.type = txTypes[0];
|
|
468
|
+
}
|
|
469
|
+
if (attribute.key === 'amount') {
|
|
470
|
+
amount = attribute.value;
|
|
471
|
+
amount = amount.replace('rune', '');
|
|
472
|
+
output.amount = amount / 100000000;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
break;
|
|
476
|
+
default:
|
|
477
|
+
// code block
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
// console.log("log: ",prettyjson.render(log))
|
|
481
|
+
}
|
|
482
|
+
return output;
|
|
483
|
+
}
|
|
484
|
+
catch (e) {
|
|
485
|
+
log.error(tag, "e: ", e);
|
|
486
|
+
throw e;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
var get_txs_by_address = function (address) {
|
|
490
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
491
|
+
var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx, e_10;
|
|
492
|
+
return __generator(this, function (_a) {
|
|
493
|
+
switch (_a.label) {
|
|
494
|
+
case 0:
|
|
495
|
+
tag = TAG + " | get_txs_by_address | ";
|
|
496
|
+
_a.label = 1;
|
|
497
|
+
case 1:
|
|
498
|
+
_a.trys.push([1, 4, , 5]);
|
|
499
|
+
output = [];
|
|
500
|
+
url = URL_THORNODE + '/txs?message.sender=' + address;
|
|
501
|
+
log.debug(tag, "url: ", url);
|
|
502
|
+
return [4 /*yield*/, axios({
|
|
503
|
+
url: url,
|
|
504
|
+
method: 'GET'
|
|
505
|
+
})];
|
|
506
|
+
case 2:
|
|
507
|
+
resultSends = _a.sent();
|
|
508
|
+
sends = resultSends.data;
|
|
509
|
+
log.debug('sends: ', sends);
|
|
510
|
+
if (!sends.txs)
|
|
511
|
+
sends.txs = [];
|
|
512
|
+
// TODO//pagnation
|
|
513
|
+
for (i = 0; i < (sends === null || sends === void 0 ? void 0 : sends.txs.length); i++) {
|
|
514
|
+
tx = sends.txs[i];
|
|
515
|
+
//pretty json
|
|
516
|
+
//normalize
|
|
517
|
+
tx = normalize_tx(tx, address);
|
|
518
|
+
output.push(tx);
|
|
519
|
+
}
|
|
520
|
+
//receives
|
|
521
|
+
url = URL_THORNODE + '/txs?transfer.recipient=' + address;
|
|
522
|
+
console.log("URL_THORNODE: ", url);
|
|
523
|
+
return [4 /*yield*/, axios({
|
|
524
|
+
url: url,
|
|
525
|
+
method: 'GET'
|
|
526
|
+
})];
|
|
527
|
+
case 3:
|
|
528
|
+
resultRecieves = _a.sent();
|
|
529
|
+
receives = resultRecieves.data;
|
|
530
|
+
if (!receives.txs)
|
|
531
|
+
receives.txs = [];
|
|
532
|
+
log.debug('receives: ', receives);
|
|
533
|
+
for (i = 0; i < (receives === null || receives === void 0 ? void 0 : receives.txs.length); i++) {
|
|
534
|
+
tx = receives.txs[i];
|
|
535
|
+
//normalize
|
|
536
|
+
tx = normalize_tx(tx, address);
|
|
537
|
+
output.push(tx);
|
|
538
|
+
}
|
|
539
|
+
return [2 /*return*/, output];
|
|
540
|
+
case 4:
|
|
541
|
+
e_10 = _a.sent();
|
|
542
|
+
log.error(tag, "e: ", e_10);
|
|
543
|
+
throw e_10;
|
|
544
|
+
case 5: return [2 /*return*/];
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
};
|
|
549
|
+
var get_balance = function (address) {
|
|
550
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
551
|
+
var tag, output, accountInfo, i, entry, e_11, e_12;
|
|
552
|
+
var _a;
|
|
553
|
+
return __generator(this, function (_b) {
|
|
554
|
+
switch (_b.label) {
|
|
555
|
+
case 0:
|
|
556
|
+
tag = TAG + " | get_balance | ";
|
|
557
|
+
_b.label = 1;
|
|
558
|
+
case 1:
|
|
559
|
+
_b.trys.push([1, 6, , 7]);
|
|
560
|
+
output = 0;
|
|
561
|
+
_b.label = 2;
|
|
562
|
+
case 2:
|
|
563
|
+
_b.trys.push([2, 4, , 5]);
|
|
564
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/bank/balances/' + address })];
|
|
565
|
+
case 3:
|
|
566
|
+
accountInfo = _b.sent();
|
|
567
|
+
log.info(tag, "accountInfo: ", accountInfo.data);
|
|
568
|
+
//
|
|
569
|
+
if ((_a = accountInfo.data) === null || _a === void 0 ? void 0 : _a.result) {
|
|
570
|
+
for (i = 0; i < accountInfo.data.result.length; i++) {
|
|
571
|
+
entry = accountInfo.data.result[i];
|
|
572
|
+
if (entry.denom === 'cacao') {
|
|
573
|
+
output = entry.amount;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
output = output / BASE_THOR;
|
|
578
|
+
return [3 /*break*/, 5];
|
|
579
|
+
case 4:
|
|
580
|
+
e_11 = _b.sent();
|
|
581
|
+
return [3 /*break*/, 5];
|
|
582
|
+
case 5: return [2 /*return*/, output];
|
|
583
|
+
case 6:
|
|
584
|
+
e_12 = _b.sent();
|
|
585
|
+
log.error(tag, "e: ", e_12);
|
|
586
|
+
throw e_12;
|
|
587
|
+
case 7: return [2 /*return*/];
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
var get_balances = function (address) {
|
|
593
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
594
|
+
var tag, output, accountInfo, i, entry, e_13, e_14;
|
|
595
|
+
var _a;
|
|
596
|
+
return __generator(this, function (_b) {
|
|
597
|
+
switch (_b.label) {
|
|
598
|
+
case 0:
|
|
599
|
+
tag = TAG + " | get_balances | ";
|
|
600
|
+
_b.label = 1;
|
|
601
|
+
case 1:
|
|
602
|
+
_b.trys.push([1, 6, , 7]);
|
|
603
|
+
output = [];
|
|
604
|
+
_b.label = 2;
|
|
605
|
+
case 2:
|
|
606
|
+
_b.trys.push([2, 4, , 5]);
|
|
607
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/bank/balances/' + address })];
|
|
608
|
+
case 3:
|
|
609
|
+
accountInfo = _b.sent();
|
|
610
|
+
log.info(tag, "accountInfo: ", accountInfo.data);
|
|
611
|
+
//
|
|
612
|
+
if ((_a = accountInfo.data) === null || _a === void 0 ? void 0 : _a.result) {
|
|
613
|
+
for (i = 0; i < accountInfo.data.result.length; i++) {
|
|
614
|
+
entry = accountInfo.data.result[i];
|
|
615
|
+
if (entry.denom === 'cacao') {
|
|
616
|
+
output.push({
|
|
617
|
+
denom: entry.denom,
|
|
618
|
+
amountBase: entry.amount,
|
|
619
|
+
amount: entry.amount / 10000000000,
|
|
620
|
+
decimals: 10
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
if (entry.denom === 'maya') {
|
|
624
|
+
output.push({
|
|
625
|
+
denom: entry.denom,
|
|
626
|
+
amountBase: entry.amount,
|
|
627
|
+
amount: entry.amount / 10000,
|
|
628
|
+
decimals: 4
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return [3 /*break*/, 5];
|
|
634
|
+
case 4:
|
|
635
|
+
e_13 = _b.sent();
|
|
636
|
+
return [3 /*break*/, 5];
|
|
637
|
+
case 5: return [2 /*return*/, output];
|
|
638
|
+
case 6:
|
|
639
|
+
e_14 = _b.sent();
|
|
640
|
+
log.error(tag, "e: ", e_14);
|
|
641
|
+
throw e_14;
|
|
642
|
+
case 7: return [2 /*return*/];
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
var get_node_info_verbose = function () {
|
|
648
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
649
|
+
var tag, output, syncInfo, nodeInfo, lastBlock, e_15;
|
|
650
|
+
return __generator(this, function (_a) {
|
|
651
|
+
switch (_a.label) {
|
|
652
|
+
case 0:
|
|
653
|
+
tag = TAG + " | get_node_info | ";
|
|
654
|
+
_a.label = 1;
|
|
655
|
+
case 1:
|
|
656
|
+
_a.trys.push([1, 5, , 6]);
|
|
657
|
+
output = {};
|
|
658
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/syncing' })];
|
|
659
|
+
case 2:
|
|
660
|
+
syncInfo = _a.sent();
|
|
661
|
+
log.debug(tag, "syncInfo: ", syncInfo.data);
|
|
662
|
+
output.isSyncing = syncInfo.data;
|
|
663
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/node_info' })];
|
|
664
|
+
case 3:
|
|
665
|
+
nodeInfo = _a.sent();
|
|
666
|
+
log.debug(tag, "nodeInfo: ", nodeInfo.data);
|
|
667
|
+
output = nodeInfo.data;
|
|
668
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
|
|
669
|
+
case 4:
|
|
670
|
+
lastBlock = _a.sent();
|
|
671
|
+
log.debug(tag, "lastBlock: ", lastBlock.data);
|
|
672
|
+
//let height
|
|
673
|
+
output.height = lastBlock.data.block.header.height;
|
|
674
|
+
return [2 /*return*/, output];
|
|
675
|
+
case 5:
|
|
676
|
+
e_15 = _a.sent();
|
|
677
|
+
log.error(tag, "e: ", e_15);
|
|
678
|
+
throw e_15;
|
|
679
|
+
case 6: return [2 /*return*/];
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
};
|