diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index f6a29e2..2593690 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -35,9 +35,29 @@ function spec() { } HistoricSync.prototype.init = function(opts, cb) { - this.rpc = new RpcClient(config.bitcoind); - this.opts = opts; - this.sync.init(opts, cb); + + var self = this; + self.rpc = new RpcClient(config.bitcoind); + self.opts = opts; + self.sync.init(opts, function(err) { + if (err) { + self.err = err.message; + self.syncInfo = util._extend(self.syncInfo, { error: err.message }); + return cb(err); + } + else { + // check testnet? + self.rpc.getBlockHash(0, function(err, res){ + if (!err && ( res && res.result !== self.genesis)) { + self.err = 'Bad genesis block. Network mismatch between Insight and bitcoind? Insight is configured for:' + config.network; + err = new Error(self.err); + self.syncInfo = util._extend(self.syncInfo, { error: err.message }); + } + return cb(err); + }); + } + }); + }; HistoricSync.prototype.close = function() { diff --git a/public/js/controllers/status.js b/public/js/controllers/status.js index d4d4111..a350002 100644 --- a/public/js/controllers/status.js +++ b/public/js/controllers/status.js @@ -23,6 +23,12 @@ function($scope, $routeParams, $location, $rootScope, Global, Status, Sync, get_ }; var on_sync_update = function(sync) { + + if (sync.error) { + $rootScope.syncError = sync.error; + return; + } + if (sync.blocksToSync > sync.syncedBlocks) { var p = parseInt(100*(sync.syncedBlocks) / sync.blocksToSync); var delta = sync.blocksToSync - sync.syncedBlocks; diff --git a/server.js b/server.js index c2fde5f..a44d1ef 100644 --- a/server.js +++ b/server.js @@ -62,13 +62,19 @@ if (!config.disableHistoricSync) { shouldBroadcast: true, progressStep: 2, networkName: config.network - }, function() { - historicSync.smart_import(function(err){ - var txt= 'ended.'; - if (err) txt = 'ABORTED with error: ' + err.message; + }, function(err) { + if (err) { + var txt = 'ABORTED with error: ' + err.message; + console.log('[historic_sync] ' + txt); + } + else { + historicSync.smart_import(function(err){ + var txt= 'ended.'; + if (err) txt = 'ABORTED with error: ' + err.message; - console.log('[historic_sync] ' + txt, historicSync.syncInfo); - }); + console.log('[historic_sync] ' + txt, historicSync.syncInfo); + }); + } }); }