diff --git a/lib/services/db/index.js b/lib/services/db/index.js index 03d9647e..ded34296 100644 --- a/lib/services/db/index.js +++ b/lib/services/db/index.js @@ -299,20 +299,18 @@ DB.prototype.loadTips = function(callback) { return next(err); } - var height, hash; + var hash; //genesis block, set to -1 because we have no yet processed the blocks if (!tipData) { - height = -1; hash = new Array(65).join('0'); self[tip] = { - height: height, + height: -1, hash: hash, - '__height': height + '__height': -1 }; return next(); } - height = tipData.readUInt32BE(32); hash = tipData.slice(0, 32).toString('hex'); self.bitcoind.getBlock(hash, function(err, block) { @@ -321,10 +319,18 @@ DB.prototype.loadTips = function(callback) { return next(err); } - block.__height = height; - self[tip] = block; - next(); + self.bitcoind.getBlockHeader(hash, function(err, header) { + if(err) { + return next(err); + } + + block.__height = header.height; + self[tip] = block; + log.info('loaded tip, hash: ' + block.hash + ' height: ' + block.__height); + next(); + + }); }); });