-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
107 lines (87 loc) · 2.54 KB
/
start.js
File metadata and controls
107 lines (87 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var ripple = require('ripple-lib');
var fs = require('fs');
var testPathFind = function(host) {
var port = 443;
var remote = ripple.Remote.from_config({
//"trace" : true,
trusted : true,
local_signing : true,
servers: [
//{ host: 's-west.ripple.com', port: 443, secure: true },
//{ host: 's-east.ripple.com', port: 443, secure: true }
{ host: host, port: port, secure: true }
],
});
// Find paths between two accounts
var pathFind = function(responseCallback) {
try {
var currency = 'USD';
var amount = ripple.Amount.from_human('0.001 USD')
amount.set_issuer('rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
console.log('Pathfinding...');
// Calculate path
remote.request_path_find_create('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
amount)
.on('success', function(res) {
console.log('success');
console.log(res);
responseCallback(null);
})
// .on('path_find_all', function(res) {
// //console.log(res);
// console.log('path_find');
// responseCallback(null);
// })
// .on('close', function(res) {
// console.log('Close');
// console.log(res);
// responseCallback(null);
// })
.on('error', function(err) {
console.log(err);
responseCallback(err);
})
.request();
}
catch (e) {
responseCallback(e);
}
};
var runPathFind = function() {
var start = Date.now();
// Start pathfind
pathFind(function(error) {
var end = Date.now();
var duration = end - start;
var log = ''+Date().toString()+',';
log = error ? log+'NOTOK,' : log+'OK,';
log = log+host+':'+port+','+duration+'\n';
console.log(log);
if (error) console.log(error);
fs.appendFileSync(filename, log);
remote.disconnect();
//return;
});
}
var filename = './log.csv';
remote.connect();
// Connected to ripple network
remote.on('connect', function () {
console.log('Connected');
runPathFind();
});
remote.on('disconnect', function () {
console.log('Disconnected');
//remote.connect();
process.kill();
});
}
if (process.argv && process.argv.length === 3) {
var host = process.argv[2];
console.log('Testing rippled host: ' + host);
testPathFind(host);
}
else {
console.log('Example: \nnode ' + process.argv[1] + ' \"s-west.ripple.com\"');
}