From c93de907fef8338d5025c2b9235c0939ef89870d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 17 Aug 2016 03:21:46 -0700 Subject: [PATCH] merkleblock: add indexOf. --- lib/bcoin/merkleblock.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/bcoin/merkleblock.js b/lib/bcoin/merkleblock.js index 85d17624..2370e88b 100644 --- a/lib/bcoin/merkleblock.js +++ b/lib/bcoin/merkleblock.js @@ -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; }; /**