merkleblock: add indexOf.

This commit is contained in:
Christopher Jeffrey 2016-08-17 03:21:46 -07:00
parent d053a25f53
commit c93de907fe
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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;
};
/**