node: scan method.
This commit is contained in:
parent
c3ff43c85b
commit
bc4e9e7387
@ -294,7 +294,17 @@ Fullnode.prototype.rescan = function rescan() {
|
||||
// Always rescan to make sure we didn't
|
||||
// miss anything: there is no atomicity
|
||||
// between the chaindb and walletdb.
|
||||
return this.walletdb.rescan(this.chain.db);
|
||||
return this.scan();
|
||||
};
|
||||
|
||||
/**
|
||||
* Rescan for any missed transactions.
|
||||
* @param {Number} height
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Fullnode.prototype.scan = function scan(height) {
|
||||
return this.walletdb.rescan(this.chain.db, height);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -227,16 +227,36 @@ SPVNode.prototype.rescan = function rescan() {
|
||||
this.chain.height);
|
||||
}
|
||||
|
||||
if (this.walletdb.height === 0)
|
||||
return Promise.resolve(null);
|
||||
|
||||
// Always replay the last block to make
|
||||
// sure we didn't miss anything: there
|
||||
// is no atomicity between the chaindb
|
||||
// and walletdb.
|
||||
return this.chain.reset(this.walletdb.height - 1);
|
||||
return this.scan();
|
||||
};
|
||||
|
||||
/**
|
||||
* Scan for any missed transactions.
|
||||
* Note that this will replay the blockchain sync.
|
||||
* @param {Number|Hash} height
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
SPVNode.prototype.scan = co(function* scan(height) {
|
||||
if (height == null)
|
||||
height = this.walletdb.height;
|
||||
|
||||
if (typeof height === 'string') {
|
||||
height = yield this.chain.db.getHeight(height);
|
||||
if (height === -1)
|
||||
return;
|
||||
}
|
||||
|
||||
if (height === 0)
|
||||
return;
|
||||
|
||||
yield this.chain.reset(height - 1);
|
||||
});
|
||||
|
||||
/**
|
||||
* Broadcast a transaction (note that this will _not_ be verified
|
||||
* by the mempool - use with care, lest you get banned from
|
||||
|
||||
Loading…
Reference in New Issue
Block a user