walletdb: refactor wallet mapping.
This commit is contained in:
parent
60575c0ea0
commit
dec45ac265
@ -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
|
* @param {Hash[]} hashes
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype.getWalletsByHashes = co(function* getWalletsByHashes(tx) {
|
WalletDB.prototype.getWalletsByTX = co(function* getWalletsByTX(tx) {
|
||||||
|
var hashes = tx.getOutputHashes('hex');
|
||||||
var result = [];
|
var result = [];
|
||||||
var hashes = tx.getHashes('hex');
|
var i, j, input, prevout, hash, map;
|
||||||
var i, j, hash, map;
|
|
||||||
|
|
||||||
for (i = 0; i < hashes.length; i++) {
|
if (!tx.isCoinbase()) {
|
||||||
hash = hashes[i];
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
|
input = tx.inputs[i];
|
||||||
|
prevout = input.prevout;
|
||||||
|
|
||||||
if (!this.testFilter(hash))
|
if (!this.testFilter(prevout.toRaw())) {
|
||||||
continue;
|
// Special behavior for SPV.
|
||||||
|
if (this.options.resolution) {
|
||||||
|
hash = input.getHash('hex');
|
||||||
|
|
||||||
map = yield this.getPathMap(hash);
|
if (!hash)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!map)
|
if (!this.testFilter(hash))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (j = 0; j < map.wids.length; j++)
|
map = yield this.getPathMap(hash);
|
||||||
utils.binaryInsert(result, map.wids[j], cmp, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.length === 0)
|
if (!map)
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
return result;
|
for (j = 0; j < map.wids.length; j++)
|
||||||
});
|
utils.binaryInsert(result, map.wids[j], cmp, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
continue;
|
||||||
* Get all wallet ids by multiple address hashes.
|
}
|
||||||
* @param {Hash[]} hashes
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
|
||||||
|
|
||||||
WalletDB.prototype.getWalletsByInsert = co(function* getWalletsByInsert(tx) {
|
map = yield this.getOutpointMap(prevout.hash, prevout.index);
|
||||||
var i, j, result, hashes, input, prevout, hash, map;
|
|
||||||
|
|
||||||
if (this.options.resolution)
|
if (!map)
|
||||||
return yield this.getWalletsByHashes(tx);
|
continue;
|
||||||
|
|
||||||
result = [];
|
for (j = 0; j < map.wids.length; j++)
|
||||||
hashes = tx.getOutputHashes('hex');
|
utils.binaryInsert(result, map.wids[j], cmp, true);
|
||||||
|
}
|
||||||
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 (i = 0; i < hashes.length; i++) {
|
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.');
|
assert(!tx.mutable, 'WDB: Cannot add mutable TX.');
|
||||||
|
|
||||||
wids = yield this.getWalletsByInsert(tx);
|
wids = yield this.getWalletsByTX(tx);
|
||||||
|
|
||||||
if (!wids)
|
if (!wids)
|
||||||
return;
|
return;
|
||||||
@ -2082,8 +2068,7 @@ WalletDB.prototype._insert = co(function* insert(tx, block) {
|
|||||||
* Unconfirm a transaction from all
|
* Unconfirm a transaction from all
|
||||||
* relevant wallets without a lock.
|
* relevant wallets without a lock.
|
||||||
* @private
|
* @private
|
||||||
* @param {TXHash} hash
|
* @param {TXMapRecord} tx
|
||||||
* @param {BlockMeta} block
|
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user