node: scan method.

This commit is contained in:
Christopher Jeffrey 2016-10-05 04:29:10 -07:00
parent c3ff43c85b
commit bc4e9e7387
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 35 additions and 5 deletions

View File

@ -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);
};
/**

View File

@ -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