diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index ed240ebc..d8a40859 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -1456,66 +1456,52 @@ WalletDB.prototype.resend = co(function* resend() { }); /** - * Get all wallet ids by multiple address hashes. + * Get all wallet ids by output addresses and outpoints. * @param {Hash[]} hashes * @returns {Promise} */ -WalletDB.prototype.getWalletsByHashes = co(function* getWalletsByHashes(tx) { +WalletDB.prototype.getWalletsByTX = co(function* getWalletsByTX(tx) { + var hashes = tx.getOutputHashes('hex'); var result = []; - var hashes = tx.getHashes('hex'); - var i, j, hash, map; + var i, j, input, prevout, hash, map; - for (i = 0; i < hashes.length; i++) { - hash = hashes[i]; + if (!tx.isCoinbase()) { + for (i = 0; i < tx.inputs.length; i++) { + input = tx.inputs[i]; + prevout = input.prevout; - if (!this.testFilter(hash)) - continue; + if (!this.testFilter(prevout.toRaw())) { + // Special behavior for SPV. + if (this.options.resolution) { + hash = input.getHash('hex'); - map = yield this.getPathMap(hash); + if (!hash) + continue; - if (!map) - continue; + if (!this.testFilter(hash)) + continue; - for (j = 0; j < map.wids.length; j++) - utils.binaryInsert(result, map.wids[j], cmp, true); - } + map = yield this.getPathMap(hash); - if (result.length === 0) - return; + if (!map) + continue; - return result; -}); + for (j = 0; j < map.wids.length; j++) + utils.binaryInsert(result, map.wids[j], cmp, true); + } -/** - * Get all wallet ids by multiple address hashes. - * @param {Hash[]} hashes - * @returns {Promise} - */ + continue; + } -WalletDB.prototype.getWalletsByInsert = co(function* getWalletsByInsert(tx) { - var i, j, result, hashes, input, prevout, hash, map; + map = yield this.getOutpointMap(prevout.hash, prevout.index); - if (this.options.resolution) - return yield this.getWalletsByHashes(tx); + if (!map) + continue; - result = []; - hashes = tx.getOutputHashes('hex'); - - for (i = 0; i < tx.inputs.length; i++) { - input = tx.inputs[i]; - prevout = input.prevout; - - if (!this.testFilter(prevout.toRaw())) - continue; - - map = yield this.getOutpointMap(prevout.hash, prevout.index); - - if (!map) - continue; - - for (j = 0; j < map.wids.length; j++) - utils.binaryInsert(result, map.wids[j], cmp, true); + for (j = 0; j < map.wids.length; j++) + utils.binaryInsert(result, map.wids[j], cmp, true); + } } for (i = 0; i < hashes.length; i++) { @@ -2049,7 +2035,7 @@ WalletDB.prototype._insert = co(function* insert(tx, block) { assert(!tx.mutable, 'WDB: Cannot add mutable TX.'); - wids = yield this.getWalletsByInsert(tx); + wids = yield this.getWalletsByTX(tx); if (!wids) return; @@ -2082,8 +2068,7 @@ WalletDB.prototype._insert = co(function* insert(tx, block) { * Unconfirm a transaction from all * relevant wallets without a lock. * @private - * @param {TXHash} hash - * @param {BlockMeta} block + * @param {TXMapRecord} tx * @returns {Promise} */