improve getMerkleRoot.
This commit is contained in:
parent
36e8d75faf
commit
0dabee0336
@ -203,14 +203,19 @@ Block.prototype._verifyPartial = function _verifyPartial() {
|
|||||||
|
|
||||||
Block.prototype.getMerkleRoot = function getMerkleRoot() {
|
Block.prototype.getMerkleRoot = function getMerkleRoot() {
|
||||||
var hashes = [];
|
var hashes = [];
|
||||||
var i;
|
var i, root;
|
||||||
|
|
||||||
assert(this.subtype === 'block');
|
assert(this.subtype === 'block');
|
||||||
|
|
||||||
for (i = 0; i < this.txs.length; i++)
|
for (i = 0; i < this.txs.length; i++)
|
||||||
hashes.push(this.txs[i].hash());
|
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() {
|
Block.prototype._verify = function _verify() {
|
||||||
|
|||||||
@ -1620,5 +1620,5 @@ utils.getMerkleRoot = function getMerkleRoot(items) {
|
|||||||
if (!tree)
|
if (!tree)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
return utils.toHex(tree[tree.length - 1]);
|
return tree[tree.length - 1];
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user