forked from slickage/baron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanitycheck.js
37 lines (35 loc) · 1.01 KB
/
sanitycheck.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
var bitcoinUtil = require(__dirname + '/bitcoinutil');
var async = require('async');
var proceedWhenBitcoindIsReady = function(cb) {
var waitForBitcoind = true;
async.whilst(
function () { return waitForBitcoind; },
function (cb) {
bitcoinUtil.getBlockTemplate(function(err, gbt) {
if (err) {
if (err.code && err.code === -10) {
// getBlockTemplate returns error code -10 while "Bitcoin is downloading blocks..."
console.log(Math.floor(new Date().getTime()/1000) + ": bitcoind is busy syncing blocks, please wait ...");
setTimeout(cb, 10000);
}
else {
// FATAL: unknown other error
console.log('FATAL bitcoind ' + err);
process.exit(1);
}
}
else {
waitForBitcoind = false;
cb();
}
});
},
function (err) {
//console.log('Sanity Check: bitcoind is ready. ')
cb();
}
);
};
module.exports = {
proceedWhenBitcoindIsReady: proceedWhenBitcoindIsReady
};