blocks: fix null prevhash issue

This commit is contained in:
Braydon Fuller 2016-04-15 15:48:18 -04:00
parent 6ec263692b
commit b686c5bea9

View File

@ -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),