diff --git a/lib/blocks.js b/lib/blocks.js index c94f331..565965b 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -84,6 +84,15 @@ BlockController.prototype.rawBlock = function(req, res, next, blockArg) { }; +BlockController.prototype._normalizePrevHash = function(hash) { + // TODO fix bitcore to give back null instead of null hash + if (hash !== '0000000000000000000000000000000000000000000000000000000000000000') { + return hash; + } else { + return null; + } +}; + BlockController.prototype.transformBlock = function(block, info) { var blockObj = block.toObject(); var transactionIds = blockObj.transactions.map(function(tx) { @@ -101,7 +110,7 @@ BlockController.prototype.transformBlock = function(block, info) { bits: blockObj.header.bits.toString(16), difficulty: block.header.getDifficulty(), chainwork: info.chainwork, - previousblockhash: blockObj.header.prevHash, + previousblockhash: this._normalizePrevHash(blockObj.header.prevHash), nextblockhash: info.nextblockhash, reward: this.getBlockReward(info.height) / 1e8, isMainChain: (info.confirmations !== -1),