diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 46dedce7..f73794a5 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -203,14 +203,19 @@ Block.prototype._verifyPartial = function _verifyPartial() { Block.prototype.getMerkleRoot = function getMerkleRoot() { var hashes = []; - var i; + var i, root; assert(this.subtype === 'block'); for (i = 0; i < this.txs.length; i++) hashes.push(this.txs[i].hash()); - return utils.getMerkleRoot(hashes); + root = utils.getMerkleRoot(hashes); + + if (!root) + return utils.toHex(constants.zeroHash); + + return utils.toHex(root); }; Block.prototype._verify = function _verify() { diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index a6352dfb..c3596fe7 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -1620,5 +1620,5 @@ utils.getMerkleRoot = function getMerkleRoot(items) { if (!tree) return; - return utils.toHex(tree[tree.length - 1]); + return tree[tree.length - 1]; };