@pioneer-platform/thor-network 8.3.4 → 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.d.ts CHANGED
@@ -14,7 +14,12 @@ declare let get_last_block: () => Promise<any>;
14
14
  declare let get_block_height: () => Promise<any>;
15
15
  declare let get_transaction: (txid: string) => Promise<any>;
16
16
  declare let broadcast_transaction: (tx: string) => Promise<any>;
17
- declare let get_account_info: (address: string) => Promise<any>;
17
+ declare let get_account_info: (address: string) => Promise<{
18
+ account: {
19
+ address: string;
20
+ balances: any;
21
+ };
22
+ }>;
18
23
  declare let normalize_tx: (tx: any, address?: string) => any;
19
24
  declare let get_txs_by_address: (address: string) => Promise<any>;
20
25
  declare let get_balance: (address: string) => Promise<number>;
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,227 +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, logSend, 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
- //tx_response
248
- if (result2.data.tx_response.txhash)
249
- output.txid = result2.data.tx_response.txhash;
250
- if (result2.data.tx_response.raw_log && result2.data.tx_response.raw_log !== '[]') {
251
- logSend = result2.data.tx_response.raw_log;
252
- log.debug(tag, "logSend: ", logSend);
253
- output.success = false;
254
- output.error = logSend;
255
- }
256
- else {
257
- output.success = true;
258
- }
259
- return [3 /*break*/, 5];
260
- case 4:
261
- e_4 = _a.sent();
262
- //log.error(tag,"failed second broadcast e: ",e.response)
263
- log.error(tag, e_4);
264
- log.error(tag, e_4.response);
265
- log.error(tag, e_4.response.data);
266
- log.error(tag, e_4.response.data.error);
267
- log.error(tag, e_4.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
268
- //throw e
269
- output.success = false;
270
- output.error = e_4.response.data.error;
271
- return [3 /*break*/, 5];
272
- case 5: return [2 /*return*/, output];
273
- case 6:
274
- e_5 = _a.sent();
275
- console.error(tag, "throw error: ", e_5);
276
- return [2 /*return*/, output];
277
- 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;
278
192
  }
279
- });
280
- });
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
+ }
281
238
  };
282
- var get_account_info = function (address) {
283
- return __awaiter(this, void 0, void 0, function () {
284
- var tag, txInfo, e_6;
285
- return __generator(this, function (_a) {
286
- switch (_a.label) {
287
- case 0:
288
- tag = TAG + " | get_account_info | ";
289
- _a.label = 1;
290
- case 1:
291
- _a.trys.push([1, 3, , 4]);
292
- //
293
- console.log("URL ", URL_THORNODE + '/auth/accounts/' + address);
294
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/auth/accounts/' + address })];
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: ", e_6);
302
- throw e_6;
303
- 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 || []
304
251
  }
305
- });
306
- });
252
+ };
253
+ return accountData;
254
+ }
255
+ catch (e) {
256
+ log.error(tag, "e: ", e);
257
+ throw e;
258
+ }
307
259
  };
308
- var normalize_tx = function (tx, address) {
309
- var tag = TAG + " | normalize_tx | ";
260
+ let normalize_tx = function (tx, address) {
261
+ let tag = TAG + " | normalize_tx | ";
310
262
  try {
311
- var output = {};
312
- var sender = void 0;
313
- var receiver = void 0;
314
- var memo = void 0;
315
- var amount = void 0;
316
- 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);
317
269
  rawlog = rawlog;
318
270
  //log.debug("rawlog: ",rawlog)
319
271
  //txTypes
320
- var txTypes = [
272
+ let txTypes = [
321
273
  'send',
322
274
  'receive',
323
275
  'governence',
324
276
  'swap',
325
277
  'other'
326
278
  ];
327
- for (var i = 0; i < rawlog.length; i++) {
328
- var txEvents = rawlog[i];
279
+ for (let i = 0; i < rawlog.length; i++) {
280
+ let txEvents = rawlog[i];
329
281
  //log.debug(tag,"txEvents: ",txEvents)
330
282
  txEvents = txEvents.events;
331
- for (var j = 0; j < txEvents.length; j++) {
332
- var event_1 = txEvents[j];
283
+ for (let j = 0; j < txEvents.length; j++) {
284
+ let event = txEvents[j];
333
285
  //
334
286
  //log.debug(tag,"event: ",event)
335
287
  //log.debug(tag,"attributes: ",prettyjson.render(event.attributes))
336
288
  //detect event type
337
- log.debug(tag, "type: ", event_1.type);
338
- switch (event_1.type) {
289
+ log.debug(tag, "type: ", event.type);
290
+ switch (event.type) {
339
291
  case 'message':
340
292
  // ignore
341
293
  break;
342
294
  case 'transfer':
343
- log.debug(tag, "attributes: ", event_1.attributes);
344
- for (var k = 0; k < event_1.attributes.length; k++) {
345
- 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];
346
298
  if (attribute.key === 'recipient') {
347
299
  receiver = attribute.value;
348
300
  output.receiver = receiver;
@@ -375,143 +327,106 @@ var normalize_tx = function (tx, address) {
375
327
  throw e;
376
328
  }
377
329
  };
378
- var get_txs_by_address = function (address) {
379
- return __awaiter(this, void 0, void 0, function () {
380
- var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx, e_7;
381
- return __generator(this, function (_a) {
382
- switch (_a.label) {
383
- case 0:
384
- tag = TAG + " | get_txs_by_address | ";
385
- _a.label = 1;
386
- case 1:
387
- _a.trys.push([1, 4, , 5]);
388
- output = [];
389
- url = URL_THORNODE + '/txs?message.sender=' + address;
390
- log.debug(tag, "url: ", url);
391
- return [4 /*yield*/, axios({
392
- url: url,
393
- method: 'GET'
394
- })];
395
- case 2:
396
- resultSends = _a.sent();
397
- sends = resultSends.data;
398
- log.debug('sends: ', sends);
399
- if (!sends.txs)
400
- sends.txs = [];
401
- // TODO//pagnation
402
- for (i = 0; i < (sends === null || sends === void 0 ? void 0 : sends.txs.length); i++) {
403
- tx = sends.txs[i];
404
- //pretty json
405
- //normalize
406
- tx = normalize_tx(tx, address);
407
- output.push(tx);
408
- }
409
- //receives
410
- url = URL_THORNODE + '/txs?transfer.recipient=' + address;
411
- console.log("URL_THORNODE: ", url);
412
- return [4 /*yield*/, axios({
413
- url: url,
414
- method: 'GET'
415
- })];
416
- case 3:
417
- resultRecieves = _a.sent();
418
- receives = resultRecieves.data;
419
- if (!receives.txs)
420
- receives.txs = [];
421
- log.debug('receives: ', receives);
422
- for (i = 0; i < (receives === null || receives === void 0 ? void 0 : receives.txs.length); i++) {
423
- tx = receives.txs[i];
424
- //normalize
425
- tx = normalize_tx(tx, address);
426
- output.push(tx);
427
- }
428
- return [2 /*return*/, output];
429
- case 4:
430
- e_7 = _a.sent();
431
- log.error(tag, "e: ", e_7);
432
- throw e_7;
433
- case 5: return [2 /*return*/];
434
- }
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'
435
340
  });
436
- });
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
+ }
437
376
  };
438
- var get_balance = function (address) {
439
- var _a;
440
- return __awaiter(this, void 0, void 0, function () {
441
- var tag, output, accountInfo, i, entry, e_8, e_9;
442
- return __generator(this, function (_b) {
443
- switch (_b.label) {
444
- case 0:
445
- tag = TAG + " | get_balance | ";
446
- _b.label = 1;
447
- case 1:
448
- _b.trys.push([1, 6, , 7]);
449
- output = 0;
450
- _b.label = 2;
451
- case 2:
452
- _b.trys.push([2, 4, , 5]);
453
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/bank/balances/' + address })];
454
- case 3:
455
- accountInfo = _b.sent();
456
- log.debug(tag, "accountInfo: ", accountInfo.data);
457
- //
458
- if ((_a = accountInfo.data) === null || _a === void 0 ? void 0 : _a.result) {
459
- for (i = 0; i < accountInfo.data.result.length; i++) {
460
- entry = accountInfo.data.result[i];
461
- if (entry.denom === 'rune') {
462
- output = entry.amount;
463
- }
464
- }
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;
465
390
  }
466
- output = output / BASE_THOR;
467
- return [3 /*break*/, 5];
468
- case 4:
469
- e_8 = _b.sent();
470
- return [3 /*break*/, 5];
471
- case 5: return [2 /*return*/, output];
472
- case 6:
473
- e_9 = _b.sent();
474
- log.error(tag, "e: ", e_9);
475
- throw e_9;
476
- case 7: return [2 /*return*/];
391
+ }
477
392
  }
478
- });
479
- });
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
+ }
480
406
  };
481
- var get_node_info_verbose = function () {
482
- return __awaiter(this, void 0, void 0, function () {
483
- var tag, output, syncInfo, nodeInfo, lastBlock, e_10;
484
- return __generator(this, function (_a) {
485
- switch (_a.label) {
486
- case 0:
487
- tag = TAG + " | get_node_info | ";
488
- _a.label = 1;
489
- case 1:
490
- _a.trys.push([1, 5, , 6]);
491
- output = {};
492
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/syncing' })];
493
- case 2:
494
- syncInfo = _a.sent();
495
- log.debug(tag, "syncInfo: ", syncInfo.data);
496
- output.isSyncing = syncInfo.data;
497
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/node_info' })];
498
- case 3:
499
- nodeInfo = _a.sent();
500
- log.debug(tag, "nodeInfo: ", nodeInfo.data);
501
- output = nodeInfo.data;
502
- return [4 /*yield*/, axios({ method: 'GET', url: URL_THORNODE + '/blocks/latest' })];
503
- case 4:
504
- lastBlock = _a.sent();
505
- log.debug(tag, "lastBlock: ", lastBlock.data);
506
- //let height
507
- output.height = lastBlock.data.block.header.height;
508
- return [2 /*return*/, output];
509
- case 5:
510
- e_10 = _a.sent();
511
- log.error(tag, "e: ", e_10);
512
- throw e_10;
513
- case 6: return [2 /*return*/];
514
- }
515
- });
516
- });
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
+ }
517
432
  };
package/lib/types.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export type Chain = string;
2
+ export declare enum MemoType {
3
+ SWAP = "SWAP",
4
+ DEPOSIT = "DEPOSIT",
5
+ WITHDRAW = "WITHDRAW",
6
+ BOND = "BOND",
7
+ UNBOND = "UNBOND",
8
+ LEAVE = "LEAVE",
9
+ OUTBOUND = "OUTBOUND",
10
+ REFUND = "REFUND",
11
+ ADD = "ADD",
12
+ MIGRATE = "MIGRATE",
13
+ THORNAME = "THORNAME"
14
+ }
15
+ export type BaseDecimal = string | number;
16
+ export type Asset = {
17
+ chain: Chain;
18
+ symbol: string;
19
+ ticker: string;
20
+ synth?: boolean;
21
+ };
package/lib/types.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ // Mock types for @coinmasters/types
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MemoType = void 0;
5
+ var MemoType;
6
+ (function (MemoType) {
7
+ MemoType["SWAP"] = "SWAP";
8
+ MemoType["DEPOSIT"] = "DEPOSIT";
9
+ MemoType["WITHDRAW"] = "WITHDRAW";
10
+ MemoType["BOND"] = "BOND";
11
+ MemoType["UNBOND"] = "UNBOND";
12
+ MemoType["LEAVE"] = "LEAVE";
13
+ MemoType["OUTBOUND"] = "OUTBOUND";
14
+ MemoType["REFUND"] = "REFUND";
15
+ MemoType["ADD"] = "ADD";
16
+ MemoType["MIGRATE"] = "MIGRATE";
17
+ MemoType["THORNAME"] = "THORNAME";
18
+ })(MemoType || (exports.MemoType = MemoType = {}));
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@pioneer-platform/thor-network",
3
- "version": "8.3.4",
3
+ "version": "8.3.5",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
7
- "create": "npm run build && npm run test",
7
+ "create": "pnpm run build && pnpm run test",
8
8
  "build": "tsc -p .",
9
- "test": "npm run build && node __tests__/test-module.js",
10
- "prepublish": "rm -R lib && npm run build",
11
- "refresh": "rm -rf ./node_modules ./package-lock.json && npm install"
9
+ "test": "pnpm run build && node __tests__/test-module.js",
10
+ "prepublish": "rm -R lib && pnpm run build",
11
+ "refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
12
12
  },
13
13
  "dependencies": {
14
14
  "@pioneer-platform/loggerdog": "^8.3.1",
15
+ "axios": "^1.9.0",
15
16
  "axios-retry": "^3.3.1",
16
17
  "bech32": "^1.1.4",
17
18
  "bip32": "^2.0.5",
@@ -25,7 +26,7 @@
25
26
  "prettyjson": "^1.2.1",
26
27
  "secp256k1": "^3.8.0",
27
28
  "ts-node": "^8.10.2",
28
- "typescript": "^5.0.2"
29
+ "typescript": "^5.0.4"
29
30
  },
30
31
  "gitHead": "aeae28273014ab69b42f22abec159c6693a56c40"
31
32
  }
package/tsconfig.json CHANGED
@@ -1,13 +1,24 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es5",
3
+ "target": "es2020",
4
4
  "module": "commonjs",
5
- "lib": ["es6", "es2015", "dom"],
5
+ "lib": ["es2020", "dom"],
6
6
  "declaration": true,
7
- "outDir": "lib",
8
- "rootDir": "src",
9
- "strict": true,
10
- "types": ["node"],
11
- "esModuleInterop": true
12
- }
7
+ "outDir": "./lib",
8
+ "rootDir": "./src",
9
+ "strict": false,
10
+ "noImplicitAny": false,
11
+ "strictNullChecks": false,
12
+ "strictFunctionTypes": false,
13
+ "strictBindCallApply": false,
14
+ "strictPropertyInitialization": false,
15
+ "noImplicitThis": false,
16
+ "alwaysStrict": false,
17
+ "esModuleInterop": true,
18
+ "resolveJsonModule": true,
19
+ "skipLibCheck": true,
20
+ "forceConsistentCasingInFileNames": true
21
+ },
22
+ "include": ["src"],
23
+ "exclude": ["node_modules", "**/__tests__/*"]
13
24
  }