diff --git a/config/config.js b/config/config.js index cdae77c..3294245 100644 --- a/config/config.js +++ b/config/config.js @@ -50,6 +50,7 @@ switch (process.env.NODE_ENV) { } var network = process.env.INSIGHT_NETWORK || 'testnet'; +var forceRPCsync = process.env.INSIGHT_FORCE_RPC_SYNC; var dataDir = process.env.BITCOIND_DATADIR; var isWin = /^win/.test(process.platform); @@ -133,4 +134,5 @@ module.exports = { }, safeConfirmations: safeConfirmations, // PLEASE NOTE THAT *FULL RESYNC* IS NEEDED TO CHANGE safeConfirmations ignoreCache: ignoreCache, + forceRPCsync: forceRPCsync, }; diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 1a17c20..717d4cf 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -38,29 +38,36 @@ function HistoricSync(opts) { var bitcore = require('bitcore'); - var RpcClient = bitcore.RpcClient; this.rpc = new RpcClient(config.bitcoind); - if (this.checkBitcoinCoreVersion) { - console.log('-------------------------------------------------------'); - console.log('- Bitcoin Core version is greater or equal than 10.99 -'); - console.log('-------------------------------------------------------'); - } + this.getBitcoinCoreVersion(function(bitcoinVersion) { + if (bitcoinVersion > 100000 && !config.forceRPCsync) { + info('-------------------------------------------------------'); + info('- Bitcoin Core version >0.10 only works with RPC sync -'); + info('- Set the env variable INSIGHT_FORCE_RPC_SYNC = 1 -'); + info('-------------------------------------------------------'); + process.exit(1); + } else { + info('Bitcoin Core version ', bitcoinVersion); + info('Using RPC sync '); + } + }); + this.sync = new Sync(opts); this.height = 0; } -HistoricSync.prototype.checkBitcoinCoreVersion = function() { +HistoricSync.prototype.getBitcoinCoreVersion = function(cb) { var self = this; self.rpc.getInfo(function(err, info) { if (err) { - console.log('ERROR ', err); + error('ERROR ', err); process.exit(-1); }; - return info.result.version >= 109900; + return cb(info.result.version); }); }; @@ -278,6 +285,8 @@ HistoricSync.prototype.updateStartBlock = function(opts, next) { HistoricSync.prototype.prepareFileSync = function(opts, next) { var self = this; + if (config.forceRPCsync) return next(); + if (opts.forceRPC || !config.bitcoind.dataDir || self.height > self.blockChainHeight * PERCENTAGE_TO_START_FROM_RPC) return next();