forked from cubedro/eth-netstats
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest.js
39 lines (35 loc) · 1.25 KB
/
test.js
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
// Testing some rpc over websockets for dcrd.
// jcv 04/11/2016
var fs = require('fs');
var WebSocket = require('ws');
// Load the certificate for the TLS connection which is automatically
// generated by btcd when it starts the RPC server and doesn't already
// have one.
var cert = fs.readFileSync('/Users/dyrk/Library/Application Support/Dcrd/rpc.cert');
var user = "user";
var password = "pass";
// Initiate the websocket connection. The btcd generated certificate acts as
// its own certificate authority, so it needs to be specified in the 'ca' array
// for the certificate to properly validate.
var ws = new WebSocket('wss://127.0.0.1:9109/ws', {
headers: {
'Authorization': 'Basic '+new Buffer(user+':'+password).toString('base64')
},
cert: cert,
ca: [cert]
});
ws.on('open', function() {
console.log('CONNECTED');
ws.send('{"jsonrpc":"1.0","id":"0","method":"getpeerinfo","params":[]}');
ws.send('{"jsonrpc":"1.0","id":"0","method":"getcoinsupply","params":[]}');
ws.send('{"jsonrpc":"1.0","id":"0","method":"getticketpoolvalue","params":[]}');
});
ws.on('message', function(data, flags) {
console.log(data);
});
ws.on('error', function(derp) {
console.log('ERROR:' + derp);
})
ws.on('close', function(data) {
console.log('DISCONNECTED');
})