walletdb: refactor.

This commit is contained in:
Christopher Jeffrey 2016-11-11 18:16:18 -08:00
parent 4e4b87b18e
commit ecd18b9613
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1424,6 +1424,38 @@ WalletDB.prototype.resend = co(function* resend() {
}
});
/**
* Insert all wallet ids for an input
* (special behavior for SPV).
* @private
* @param {Input} input
* @param {WalletID[]} result
* @returns {Promise}
*/
WalletDB.prototype.testInput = co(function* testInput(input, result) {
var i, hash, map;
if (!this.options.resolution)
return;
hash = input.getHash('hex');
if (!hash)
return;
if (!this.testFilter(hash))
return;
map = yield this.getPathMap(hash);
if (!map)
return;
for (i = 0; i < map.wids.length; i++)
utils.binaryInsert(result, map.wids[i], cmp, true);
});
/**
* Get all wallet ids by output addresses and outpoints.
* @param {Hash[]} hashes
@ -1441,32 +1473,16 @@ WalletDB.prototype.getWalletsByTX = co(function* getWalletsByTX(tx) {
prevout = input.prevout;
if (!this.testFilter(prevout.toRaw())) {
// Special behavior for SPV.
if (this.options.resolution) {
hash = input.getHash('hex');
if (!hash)
continue;
if (!this.testFilter(hash))
continue;
map = yield this.getPathMap(hash);
if (!map)
continue;
for (j = 0; j < map.wids.length; j++)
utils.binaryInsert(result, map.wids[j], cmp, true);
}
yield this.testInput(input, result);
continue;
}
map = yield this.getOutpointMap(prevout.hash, prevout.index);
if (!map)
if (!map) {
yield this.testInput(input, result);
continue;
}
for (j = 0; j < map.wids.length; j++)
utils.binaryInsert(result, map.wids[j], cmp, true);