-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwalletAPI.js
52 lines (43 loc) · 1.59 KB
/
walletAPI.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
40
41
42
43
44
45
46
47
48
49
50
51
52
var bitcoin_rpc = require('node-bitcoin-rpc');
var config = require('./config.js');
var masternoodeCount;
function Setup() {
bitcoin_rpc.BITCOIND_TIMEOUT = 1000;
bitcoin_rpc.init(config.Getrpchost(), config.Getrpcport(), config.Getrpcusername(), config.Getrpcpass());
}
function Masternode() {
return new Promise(function (resolve, reject) {
// Do async job
var number = walletAPI.GetMasternodeCount();
resolve(number);
})
}
function GetMasternodeCount() {
return new Promise(function (resolve, reject) {
// Do async job
bitcoin_rpc.call('masternodelist', [], function (err, res) {
var enabled = 0;
if (err) {
let errMsg = "Error when calling bitcoin RPC: " + err;
console.log(errMsg);
} else if (res.error) {
let errMsg = "Error received by bitcoin RPC: " + res.error.message + " (" + res.error.code + ")";
console.log(errMsg);
} else {
var keys = Object.keys(res.result);
console.log(res.result[keys[0]].status);
for (var i = 0; i < keys.length; i++) {
if(res.result[keys[i]].status == "ENABLED"){
enabled++;
}
}
masternoodeCount = enabled;
}
resolve(enabled);
})
console.log("Masternodes : " + masternoodeCount);
return masternoodeCount;
})
}
module.exports.Setup = Setup;
module.exports.GetMasternodeCount = GetMasternodeCount;