diff --git a/lib/blocks.js b/lib/blocks.js index 51417e5..d922d43 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -27,6 +27,7 @@ BlockController.prototype.block = function(req, res, next, hash) { } var info = self.node.services.bitcoind.getBlockIndex(hash); + info.isMainChain = self.node.services.bitcoind.isMainChain(hash); req.block = self.transformBlock(block, info); next(); @@ -54,8 +55,8 @@ BlockController.prototype.transformBlock = function(block, info) { previousblockhash: blockObj.header.prevHash, nextblockhash: null, // placeholder reward: this.getBlockReward(info.height) / 1e8, - isMainChain: true // placeholder - } + isMainChain: info.isMainChain + }; }; /** diff --git a/test/blocks.js b/test/blocks.js index 655e555..4eab00a 100644 --- a/test/blocks.js +++ b/test/blocks.js @@ -74,7 +74,8 @@ describe('Blocks', function() { getBlock: sinon.stub().callsArgWith(1, null, bitcoreBlock), services: { bitcoind: { - getBlockIndex: sinon.stub().returns(blockIndexes['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7']) + getBlockIndex: sinon.stub().returns(blockIndexes['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7']), + isMainChain: sinon.stub().returns(true) }, db: { tip: {