@pioneer-platform/ripple-network 8.3.2 → 8.3.3
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 +12 -1
- package/lib/index.js +147 -325
- package/package.json +12 -20
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
declare const TAG = " | ripple-network | ";
|
|
2
|
+
declare const Axios: any;
|
|
3
|
+
declare const https: any;
|
|
4
|
+
declare const log: any;
|
|
5
|
+
declare const URL_NODE = "https://xrp.nownodes.io";
|
|
6
|
+
declare const axios: any;
|
|
7
|
+
/**********************************
|
|
8
|
+
// Implementation Functions
|
|
9
|
+
//**********************************/
|
|
10
|
+
declare let broadcast_transaction: (tx: string) => Promise<any>;
|
|
11
|
+
declare let get_account_info: (address: string) => Promise<any>;
|
|
12
|
+
declare let get_balance: (address: string) => Promise<number>;
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Ripple Network Module
|
|
4
|
+
|
|
5
|
+
Uses NowNodes API for XRP Ledger connectivity
|
|
6
|
+
https://nownodes.io/
|
|
7
|
+
|
|
8
|
+
Endpoints:
|
|
9
|
+
- Full Node: https://xrp.nownodes.io
|
|
10
|
+
- WebSocket: wss://xrp.nownodes.io/wss
|
|
11
|
+
*/
|
|
2
12
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
13
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
14
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,8 +19,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
19
|
});
|
|
10
20
|
};
|
|
11
21
|
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 =
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
24
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
25
|
function step(op) {
|
|
16
26
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -35,147 +45,97 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
46
|
}
|
|
37
47
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var prettyjson = require('prettyjson');
|
|
41
|
-
require("dotenv").config({ path: '../../../.env' });
|
|
48
|
+
var TAG = " | ripple-network | ";
|
|
49
|
+
require("dotenv").config({ path: '../../../../.env' });
|
|
42
50
|
var Axios = require('axios');
|
|
43
51
|
var https = require('https');
|
|
52
|
+
var log = require('@pioneer-platform/loggerdog')();
|
|
53
|
+
// NowNodes configuration
|
|
54
|
+
var URL_NODE = "https://xrp.nownodes.io";
|
|
55
|
+
// Create axios instance - API key will be added per request
|
|
44
56
|
var axios = Axios.create({
|
|
45
57
|
httpsAgent: new https.Agent({
|
|
46
58
|
rejectUnauthorized: false
|
|
47
|
-
})
|
|
59
|
+
}),
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/json'
|
|
62
|
+
}
|
|
48
63
|
});
|
|
49
|
-
// const axiosRetry = require('axios-retry');
|
|
50
|
-
// axiosRetry(axios, {
|
|
51
|
-
// retries: 3, // number of retries
|
|
52
|
-
// retryDelay: (retryCount: number) => {
|
|
53
|
-
// console.log(`retry attempt: ${retryCount}`);
|
|
54
|
-
// return retryCount * 2000; // time interval between retries
|
|
55
|
-
// },
|
|
56
|
-
// retryCondition: (error: { response: { status: number; }; }) => {
|
|
57
|
-
// console.error(error)
|
|
58
|
-
// // if retry condition is not specified, by default idempotent requests are retried
|
|
59
|
-
// return error.response.status === 503;
|
|
60
|
-
// },
|
|
61
|
-
// });
|
|
62
|
-
var xrpl = require("xrpl");
|
|
63
|
-
var log = require('@pioneer-platform/loggerdog')();
|
|
64
|
-
var URL_THORNODE = process.env['URL_THORNODE'] || 'https://thornode.ninerealms.com';
|
|
65
|
-
//let URL_MIDGARD = process.env['URL_THORNODE'] || 'https://testnet.midgard.thorchain.info/v2'
|
|
66
|
-
var BASE_THOR = 100000000;
|
|
67
64
|
/**********************************
|
|
68
65
|
// Module
|
|
69
66
|
//**********************************/
|
|
70
|
-
var client;
|
|
71
|
-
var URL_NODE = "https://xrplcluster.com";
|
|
72
|
-
//https://s1.ripple.com:51234
|
|
73
|
-
// let URL_NODE = "https://s1.ripple.com:51234"
|
|
74
67
|
module.exports = {
|
|
75
68
|
init: function (url, settings) {
|
|
76
69
|
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
var tag, NOWNODES_API_KEY, testResult, e_1;
|
|
71
|
+
var _a;
|
|
72
|
+
return __generator(this, function (_b) {
|
|
73
|
+
switch (_b.label) {
|
|
79
74
|
case 0:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// console.log(client)
|
|
83
|
-
return [4 /*yield*/, client.connect()];
|
|
75
|
+
tag = TAG + " | init | ";
|
|
76
|
+
_b.label = 1;
|
|
84
77
|
case 1:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
_b.trys.push([1, 3, , 4]);
|
|
79
|
+
NOWNODES_API_KEY = process.env['NOW_NODES_API'];
|
|
80
|
+
if (!NOWNODES_API_KEY) {
|
|
81
|
+
throw new Error("NOW_NODES_API environment variable is required");
|
|
82
|
+
}
|
|
83
|
+
log.info(tag, "Initializing Ripple network with NowNodes...");
|
|
84
|
+
log.info(tag, "HTTP Endpoint:", URL_NODE);
|
|
85
|
+
// For now, let's skip WebSocket connection and use HTTP-only mode
|
|
86
|
+
// This is because NowNodes WebSocket might have different authentication requirements
|
|
87
|
+
log.info(tag, "Using HTTP-only mode for NowNodes compatibility");
|
|
88
|
+
return [4 /*yield*/, axios({
|
|
89
|
+
url: URL_NODE,
|
|
90
|
+
method: 'POST',
|
|
91
|
+
data: {
|
|
92
|
+
"method": "server_info",
|
|
93
|
+
"params": []
|
|
94
|
+
},
|
|
95
|
+
headers: {
|
|
96
|
+
'Content-Type': 'application/json',
|
|
97
|
+
'api-key': NOWNODES_API_KEY
|
|
98
|
+
}
|
|
99
|
+
})];
|
|
100
|
+
case 2:
|
|
101
|
+
testResult = _b.sent();
|
|
102
|
+
if (testResult.data && testResult.data.result) {
|
|
103
|
+
log.info(tag, "Successfully connected to NowNodes XRP HTTP API");
|
|
104
|
+
log.info(tag, "Server info:", ((_a = testResult.data.result.info) === null || _a === void 0 ? void 0 : _a.server_version) || "Unknown version");
|
|
105
|
+
return [2 /*return*/, true];
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error("Invalid response from NowNodes API");
|
|
109
|
+
}
|
|
110
|
+
return [3 /*break*/, 4];
|
|
111
|
+
case 3:
|
|
112
|
+
e_1 = _b.sent();
|
|
113
|
+
log.error(tag, "Failed to initialize:", e_1.message);
|
|
114
|
+
throw e_1;
|
|
115
|
+
case 4: return [2 /*return*/];
|
|
88
116
|
}
|
|
89
117
|
});
|
|
90
118
|
});
|
|
91
119
|
},
|
|
92
120
|
isOnline: function () {
|
|
93
|
-
return true;
|
|
121
|
+
return true; // HTTP-only mode - always online if initialized
|
|
94
122
|
},
|
|
95
|
-
// info:function () {
|
|
96
|
-
// return get_node_info_verbose();
|
|
97
|
-
// },
|
|
98
123
|
getBalance: function (address) {
|
|
99
124
|
return get_balance(address);
|
|
100
125
|
},
|
|
101
126
|
getAccount: function (address) {
|
|
102
127
|
return get_account_info(address);
|
|
103
128
|
},
|
|
104
|
-
// getLastBlock:function () {
|
|
105
|
-
// return get_last_block();
|
|
106
|
-
// },
|
|
107
|
-
// getBlockHeight:function () {
|
|
108
|
-
// return get_block_height();
|
|
109
|
-
// },
|
|
110
|
-
// getAccountInfo:function (address:string) {
|
|
111
|
-
// return get_account_info(address);
|
|
112
|
-
// },
|
|
113
|
-
// txs: function (address:string) {
|
|
114
|
-
// return get_txs_by_address(address);
|
|
115
|
-
// },
|
|
116
|
-
// getTransaction: function (txid:string) {
|
|
117
|
-
// return get_transaction(txid);
|
|
118
|
-
// },
|
|
119
|
-
// transaction: function (txid:string) {
|
|
120
|
-
// return get_transaction(txid);
|
|
121
|
-
// },
|
|
122
129
|
broadcast: function (tx) {
|
|
123
130
|
return broadcast_transaction(tx);
|
|
124
131
|
},
|
|
125
132
|
};
|
|
126
133
|
/**********************************
|
|
127
|
-
//
|
|
134
|
+
// Implementation Functions
|
|
128
135
|
//**********************************/
|
|
129
|
-
// let get_last_block = async function(){
|
|
130
|
-
// let tag = TAG + " | get_last_block | "
|
|
131
|
-
// try{
|
|
132
|
-
//
|
|
133
|
-
// let lastBlock = await axios({method:'GET',url: URL_THORNODE+'/blocks/latest'})
|
|
134
|
-
// log.debug(tag,"lastBlock: ",lastBlock.data)
|
|
135
|
-
//
|
|
136
|
-
// return lastBlock.data.block
|
|
137
|
-
// }catch(e){
|
|
138
|
-
// log.error(tag,"e: ",e)
|
|
139
|
-
// throw e
|
|
140
|
-
// }
|
|
141
|
-
// }
|
|
142
|
-
//
|
|
143
|
-
// let get_block_height = async function(){
|
|
144
|
-
// let tag = TAG + " | get_block_height | "
|
|
145
|
-
// try{
|
|
146
|
-
//
|
|
147
|
-
// let lastBlock = await axios({method:'GET',url: URL_THORNODE+'/blocks/latest'})
|
|
148
|
-
// log.debug(tag,"lastBlock: ",lastBlock.data)
|
|
149
|
-
//
|
|
150
|
-
// return lastBlock.data.block.header.height
|
|
151
|
-
// }catch(e){
|
|
152
|
-
// log.error(tag,"e: ",e)
|
|
153
|
-
// throw e
|
|
154
|
-
// }
|
|
155
|
-
// }
|
|
156
|
-
//
|
|
157
|
-
// let get_transaction = async function(txid:string){
|
|
158
|
-
// let tag = TAG + " | get_transaction | "
|
|
159
|
-
// try{
|
|
160
|
-
// let txInfo = await axios({method:'GET',url: URL_THORNODE+'/txs/'+txid})
|
|
161
|
-
// log.debug(tag,"txInfo: ",txInfo.data)
|
|
162
|
-
// return txInfo.data
|
|
163
|
-
// }catch(e){
|
|
164
|
-
// // log.error(tag,e.response.data)
|
|
165
|
-
// // log.error(tag,e.response.data.error)
|
|
166
|
-
// if(e.response.status === 404){
|
|
167
|
-
// let output:any = {}
|
|
168
|
-
// output.success = false
|
|
169
|
-
// output.error = e.response.data.error
|
|
170
|
-
// return output
|
|
171
|
-
// } else {
|
|
172
|
-
// throw Error(e)
|
|
173
|
-
// }
|
|
174
|
-
// }
|
|
175
|
-
// }
|
|
176
136
|
var broadcast_transaction = function (tx) {
|
|
177
137
|
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
-
var tag, output, buffer, bufString, data,
|
|
138
|
+
var tag, output, buffer, bufString, data, NOWNODES_API_KEY, result, responseData, resultObject, txJson, txid, engineResult, engineResultCode, engineResultMessage, validatedLedgerIndex, accountSequenceNext, applied, wasSuccessful, e_2;
|
|
179
139
|
return __generator(this, function (_a) {
|
|
180
140
|
switch (_a.label) {
|
|
181
141
|
case 0:
|
|
@@ -184,7 +144,7 @@ var broadcast_transaction = function (tx) {
|
|
|
184
144
|
_a.label = 1;
|
|
185
145
|
case 1:
|
|
186
146
|
_a.trys.push([1, 3, , 4]);
|
|
187
|
-
log.debug(tag, "
|
|
147
|
+
log.debug(tag, "Broadcasting transaction...");
|
|
188
148
|
buffer = Buffer.from(tx, 'base64');
|
|
189
149
|
bufString = buffer.toString('hex');
|
|
190
150
|
output.success = false;
|
|
@@ -199,18 +159,21 @@ var broadcast_transaction = function (tx) {
|
|
|
199
159
|
}
|
|
200
160
|
]
|
|
201
161
|
};
|
|
202
|
-
|
|
203
|
-
log.debug(tag, "
|
|
162
|
+
log.debug(tag, "Request URL: ", URL_NODE);
|
|
163
|
+
log.debug(tag, "Request data: ", JSON.stringify(data));
|
|
164
|
+
NOWNODES_API_KEY = process.env['NOW_NODES_API'];
|
|
204
165
|
return [4 /*yield*/, axios({
|
|
205
|
-
url:
|
|
206
|
-
headers: {},
|
|
166
|
+
url: URL_NODE,
|
|
207
167
|
method: 'POST',
|
|
208
168
|
data: data,
|
|
169
|
+
headers: {
|
|
170
|
+
'Content-Type': 'application/json',
|
|
171
|
+
'api-key': NOWNODES_API_KEY
|
|
172
|
+
}
|
|
209
173
|
})];
|
|
210
174
|
case 2:
|
|
211
175
|
result = _a.sent();
|
|
212
|
-
log.info(tag, '
|
|
213
|
-
log.info(tag, '** Broadcast ** REMOTE: result: ', JSON.stringify(result.data));
|
|
176
|
+
log.info(tag, 'Broadcast result: ', result.data);
|
|
214
177
|
responseData = result.data || {};
|
|
215
178
|
resultObject = responseData.result || {};
|
|
216
179
|
txJson = resultObject.tx_json || {};
|
|
@@ -234,9 +197,10 @@ var broadcast_transaction = function (tx) {
|
|
|
234
197
|
};
|
|
235
198
|
return [2 /*return*/, output];
|
|
236
199
|
case 3:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
200
|
+
e_2 = _a.sent();
|
|
201
|
+
log.error(tag, "Broadcast error: ", e_2);
|
|
202
|
+
output.success = false;
|
|
203
|
+
output.error = e_2.message;
|
|
240
204
|
return [2 /*return*/, output];
|
|
241
205
|
case 4: return [2 /*return*/];
|
|
242
206
|
}
|
|
@@ -245,170 +209,55 @@ var broadcast_transaction = function (tx) {
|
|
|
245
209
|
};
|
|
246
210
|
var get_account_info = function (address) {
|
|
247
211
|
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
-
var tag,
|
|
212
|
+
var tag, NOWNODES_API_KEY, response, output, e_3;
|
|
249
213
|
return __generator(this, function (_a) {
|
|
250
214
|
switch (_a.label) {
|
|
251
215
|
case 0:
|
|
252
216
|
tag = TAG + " | get_account_info | ";
|
|
253
217
|
_a.label = 1;
|
|
254
218
|
case 1:
|
|
255
|
-
_a.trys.push([1,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
219
|
+
_a.trys.push([1, 3, , 4]);
|
|
220
|
+
log.debug(tag, "Getting account info for:", address);
|
|
221
|
+
NOWNODES_API_KEY = process.env['NOW_NODES_API'];
|
|
222
|
+
return [4 /*yield*/, axios({
|
|
223
|
+
url: URL_NODE,
|
|
224
|
+
method: 'POST',
|
|
225
|
+
data: {
|
|
226
|
+
"method": "account_info",
|
|
227
|
+
"params": [{
|
|
228
|
+
"account": address,
|
|
229
|
+
"ledger_index": "validated"
|
|
230
|
+
}]
|
|
231
|
+
},
|
|
232
|
+
headers: {
|
|
233
|
+
'Content-Type': 'application/json',
|
|
234
|
+
'api-key': NOWNODES_API_KEY
|
|
235
|
+
}
|
|
236
|
+
})];
|
|
263
237
|
case 2:
|
|
264
238
|
response = _a.sent();
|
|
265
|
-
|
|
239
|
+
if (response.data && response.data.result && response.data.result.account_data) {
|
|
240
|
+
output = response.data.result.account_data;
|
|
241
|
+
output.ledger_index_current = response.data.result.ledger_current_index;
|
|
242
|
+
log.debug(tag, "Account info retrieved successfully");
|
|
243
|
+
return [2 /*return*/, output];
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
throw new Error("Invalid response from NowNodes API");
|
|
247
|
+
}
|
|
248
|
+
return [3 /*break*/, 4];
|
|
266
249
|
case 3:
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
case 4:
|
|
272
|
-
e_2 = _a.sent();
|
|
273
|
-
log.error(tag, "e: ", e_2);
|
|
274
|
-
throw e_2;
|
|
275
|
-
case 5: return [2 /*return*/];
|
|
250
|
+
e_3 = _a.sent();
|
|
251
|
+
log.error(tag, "Error getting account info: ", e_3.message);
|
|
252
|
+
throw e_3;
|
|
253
|
+
case 4: return [2 /*return*/];
|
|
276
254
|
}
|
|
277
255
|
});
|
|
278
256
|
});
|
|
279
257
|
};
|
|
280
|
-
// let normalize_tx = function(tx:any,address?:string){
|
|
281
|
-
// let tag = TAG + " | normalize_tx | "
|
|
282
|
-
// try{
|
|
283
|
-
// let output:any = {}
|
|
284
|
-
//
|
|
285
|
-
// let sender
|
|
286
|
-
// let receiver
|
|
287
|
-
// let memo
|
|
288
|
-
// let amount
|
|
289
|
-
//
|
|
290
|
-
// let rawlog = JSON.parse(tx.raw_log)
|
|
291
|
-
// rawlog = rawlog
|
|
292
|
-
// //log.debug("rawlog: ",rawlog)
|
|
293
|
-
//
|
|
294
|
-
// //txTypes
|
|
295
|
-
// let txTypes = [
|
|
296
|
-
// 'send',
|
|
297
|
-
// 'receive',
|
|
298
|
-
// 'governence',
|
|
299
|
-
// 'swap',
|
|
300
|
-
// 'other'
|
|
301
|
-
// ]
|
|
302
|
-
//
|
|
303
|
-
// for(let i = 0; i < rawlog.length; i++){
|
|
304
|
-
// let txEvents = rawlog[i]
|
|
305
|
-
//
|
|
306
|
-
// //log.debug(tag,"txEvents: ",txEvents)
|
|
307
|
-
// txEvents = txEvents.events
|
|
308
|
-
//
|
|
309
|
-
// for(let j = 0; j < txEvents.length; j++){
|
|
310
|
-
// let event = txEvents[j]
|
|
311
|
-
//
|
|
312
|
-
// //
|
|
313
|
-
// //log.debug(tag,"event: ",event)
|
|
314
|
-
// //log.debug(tag,"attributes: ",prettyjson.render(event.attributes))
|
|
315
|
-
//
|
|
316
|
-
// //detect event type
|
|
317
|
-
// log.debug(tag,"type: ",event.type)
|
|
318
|
-
// switch(event.type) {
|
|
319
|
-
// case 'message':
|
|
320
|
-
// // ignore
|
|
321
|
-
// break;
|
|
322
|
-
// case 'transfer':
|
|
323
|
-
// log.debug(tag,"attributes: ",event.attributes)
|
|
324
|
-
// for(let k = 0; k < event.attributes.length; k++){
|
|
325
|
-
// let attribute = event.attributes[k]
|
|
326
|
-
// if(attribute.key === 'recipient'){
|
|
327
|
-
// receiver = attribute.value
|
|
328
|
-
// output.receiver = receiver
|
|
329
|
-
// if(receiver === address) output.type = txTypes[1]
|
|
330
|
-
// }
|
|
331
|
-
// if(attribute.key === 'sender'){
|
|
332
|
-
// sender = attribute.value
|
|
333
|
-
// output.sender = sender
|
|
334
|
-
// if(sender === address) output.type = txTypes[0]
|
|
335
|
-
// }
|
|
336
|
-
// if(attribute.key === 'amount'){
|
|
337
|
-
// amount = attribute.value
|
|
338
|
-
// amount = amount.replace('rune','')
|
|
339
|
-
// output.amount = amount / 100000000
|
|
340
|
-
// }
|
|
341
|
-
// }
|
|
342
|
-
// break;
|
|
343
|
-
// default:
|
|
344
|
-
// // code block
|
|
345
|
-
// }
|
|
346
|
-
// }
|
|
347
|
-
//
|
|
348
|
-
// // console.log("log: ",prettyjson.render(log))
|
|
349
|
-
// }
|
|
350
|
-
//
|
|
351
|
-
// return output
|
|
352
|
-
// }catch(e){
|
|
353
|
-
// log.error(tag,"e: ",e)
|
|
354
|
-
// throw e
|
|
355
|
-
// }
|
|
356
|
-
// }
|
|
357
|
-
//
|
|
358
|
-
// let get_txs_by_address = async function(address:string){
|
|
359
|
-
// let tag = TAG + " | get_txs_by_address | "
|
|
360
|
-
// try{
|
|
361
|
-
// let output:any = []
|
|
362
|
-
//
|
|
363
|
-
// //sends
|
|
364
|
-
// let url = URL_THORNODE+ '/txs?message.sender='+address
|
|
365
|
-
// log.debug(tag,"url: ",url)
|
|
366
|
-
// let resultSends = await axios({
|
|
367
|
-
// url: url,
|
|
368
|
-
// method: 'GET'
|
|
369
|
-
// })
|
|
370
|
-
// let sends = resultSends.data
|
|
371
|
-
// log.debug('sends: ', sends)
|
|
372
|
-
// if(!sends.txs) sends.txs = []
|
|
373
|
-
// // TODO//pagnation
|
|
374
|
-
// for(let i = 0; i < sends?.txs.length; i++ ){
|
|
375
|
-
// let tx = sends.txs[i]
|
|
376
|
-
//
|
|
377
|
-
// //pretty json
|
|
378
|
-
//
|
|
379
|
-
// //normalize
|
|
380
|
-
// tx = normalize_tx(tx,address)
|
|
381
|
-
// output.push(tx)
|
|
382
|
-
// }
|
|
383
|
-
//
|
|
384
|
-
// //receives
|
|
385
|
-
// url = URL_THORNODE+ '/txs?transfer.recipient='+address
|
|
386
|
-
// console.log("URL_THORNODE: ",url)
|
|
387
|
-
// let resultRecieves = await axios({
|
|
388
|
-
// url: url,
|
|
389
|
-
// method: 'GET'
|
|
390
|
-
// })
|
|
391
|
-
// let receives = resultRecieves.data
|
|
392
|
-
// if(!receives.txs) receives.txs = []
|
|
393
|
-
// log.debug('receives: ', receives)
|
|
394
|
-
//
|
|
395
|
-
// for(let i = 0; i < receives?.txs.length; i++ ){
|
|
396
|
-
// let tx = receives.txs[i]
|
|
397
|
-
// //normalize
|
|
398
|
-
// tx = normalize_tx(tx,address)
|
|
399
|
-
// output.push(tx)
|
|
400
|
-
// }
|
|
401
|
-
//
|
|
402
|
-
//
|
|
403
|
-
// return output
|
|
404
|
-
// }catch(e){
|
|
405
|
-
// log.error(tag,"e: ",e)
|
|
406
|
-
// throw e
|
|
407
|
-
// }
|
|
408
|
-
// }
|
|
409
258
|
var get_balance = function (address) {
|
|
410
259
|
return __awaiter(this, void 0, void 0, function () {
|
|
411
|
-
var tag,
|
|
260
|
+
var tag, NOWNODES_API_KEY, response, balanceInDrops, balanceInXRP, e_4;
|
|
412
261
|
return __generator(this, function (_a) {
|
|
413
262
|
switch (_a.label) {
|
|
414
263
|
case 0:
|
|
@@ -416,68 +265,41 @@ var get_balance = function (address) {
|
|
|
416
265
|
_a.label = 1;
|
|
417
266
|
case 1:
|
|
418
267
|
_a.trys.push([1, 3, , 4]);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
268
|
+
log.debug(tag, "Getting balance for:", address);
|
|
269
|
+
NOWNODES_API_KEY = process.env['NOW_NODES_API'];
|
|
270
|
+
return [4 /*yield*/, axios({
|
|
271
|
+
url: URL_NODE,
|
|
272
|
+
method: 'POST',
|
|
273
|
+
data: {
|
|
274
|
+
"method": "account_info",
|
|
275
|
+
"params": [{
|
|
276
|
+
"account": address,
|
|
277
|
+
"ledger_index": "validated"
|
|
278
|
+
}]
|
|
279
|
+
},
|
|
280
|
+
headers: {
|
|
281
|
+
'Content-Type': 'application/json',
|
|
282
|
+
'api-key': NOWNODES_API_KEY
|
|
283
|
+
}
|
|
284
|
+
})];
|
|
432
285
|
case 2:
|
|
433
286
|
response = _a.sent();
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
287
|
+
if (response.data && response.data.result && response.data.result.account_data) {
|
|
288
|
+
balanceInDrops = parseFloat(response.data.result.account_data.Balance);
|
|
289
|
+
balanceInXRP = balanceInDrops / 1000000;
|
|
290
|
+
log.debug(tag, "Balance retrieved:", balanceInXRP, "XRP");
|
|
291
|
+
return [2 /*return*/, balanceInXRP];
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
throw new Error("Invalid response from NowNodes API");
|
|
295
|
+
}
|
|
296
|
+
return [3 /*break*/, 4];
|
|
442
297
|
case 3:
|
|
443
|
-
|
|
444
|
-
log.error(tag, "
|
|
445
|
-
throw
|
|
298
|
+
e_4 = _a.sent();
|
|
299
|
+
log.error(tag, "Error getting balance: ", e_4.message);
|
|
300
|
+
throw e_4;
|
|
446
301
|
case 4: return [2 /*return*/];
|
|
447
302
|
}
|
|
448
303
|
});
|
|
449
304
|
});
|
|
450
305
|
};
|
|
451
|
-
// let get_node_info_verbose = async function(){
|
|
452
|
-
// let tag = TAG + " | get_node_info | "
|
|
453
|
-
// try{
|
|
454
|
-
// let output:any = {}
|
|
455
|
-
//
|
|
456
|
-
// //get syncing status
|
|
457
|
-
// let syncInfo = await axios({method:'GET',url: URL_THORNODE+'/syncing'})
|
|
458
|
-
// log.debug(tag,"syncInfo: ",syncInfo.data)
|
|
459
|
-
//
|
|
460
|
-
// output.isSyncing = syncInfo.data
|
|
461
|
-
//
|
|
462
|
-
// //gaiad abci_info
|
|
463
|
-
// let nodeInfo = await axios({method:'GET',url: URL_THORNODE+'/node_info'})
|
|
464
|
-
// log.debug(tag,"nodeInfo: ",nodeInfo.data)
|
|
465
|
-
// output = nodeInfo.data
|
|
466
|
-
//
|
|
467
|
-
// // let network = await axios({method:'GET',url: URL_THORNODE+'/network'})
|
|
468
|
-
// // log.debug(tag,"nodeInfo: ",network.data)
|
|
469
|
-
// // output.network = network.data
|
|
470
|
-
//
|
|
471
|
-
//
|
|
472
|
-
// let lastBlock = await axios({method:'GET',url: URL_THORNODE+'/blocks/latest'})
|
|
473
|
-
// log.debug(tag,"lastBlock: ",lastBlock.data)
|
|
474
|
-
//
|
|
475
|
-
// //let height
|
|
476
|
-
// output.height = lastBlock.data.block.header.height
|
|
477
|
-
//
|
|
478
|
-
// return output
|
|
479
|
-
// }catch(e){
|
|
480
|
-
// log.error(tag,"e: ",e)
|
|
481
|
-
// throw e
|
|
482
|
-
// }
|
|
483
|
-
// }
|
package/package.json
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/ripple-network",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.3",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
|
+
"description": "Pioneer Platform Ripple Network module with NowNodes integration",
|
|
7
|
+
"keywords": ["ripple", "xrp", "blockchain", "nownodes", "pioneer"],
|
|
6
8
|
"scripts": {
|
|
7
|
-
"create": "
|
|
9
|
+
"create": "pnpm run build && pnpm run test",
|
|
8
10
|
"build": "tsc -p .",
|
|
9
|
-
"test": "
|
|
10
|
-
"prepublish": "rm -R lib &&
|
|
11
|
-
"refresh": "rm -rf ./node_modules ./package-lock.json &&
|
|
11
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
12
|
+
"prepublish": "rm -R lib && pnpm run build",
|
|
13
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
12
14
|
},
|
|
13
15
|
"dependencies": {
|
|
14
16
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
15
|
-
"axios
|
|
16
|
-
"
|
|
17
|
-
"bip32": "^2.0.5",
|
|
18
|
-
"bip39": "^3.0.2",
|
|
19
|
-
"bitcoinjs-lib": "^5.1.10",
|
|
20
|
-
"coininfo": "^5.1.0",
|
|
21
|
-
"cosmos-client": "^0.40.0-rc1",
|
|
22
|
-
"crypto-js": "^3.3.0",
|
|
23
|
-
"dotenv": "^8.2.0",
|
|
24
|
-
"hdkey": "^1.1.2",
|
|
17
|
+
"axios": "^1.6.0",
|
|
18
|
+
"dotenv": "^16.0.0",
|
|
25
19
|
"prettyjson": "^1.2.1",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"typescript": "^5.0.2",
|
|
29
|
-
"xrpl": "^2.5.0"
|
|
20
|
+
"ts-node": "^10.9.0",
|
|
21
|
+
"typescript": "^5.0.4"
|
|
30
22
|
},
|
|
31
23
|
"gitHead": "aeae28273014ab69b42f22abec159c6693a56c40"
|
|
32
|
-
}
|
|
24
|
+
}
|