function (cb) { bitcoinRpc.getBlockTemplate(function(err, gbt) { if (err) { if (!gbt) { // connection failure, err === {} which is unhelpful if (connFailurePrint) { console.log('Baron Init: Bitcoind connection failure. Baron will retry every 15 seconds until it appears.'); connFailurePrint = false; } setTimeout(cb, 15000); } else if (err.code && err.code === -10) { // getBlockTemplate returns error code -10 while "Bitcoin is downloading blocks..." if (syncPrint) { console.log('Baron Init: Bitcoind is busy syncing blocks. Baron will quietly check every 15 seconds until it is ready.'); syncPrint = false; } setTimeout(cb, 15000); } else { // FATAL: unknown other error console.log('Baron Init: Fatal bitcoind error: ' + JSON.stringify(err)); process.exit(1); } } else { waitForBitcoind = false; cb(); } }); },
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 (cb) { bitcoinRpc.getBlockTemplate(function(err, gbt) { if (err) { if (!gbt || err.code && err.code === -9 ) { // ECONNREFUSED, err === {} && !gbt // err.code === -9 for a split second during bitcoind startup if (connFailurePrint) { if (err && err.code) { log.error(err, 'getBlockTemplate error'); } else if (err.message === "bitcoin JSON-RPC connection rejected: 401 unauthorized") { log.fatal('Baron Init: bitcoind credentials are incorrect.'); process.exit(1); } log.info('Baron Init: Bitcoind connection failure. Baron will retry every 15 seconds until it appears.'); connFailurePrint = false; } setTimeout(cb, 15000); } else if (err.code && err.code === -10) { // getBlockTemplate returns error code -10 while "Bitcoin is downloading blocks..." if (syncPrint) { log.info('Baron Init: Bitcoind is busy syncing blocks. Baron will quietly check every 15 seconds until it is ready.'); syncPrint = false; } setTimeout(cb, 15000); } else { // FATAL: unknown other error log.fatal(err, 'Baron Init: Fatal bitcoind error'); process.exit(1); } } else { waitForBitcoind = false; cb(); } }); },