@pioneer-platform/thor-network 8.3.4 → 8.4.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/CHANGELOG.md +12 -0
- package/lib/index.d.ts +6 -1
- package/lib/index.js +292 -377
- package/lib/types.d.ts +21 -0
- package/lib/types.js +18 -0
- package/package.json +13 -12
- package/tsconfig.json +19 -8
package/CHANGELOG.md
ADDED
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<
|
|
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
|
-
|
|
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,227 +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
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
309
|
-
|
|
260
|
+
let normalize_tx = function (tx, address) {
|
|
261
|
+
let tag = TAG + " | normalize_tx | ";
|
|
310
262
|
try {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
272
|
+
let txTypes = [
|
|
321
273
|
'send',
|
|
322
274
|
'receive',
|
|
323
275
|
'governence',
|
|
324
276
|
'swap',
|
|
325
277
|
'other'
|
|
326
278
|
];
|
|
327
|
-
for (
|
|
328
|
-
|
|
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 (
|
|
332
|
-
|
|
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: ",
|
|
338
|
-
switch (
|
|
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: ",
|
|
344
|
-
for (
|
|
345
|
-
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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
|
-
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/thor-network",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"create": "npm run build && npm run test",
|
|
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"
|
|
12
|
-
},
|
|
13
6
|
"dependencies": {
|
|
14
|
-
"@pioneer-platform/loggerdog": "^8.
|
|
7
|
+
"@pioneer-platform/loggerdog": "^8.4.0",
|
|
8
|
+
"axios": "^1.9.0",
|
|
15
9
|
"axios-retry": "^3.3.1",
|
|
16
10
|
"bech32": "^1.1.4",
|
|
17
11
|
"bip32": "^2.0.5",
|
|
@@ -25,7 +19,14 @@
|
|
|
25
19
|
"prettyjson": "^1.2.1",
|
|
26
20
|
"secp256k1": "^3.8.0",
|
|
27
21
|
"ts-node": "^8.10.2",
|
|
28
|
-
"typescript": "^5.0.
|
|
22
|
+
"typescript": "^5.0.4"
|
|
29
23
|
},
|
|
30
|
-
"gitHead": "aeae28273014ab69b42f22abec159c6693a56c40"
|
|
31
|
-
|
|
24
|
+
"gitHead": "aeae28273014ab69b42f22abec159c6693a56c40",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"create": "pnpm run build && pnpm run test",
|
|
27
|
+
"build": "tsc -p .",
|
|
28
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
29
|
+
"prepublish": "rm -R lib && pnpm run build",
|
|
30
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "es2020",
|
|
4
4
|
"module": "commonjs",
|
|
5
|
-
"lib": ["
|
|
5
|
+
"lib": ["es2020", "dom"],
|
|
6
6
|
"declaration": true,
|
|
7
|
-
"outDir": "lib",
|
|
8
|
-
"rootDir": "src",
|
|
9
|
-
"strict":
|
|
10
|
-
"
|
|
11
|
-
"
|
|
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
|
}
|