@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.d.ts +6 -1
- package/lib/index.js +292 -365
- package/lib/types.d.ts +21 -0
- package/lib/types.js +18 -0
- package/package.json +8 -7
- package/tsconfig.json +19 -8
- package/LICENSE +0 -674
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
|
-
|
|
55
|
-
|
|
17
|
+
const TAG = " | thorchain-api | ";
|
|
18
|
+
const prettyjson = require('prettyjson');
|
|
56
19
|
require("dotenv").config({ path: '../../../.env' });
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
27
|
+
const axiosRetry = require('axios-retry');
|
|
65
28
|
axiosRetry(axios, {
|
|
66
29
|
retries: 3, // number of retries
|
|
67
|
-
retryDelay:
|
|
68
|
-
console.log(
|
|
30
|
+
retryDelay: (retryCount) => {
|
|
31
|
+
console.log(`retry attempt: ${retryCount}`);
|
|
69
32
|
return retryCount * 2000; // time interval between retries
|
|
70
33
|
},
|
|
71
|
-
retryCondition:
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
297
|
-
|
|
260
|
+
let normalize_tx = function (tx, address) {
|
|
261
|
+
let tag = TAG + " | normalize_tx | ";
|
|
298
262
|
try {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
272
|
+
let txTypes = [
|
|
309
273
|
'send',
|
|
310
274
|
'receive',
|
|
311
275
|
'governence',
|
|
312
276
|
'swap',
|
|
313
277
|
'other'
|
|
314
278
|
];
|
|
315
|
-
for (
|
|
316
|
-
|
|
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 (
|
|
320
|
-
|
|
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: ",
|
|
326
|
-
switch (
|
|
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: ",
|
|
332
|
-
for (
|
|
333
|
-
|
|
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
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
|
|
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
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
};
|