merkleblock: add indexOf.
This commit is contained in:
parent
d053a25f53
commit
c93de907fe
@ -109,12 +109,29 @@ MerkleBlock.prototype.addTX = function addTX(tx) {
|
||||
*/
|
||||
|
||||
MerkleBlock.prototype.hasTX = function hasTX(hash) {
|
||||
return this.indexOf(hash) !== -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test the block's _matched_ transaction vector against a hash.
|
||||
* @param {Hash|TX} hash
|
||||
* @returns {Number} Index.
|
||||
*/
|
||||
|
||||
MerkleBlock.prototype.indexOf = function indexOf(hash) {
|
||||
var index;
|
||||
|
||||
if (hash instanceof bcoin.tx)
|
||||
hash = hash.hash('hex');
|
||||
|
||||
this.verifyPartial();
|
||||
|
||||
return this.map[hash] != null;
|
||||
index = this.map[hash];
|
||||
|
||||
if (index == null)
|
||||
return -1;
|
||||
|
||||
return index;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user