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