@pioneer-platform/thor-network 8.3.3 → 8.3.5

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/lib/index.js CHANGED
@@ -1,40 +1,3 @@
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;
13
- return g = { next: verb(0), "throw": verb(1), "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
1
  /*
39
2
  const thorMainnetClient: CosmosSDKClient = new CosmosSDKClient({
40
3
  server: 'http://104.248.96.152:1317',
@@ -51,33 +14,33 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
51
14
  https://main.d3mbd42yfy75lz.amplifyapp.com/#/nodes
52
15
 
53
16
  */
54
- var TAG = " | thorchain-api | ";
55
- var prettyjson = require('prettyjson');
17
+ const TAG = " | thorchain-api | ";
18
+ const prettyjson = require('prettyjson');
56
19
  require("dotenv").config({ path: '../../../.env' });
57
- var Axios = require('axios');
58
- var https = require('https');
59
- var axios = Axios.create({
20
+ const Axios = require('axios');
21
+ const https = require('https');
22
+ const axios = Axios.create({
60
23
  httpsAgent: new https.Agent({
61
24
  rejectUnauthorized: false
62
25
  })
63
26
  });
64
- var axiosRetry = require('axios-retry');
27
+ const axiosRetry = require('axios-retry');
65
28
  axiosRetry(axios, {
66
29
  retries: 3, // number of retries
67
- retryDelay: function (retryCount) {
68
- console.log("retry attempt: ".concat(retryCount));
30
+ retryDelay: (retryCount) => {
31
+ console.log(`retry attempt: ${retryCount}`);
69
32
  return retryCount * 2000; // time interval between retries
70
33
  },
71
- retryCondition: function (error) {
34
+ retryCondition: (error) => {
72
35
  console.error(error);
73
36
  // if retry condition is not specified, by default idempotent requests are retried
74
37
  return error.response.status === 503;
75
38
  },
76
39
  });
77
- var log = require('@pioneer-platform/loggerdog')();
78
- var URL_THORNODE = process.env['URL_THORNODE'] || 'https://thornode.ninerealms.com';
40
+ const log = require('@pioneer-platform/loggerdog')();
41
+ let URL_THORNODE = process.env['URL_THORNODE'] || 'https://thornode.ninerealms.com';
79
42
  //let URL_MIDGARD = process.env['URL_THORNODE'] || 'https://testnet.midgard.thorchain.info/v2'
80
- var BASE_THOR = 100000000;
43
+ let BASE_THOR = 100000000;
81
44
  /**********************************
82
45
  // Module
83
46
  //**********************************/
@@ -122,215 +85,216 @@ module.exports = {
122
85
  /**********************************
123
86
  // Lib
124
87
  //**********************************/
125
- var get_last_block = function () {
126
- return __awaiter(this, void 0, void 0, function () {
127
- var tag, lastBlock, e_1;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0:
131
- tag = TAG + " | get_last_block | ";
132
- _a.label = 1;
133
- case 1:
134
- _a.trys.push([1, 3, , 4]);
135
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
136
- case 2:
137
- lastBlock = _a.sent();
138
- log.debug(tag, "lastBlock: ", lastBlock.data);
139
- return [2 /*return*/, lastBlock.data.block];
140
- case 3:
141
- e_1 = _a.sent();
142
- log.error(tag, "e: ", e_1);
143
- throw e_1;
144
- case 4: return [2 /*return*/];
145
- }
146
- });
147
- });
88
+ let get_last_block = async function () {
89
+ let tag = TAG + " | get_last_block | ";
90
+ try {
91
+ let lastBlock = await axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' });
92
+ log.debug(tag, "lastBlock: ", lastBlock.data);
93
+ return lastBlock.data.block;
94
+ }
95
+ catch (e) {
96
+ log.error(tag, "e: ", e);
97
+ throw e;
98
+ }
148
99
  };
149
- var get_block_height = function () {
150
- return __awaiter(this, void 0, void 0, function () {
151
- var tag, lastBlock, e_2;
152
- return __generator(this, function (_a) {
153
- switch (_a.label) {
154
- case 0:
155
- tag = TAG + " | get_block_height | ";
156
- _a.label = 1;
157
- case 1:
158
- _a.trys.push([1, 3, , 4]);
159
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
160
- case 2:
161
- lastBlock = _a.sent();
162
- log.debug(tag, "lastBlock: ", lastBlock.data);
163
- return [2 /*return*/, lastBlock.data.block.header.height];
164
- case 3:
165
- e_2 = _a.sent();
166
- log.error(tag, "e: ", e_2);
167
- throw e_2;
168
- case 4: return [2 /*return*/];
169
- }
170
- });
171
- });
100
+ let get_block_height = async function () {
101
+ let tag = TAG + " | get_block_height | ";
102
+ try {
103
+ let lastBlock = await axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' });
104
+ log.debug(tag, "lastBlock: ", lastBlock.data);
105
+ return lastBlock.data.block.header.height;
106
+ }
107
+ catch (e) {
108
+ log.error(tag, "e: ", e);
109
+ throw e;
110
+ }
172
111
  };
173
- var get_transaction = function (txid) {
174
- return __awaiter(this, void 0, void 0, function () {
175
- var tag, txInfo, e_3, output;
176
- return __generator(this, function (_a) {
177
- switch (_a.label) {
178
- case 0:
179
- tag = TAG + " | get_transaction | ";
180
- _a.label = 1;
181
- case 1:
182
- _a.trys.push([1, 3, , 4]);
183
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/txs/' + txid })];
184
- case 2:
185
- txInfo = _a.sent();
186
- log.debug(tag, "txInfo: ", txInfo.data);
187
- return [2 /*return*/, txInfo.data];
188
- case 3:
189
- e_3 = _a.sent();
190
- // log.error(tag,e.response.data)
191
- // log.error(tag,e.response.data.error)
192
- if (e_3.response.status === 404) {
193
- output = {};
194
- output.success = false;
195
- output.error = e_3.response.data.error;
196
- return [2 /*return*/, output];
197
- }
198
- else {
199
- throw Error(e_3);
200
- }
201
- return [3 /*break*/, 4];
202
- case 4: return [2 /*return*/];
203
- }
204
- });
205
- });
112
+ let get_transaction = async function (txid) {
113
+ let tag = TAG + " | get_transaction | ";
114
+ try {
115
+ let txInfo = await axios({ method: 'GET', url: URL_THORNODE + '/txs/' + txid });
116
+ log.debug(tag, "txInfo: ", txInfo.data);
117
+ return txInfo.data;
118
+ }
119
+ catch (e) {
120
+ // log.error(tag,e.response.data)
121
+ // log.error(tag,e.response.data.error)
122
+ if (e.response.status === 404) {
123
+ let output = {};
124
+ output.success = false;
125
+ output.error = e.response.data.error;
126
+ return output;
127
+ }
128
+ else {
129
+ throw Error(e);
130
+ }
131
+ }
206
132
  };
207
- var broadcast_transaction = function (tx) {
208
- return __awaiter(this, void 0, void 0, function () {
209
- var tag, output, payload, urlRemote, result2, e_4, e_5;
210
- return __generator(this, function (_a) {
211
- switch (_a.label) {
212
- case 0:
213
- tag = TAG + " | broadcast_transaction | ";
214
- output = {};
215
- _a.label = 1;
216
- case 1:
217
- _a.trys.push([1, 6, , 7]);
218
- log.debug(tag, "CHECKPOINT 1");
219
- output.success = false;
220
- _a.label = 2;
221
- case 2:
222
- _a.trys.push([2, 4, , 5]);
223
- payload = {
224
- // "tx_bytes": btoa(tx),
225
- // "tx_bytes":broadcastTx,
226
- "tx_bytes": tx,
227
- "mode": "BROADCAST_MODE_SYNC"
228
- };
229
- urlRemote = URL_THORNODE + '/cosmos/tx/v1beta1/txs';
230
- // let urlRemote = URL_GAIAD+ '/txs'
231
- log.info(tag, "urlRemote: ", urlRemote);
232
- return [4 /*yield*/, axios({
233
- url: urlRemote,
234
- headers: {
235
- 'api-key': process.env['NOW_NODES_API'],
236
- 'Content-Type': 'application/json'
237
- },
238
- method: 'POST',
239
- data: payload,
240
- })];
241
- case 3:
242
- result2 = _a.sent();
243
- log.info(tag, '** Broadcast ** REMOTE: result: ', result2.data);
244
- log.info(tag, '** Broadcast ** REMOTE: result: ', JSON.stringify(result2.data));
245
- if (result2.data.txhash)
246
- output.txid = result2.data.txhash;
247
- return [3 /*break*/, 5];
248
- case 4:
249
- e_4 = _a.sent();
250
- //log.error(tag,"failed second broadcast e: ",e.response)
251
- log.error(tag, e_4);
252
- log.error(tag, e_4.response);
253
- log.error(tag, e_4.response.data);
254
- log.error(tag, e_4.response.data.error);
255
- log.error(tag, e_4.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
256
- //throw e
257
- output.success = false;
258
- output.error = e_4.response.data.error;
259
- return [3 /*break*/, 5];
260
- case 5: return [2 /*return*/, output];
261
- case 6:
262
- e_5 = _a.sent();
263
- console.error(tag, "throw error: ", e_5);
264
- return [2 /*return*/, output];
265
- case 7: return [2 /*return*/];
133
+ let broadcast_transaction = async function (tx) {
134
+ let tag = TAG + " | broadcast_transaction | ";
135
+ let output = {};
136
+ try {
137
+ log.debug(tag, "CHECKPOINT 1");
138
+ output.success = false;
139
+ try {
140
+ // let payload = {
141
+ // // "tx_bytes": btoa(tx),
142
+ // // "tx_bytes":broadcastTx,
143
+ // "tx_bytes":tx,
144
+ // "mode": "BROADCAST_MODE_SYNC"
145
+ // }
146
+ //
147
+ // let urlRemote = URL_THORNODE+ '/cosmos/tx/v1beta1/txs'
148
+ // // let urlRemote = URL_GAIAD+ '/txs'
149
+ // log.debug(tag,"urlRemote: ",urlRemote)
150
+ // let result2 = await axios({
151
+ // url: urlRemote,
152
+ // headers: {
153
+ // 'api-key': process.env['NOW_NODES_API'],
154
+ // 'Content-Type': 'application/json'
155
+ // },
156
+ // method: 'POST',
157
+ // data: payload,
158
+ // })
159
+ // log.debug(tag,'** Broadcast ** REMOTE: result: ', result2.data)
160
+ // log.debug(tag,'** Broadcast ** REMOTE: result: ', JSON.stringify(result2.data))
161
+ // if(result2.data.txhash) output.txid = result2.data.txhash
162
+ let payload = {
163
+ // "tx_bytes": btoa(tx),
164
+ // "tx_bytes":broadcastTx,
165
+ "tx_bytes": tx,
166
+ "mode": "BROADCAST_MODE_SYNC"
167
+ };
168
+ let urlRemote = URL_THORNODE + '/cosmos/tx/v1beta1/txs';
169
+ // let urlRemote = URL_GAIAD+ '/txs'
170
+ log.info(tag, "urlRemote: ", urlRemote);
171
+ let result2 = await axios({
172
+ url: urlRemote,
173
+ headers: {
174
+ 'api-key': process.env['NOW_NODES_API'],
175
+ 'Content-Type': 'application/json'
176
+ },
177
+ method: 'POST',
178
+ data: payload,
179
+ });
180
+ log.info(tag, '** Broadcast ** REMOTE: result: ', result2.data);
181
+ log.info(tag, '** Broadcast ** REMOTE: result: ', JSON.stringify(result2.data));
182
+ if (result2.data.txhash)
183
+ output.txid = result2.data.txhash;
184
+ //tx_response
185
+ if (result2.data.tx_response.txhash)
186
+ output.txid = result2.data.tx_response.txhash;
187
+ if (result2.data.tx_response.raw_log && result2.data.tx_response.raw_log !== '[]') {
188
+ let logSend = result2.data.tx_response.raw_log;
189
+ log.debug(tag, "logSend: ", logSend);
190
+ output.success = false;
191
+ output.error = logSend;
266
192
  }
267
- });
268
- });
193
+ else {
194
+ output.success = true;
195
+ }
196
+ //push to seed
197
+ // let urlRemote = URL_THORNODE+ '/cosmos/tx/v1beta1/txs'
198
+ // log.debug(tag,"urlRemote: ",urlRemote)
199
+ // let result2 = await axios({
200
+ // url: urlRemote,
201
+ // method: 'POST',
202
+ // data: tx,
203
+ // })
204
+ // log.debug(tag,'** Broadcast ** REMOTE: result: ', result2.data)
205
+ // if(result2 && result2.data && result2.data.txhash) output.txid = result2.data.txhash
206
+ //
207
+ // //verify success
208
+ // if(result2.data.raw_log && result2.data.raw_log !== '[]'){
209
+ // let logSend = result2.data.raw_log
210
+ // log.debug(tag,"logSend: ",logSend)
211
+ // output.success = false
212
+ // output.error = logSend
213
+ // } else {
214
+ // output.success = true
215
+ // }
216
+ // output.height = result2.height
217
+ // output.gas_wanted = result2.gas_wanted
218
+ // output.gas_used = result2.gas_used
219
+ // output.raw = result2.data
220
+ }
221
+ catch (e) {
222
+ //log.error(tag,"failed second broadcast e: ",e.response)
223
+ log.error(tag, e);
224
+ log.error(tag, e.response);
225
+ log.error(tag, e.response.data);
226
+ log.error(tag, e.response.data.error);
227
+ log.error(tag, e.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
228
+ //throw e
229
+ output.success = false;
230
+ output.error = e.response.data.error;
231
+ }
232
+ return output;
233
+ }
234
+ catch (e) {
235
+ console.error(tag, "throw error: ", e);
236
+ return output;
237
+ }
269
238
  };
270
- var get_account_info = function (address) {
271
- return __awaiter(this, void 0, void 0, function () {
272
- var tag, txInfo, e_6;
273
- return __generator(this, function (_a) {
274
- switch (_a.label) {
275
- case 0:
276
- tag = TAG + " | get_account_info | ";
277
- _a.label = 1;
278
- case 1:
279
- _a.trys.push([1, 3, , 4]);
280
- //
281
- console.log("URL ", URL_THORNODE + '/auth/accounts/' + address);
282
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/auth/accounts/' + address })];
283
- case 2:
284
- txInfo = _a.sent();
285
- log.debug(tag, "txInfo: ", txInfo.data);
286
- return [2 /*return*/, txInfo.data];
287
- case 3:
288
- e_6 = _a.sent();
289
- log.error(tag, "e: ", e_6);
290
- throw e_6;
291
- case 4: return [2 /*return*/];
239
+ let get_account_info = async function (address) {
240
+ let tag = TAG + " | get_account_info | ";
241
+ try {
242
+ // Use the cosmos bank endpoint instead of auth/accounts
243
+ console.log("URL ", URL_THORNODE + '/cosmos/bank/v1beta1/balances/' + address);
244
+ let balanceInfo = await axios({ method: 'GET', url: URL_THORNODE + '/cosmos/bank/v1beta1/balances/' + address });
245
+ log.debug(tag, "balanceInfo: ", balanceInfo.data);
246
+ // Format response to match expected structure
247
+ let accountData = {
248
+ account: {
249
+ address: address,
250
+ balances: balanceInfo.data.balances || []
292
251
  }
293
- });
294
- });
252
+ };
253
+ return accountData;
254
+ }
255
+ catch (e) {
256
+ log.error(tag, "e: ", e);
257
+ throw e;
258
+ }
295
259
  };
296
- var normalize_tx = function (tx, address) {
297
- var tag = TAG + " | normalize_tx | ";
260
+ let normalize_tx = function (tx, address) {
261
+ let tag = TAG + " | normalize_tx | ";
298
262
  try {
299
- var output = {};
300
- var sender = void 0;
301
- var receiver = void 0;
302
- var memo = void 0;
303
- var amount = void 0;
304
- var rawlog = JSON.parse(tx.raw_log);
263
+ let output = {};
264
+ let sender;
265
+ let receiver;
266
+ let memo;
267
+ let amount;
268
+ let rawlog = JSON.parse(tx.raw_log);
305
269
  rawlog = rawlog;
306
270
  //log.debug("rawlog: ",rawlog)
307
271
  //txTypes
308
- var txTypes = [
272
+ let txTypes = [
309
273
  'send',
310
274
  'receive',
311
275
  'governence',
312
276
  'swap',
313
277
  'other'
314
278
  ];
315
- for (var i = 0; i < rawlog.length; i++) {
316
- var txEvents = rawlog[i];
279
+ for (let i = 0; i < rawlog.length; i++) {
280
+ let txEvents = rawlog[i];
317
281
  //log.debug(tag,"txEvents: ",txEvents)
318
282
  txEvents = txEvents.events;
319
- for (var j = 0; j < txEvents.length; j++) {
320
- var event_1 = txEvents[j];
283
+ for (let j = 0; j < txEvents.length; j++) {
284
+ let event = txEvents[j];
321
285
  //
322
286
  //log.debug(tag,"event: ",event)
323
287
  //log.debug(tag,"attributes: ",prettyjson.render(event.attributes))
324
288
  //detect event type
325
- log.debug(tag, "type: ", event_1.type);
326
- switch (event_1.type) {
289
+ log.debug(tag, "type: ", event.type);
290
+ switch (event.type) {
327
291
  case 'message':
328
292
  // ignore
329
293
  break;
330
294
  case 'transfer':
331
- log.debug(tag, "attributes: ", event_1.attributes);
332
- for (var k = 0; k < event_1.attributes.length; k++) {
333
- var attribute = event_1.attributes[k];
295
+ log.debug(tag, "attributes: ", event.attributes);
296
+ for (let k = 0; k < event.attributes.length; k++) {
297
+ let attribute = event.attributes[k];
334
298
  if (attribute.key === 'recipient') {
335
299
  receiver = attribute.value;
336
300
  output.receiver = receiver;
@@ -363,143 +327,106 @@ var normalize_tx = function (tx, address) {
363
327
  throw e;
364
328
  }
365
329
  };
366
- var get_txs_by_address = function (address) {
367
- return __awaiter(this, void 0, void 0, function () {
368
- var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx, e_7;
369
- return __generator(this, function (_a) {
370
- switch (_a.label) {
371
- case 0:
372
- tag = TAG + " | get_txs_by_address | ";
373
- _a.label = 1;
374
- case 1:
375
- _a.trys.push([1, 4, , 5]);
376
- output = [];
377
- url = URL_THORNODE + '/txs?message.sender=' + address;
378
- log.debug(tag, "url: ", url);
379
- return [4 /*yield*/, axios({
380
- url: url,
381
- method: 'GET'
382
- })];
383
- case 2:
384
- resultSends = _a.sent();
385
- sends = resultSends.data;
386
- log.debug('sends: ', sends);
387
- if (!sends.txs)
388
- sends.txs = [];
389
- // TODO//pagnation
390
- for (i = 0; i < (sends === null || sends === void 0 ? void 0 : sends.txs.length); i++) {
391
- tx = sends.txs[i];
392
- //pretty json
393
- //normalize
394
- tx = normalize_tx(tx, address);
395
- output.push(tx);
396
- }
397
- //receives
398
- url = URL_THORNODE + '/txs?transfer.recipient=' + address;
399
- console.log("URL_THORNODE: ", url);
400
- return [4 /*yield*/, axios({
401
- url: url,
402
- method: 'GET'
403
- })];
404
- case 3:
405
- resultRecieves = _a.sent();
406
- receives = resultRecieves.data;
407
- if (!receives.txs)
408
- receives.txs = [];
409
- log.debug('receives: ', receives);
410
- for (i = 0; i < (receives === null || receives === void 0 ? void 0 : receives.txs.length); i++) {
411
- tx = receives.txs[i];
412
- //normalize
413
- tx = normalize_tx(tx, address);
414
- output.push(tx);
415
- }
416
- return [2 /*return*/, output];
417
- case 4:
418
- e_7 = _a.sent();
419
- log.error(tag, "e: ", e_7);
420
- throw e_7;
421
- case 5: return [2 /*return*/];
422
- }
330
+ let get_txs_by_address = async function (address) {
331
+ let tag = TAG + " | get_txs_by_address | ";
332
+ try {
333
+ let output = [];
334
+ //sends
335
+ let url = URL_THORNODE + '/txs?message.sender=' + address;
336
+ log.debug(tag, "url: ", url);
337
+ let resultSends = await axios({
338
+ url: url,
339
+ method: 'GET'
423
340
  });
424
- });
341
+ let sends = resultSends.data;
342
+ log.debug('sends: ', sends);
343
+ if (!sends.txs)
344
+ sends.txs = [];
345
+ // TODO//pagnation
346
+ for (let i = 0; i < sends?.txs.length; i++) {
347
+ let tx = sends.txs[i];
348
+ //pretty json
349
+ //normalize
350
+ tx = normalize_tx(tx, address);
351
+ output.push(tx);
352
+ }
353
+ //receives
354
+ url = URL_THORNODE + '/txs?transfer.recipient=' + address;
355
+ console.log("URL_THORNODE: ", url);
356
+ let resultRecieves = await axios({
357
+ url: url,
358
+ method: 'GET'
359
+ });
360
+ let receives = resultRecieves.data;
361
+ if (!receives.txs)
362
+ receives.txs = [];
363
+ log.debug('receives: ', receives);
364
+ for (let i = 0; i < receives?.txs.length; i++) {
365
+ let tx = receives.txs[i];
366
+ //normalize
367
+ tx = normalize_tx(tx, address);
368
+ output.push(tx);
369
+ }
370
+ return output;
371
+ }
372
+ catch (e) {
373
+ log.error(tag, "e: ", e);
374
+ throw e;
375
+ }
425
376
  };
426
- var get_balance = function (address) {
427
- var _a;
428
- return __awaiter(this, void 0, void 0, function () {
429
- var tag, output, accountInfo, i, entry, e_8, e_9;
430
- return __generator(this, function (_b) {
431
- switch (_b.label) {
432
- case 0:
433
- tag = TAG + " | get_balance | ";
434
- _b.label = 1;
435
- case 1:
436
- _b.trys.push([1, 6, , 7]);
437
- output = 0;
438
- _b.label = 2;
439
- case 2:
440
- _b.trys.push([2, 4, , 5]);
441
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/bank/balances/' + address })];
442
- case 3:
443
- accountInfo = _b.sent();
444
- log.debug(tag, "accountInfo: ", accountInfo.data);
445
- //
446
- if ((_a = accountInfo.data) === null || _a === void 0 ? void 0 : _a.result) {
447
- for (i = 0; i < accountInfo.data.result.length; i++) {
448
- entry = accountInfo.data.result[i];
449
- if (entry.denom === 'rune') {
450
- output = entry.amount;
451
- }
452
- }
377
+ let get_balance = async function (address) {
378
+ let tag = TAG + " | get_balance | ";
379
+ try {
380
+ let output = 0;
381
+ try {
382
+ let accountInfo = await axios({ method: 'GET', url: URL_THORNODE + '/cosmos/bank/v1beta1/balances/' + address });
383
+ log.debug(tag, "accountInfo: ", accountInfo.data);
384
+ //
385
+ if (accountInfo.data?.balances) {
386
+ for (let i = 0; i < accountInfo.data.balances.length; i++) {
387
+ let entry = accountInfo.data.balances[i];
388
+ if (entry.denom === 'rune') {
389
+ output = entry.amount;
453
390
  }
454
- output = output / BASE_THOR;
455
- return [3 /*break*/, 5];
456
- case 4:
457
- e_8 = _b.sent();
458
- return [3 /*break*/, 5];
459
- case 5: return [2 /*return*/, output];
460
- case 6:
461
- e_9 = _b.sent();
462
- log.error(tag, "e: ", e_9);
463
- throw e_9;
464
- case 7: return [2 /*return*/];
391
+ }
465
392
  }
466
- });
467
- });
393
+ output = output / BASE_THOR;
394
+ }
395
+ catch (e) {
396
+ //TODO stupid node 404's on new addresses!
397
+ //if !404
398
+ //really thow
399
+ }
400
+ return output;
401
+ }
402
+ catch (e) {
403
+ log.error(tag, "e: ", e);
404
+ throw e;
405
+ }
468
406
  };
469
- var get_node_info_verbose = function () {
470
- return __awaiter(this, void 0, void 0, function () {
471
- var tag, output, syncInfo, nodeInfo, lastBlock, e_10;
472
- return __generator(this, function (_a) {
473
- switch (_a.label) {
474
- case 0:
475
- tag = TAG + " | get_node_info | ";
476
- _a.label = 1;
477
- case 1:
478
- _a.trys.push([1, 5, , 6]);
479
- output = {};
480
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/syncing' })];
481
- case 2:
482
- syncInfo = _a.sent();
483
- log.debug(tag, "syncInfo: ", syncInfo.data);
484
- output.isSyncing = syncInfo.data;
485
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/node_info' })];
486
- case 3:
487
- nodeInfo = _a.sent();
488
- log.debug(tag, "nodeInfo: ", nodeInfo.data);
489
- output = nodeInfo.data;
490
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
491
- case 4:
492
- lastBlock = _a.sent();
493
- log.debug(tag, "lastBlock: ", lastBlock.data);
494
- //let height
495
- output.height = lastBlock.data.block.header.height;
496
- return [2 /*return*/, output];
497
- case 5:
498
- e_10 = _a.sent();
499
- log.error(tag, "e: ", e_10);
500
- throw e_10;
501
- case 6: return [2 /*return*/];
502
- }
503
- });
504
- });
407
+ let get_node_info_verbose = async function () {
408
+ let tag = TAG + " | get_node_info | ";
409
+ try {
410
+ let output = {};
411
+ //get syncing status
412
+ let syncInfo = await axios({ method: 'GET', url: URL_THORNODE + '/syncing' });
413
+ log.debug(tag, "syncInfo: ", syncInfo.data);
414
+ output.isSyncing = syncInfo.data;
415
+ //gaiad abci_info
416
+ let nodeInfo = await axios({ method: 'GET', url: URL_THORNODE + '/node_info' });
417
+ log.debug(tag, "nodeInfo: ", nodeInfo.data);
418
+ output = nodeInfo.data;
419
+ // let network = await axios({method:'GET',url: URL_THORNODE+'/network'})
420
+ // log.debug(tag,"nodeInfo: ",network.data)
421
+ // output.network = network.data
422
+ let lastBlock = await axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' });
423
+ log.debug(tag, "lastBlock: ", lastBlock.data);
424
+ //let height
425
+ output.height = lastBlock.data.block.header.height;
426
+ return output;
427
+ }
428
+ catch (e) {
429
+ log.error(tag, "e: ", e);
430
+ throw e;
431
+ }
505
432
  };