improve getMerkleRoot.

This commit is contained in:
Christopher Jeffrey 2016-02-23 17:11:24 -08:00
parent 36e8d75faf
commit 0dabee0336
2 changed files with 8 additions and 3 deletions

View File

@ -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() {

View File

@ -1620,5 +1620,5 @@ utils.getMerkleRoot = function getMerkleRoot(items) {
if (!tree)
return;
return utils.toHex(tree[tree.length - 1]);
return tree[tree.length - 1];
};