|
|
@ -60,7 +60,6 @@ function MerkleBlock(arg) { |
|
|
|
throw new TypeError('Unrecognized argument for MerkleBlock'); |
|
|
|
} |
|
|
|
_.extend(this,info); |
|
|
|
this._validMerkleTree = null; |
|
|
|
this._flagBitsUsed = 0; |
|
|
|
this._hashesUsed = 0; |
|
|
|
return this; |
|
|
@ -144,18 +143,15 @@ MerkleBlock.prototype.toJSON = function toJSON() { |
|
|
|
MerkleBlock.prototype.validMerkleTree = function validMerkleTree() { |
|
|
|
$.checkState(_.isArray(this.flags), 'MerkleBlock flags is not an array'); |
|
|
|
$.checkState(_.isArray(this.hashes), 'MerkleBlock hashes is not an array'); |
|
|
|
if(_.isBoolean(this._validMerkleTree)) { |
|
|
|
return this._validMerkleTree; |
|
|
|
} |
|
|
|
|
|
|
|
// Can't have more hashes than numTransactions
|
|
|
|
if(this.hashes.length > this.numTransactions) { |
|
|
|
return this._setValidMerkleTree(false); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Can't have more flag bits than num hashes
|
|
|
|
if(this.flags.length * 8 < this.hashes.length) { |
|
|
|
return this._setValidMerkleTree(false); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var height = 0; |
|
|
@ -167,9 +163,9 @@ MerkleBlock.prototype.validMerkleTree = function validMerkleTree() { |
|
|
|
this._hashesUsed = 0; |
|
|
|
var root = this._traverseMerkleTree(height, 0); |
|
|
|
if(this._hashesUsed !== this.hashes.length) { |
|
|
|
return this._setValidMerkleTree(false); |
|
|
|
false; |
|
|
|
} |
|
|
|
return this._setValidMerkleTree(BufferUtil.equals(root, this.header.merkleRoot)); |
|
|
|
return BufferUtil.equals(root, this.header.merkleRoot); |
|
|
|
} |
|
|
|
|
|
|
|
/** Traverse a the tree in this MerkleBlock, validating it along the way |
|
|
@ -229,17 +225,6 @@ MerkleBlock.prototype.hasTransaction = function hasTransaction(tx) { |
|
|
|
|| this.hashes.indexOf(revHash) !== -1); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param {Bool} - set the merkle tree validity |
|
|
|
* @returns {Bool} - return true/false |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
MerkleBlock.prototype._setValidMerkleTree = function(valid) { |
|
|
|
this._validMerkleTree = valid; |
|
|
|
return valid; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @param {Buffer} - MerkleBlock data |
|
|
|
* @returns {Object} - An Object representing merkleblock data |
|
|
|