diff --git a/bin/cli b/bin/cli index 396353d5..94add755 100755 --- a/bin/cli +++ b/bin/cli @@ -357,14 +357,25 @@ CLI.prototype.retoken = co(function* retoken() { }); CLI.prototype.rescan = co(function* rescan() { + var height = this.argv[0]; + + if (!utils.isUInt32(height)) + height = null; + + yield this.client.rescan(height); + + this.log('Rescanning...'); +}); + +CLI.prototype.reset = co(function* reset() { var hash = this.argv[0]; if (hash.length !== 64) hash = +hash; - yield this.client.rescan(hash); + yield this.client.reset(hash); - this.log('Rescanning...'); + this.log('Chain has been reset.'); }); CLI.prototype.resend = co(function* resend() { @@ -595,6 +606,8 @@ CLI.prototype.handleNode = co(function* handleNode() { return yield this.getBlock(); case 'rescan': return yield this.rescan(); + case 'reset': + return yield this.reset(); case 'resend': return yield this.resend(); case 'backup': @@ -611,7 +624,8 @@ CLI.prototype.handleNode = co(function* handleNode() { this.log(' $ tx [hash/address]: View transactions.'); this.log(' $ coin [hash+index/address]: View coins.'); this.log(' $ block [hash/height]: View block.'); - this.log(' $ rescan [height/hash]: Rescan for transactions.'); + this.log(' $ rescan [height]: Rescan for transactions.'); + this.log(' $ reset [height/hash]: Reset chain to desired block.'); this.log(' $ resend: Resend pending transactions.'); this.log(' $ backup [path]: Backup the wallet db.'); this.log(' $ rpc [command] [args]: Execute RPC command.'); diff --git a/lib/http/client.js b/lib/http/client.js index 9e2d9a4b..580c59dd 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -366,13 +366,24 @@ HTTPClient.prototype.broadcast = function broadcast(tx) { /** * Rescan the chain. + * @param {Number} height + * @returns {Promise} + */ + +HTTPClient.prototype.rescan = function rescan(height) { + var options = { height: height }; + return this._post('/rescan', options); +}; + +/** + * Reset the chain. * @param {Hash|Number} hash * @returns {Promise} */ -HTTPClient.prototype.rescan = function rescan(hash) { +HTTPClient.prototype.reset = function reset(hash) { var options = { hash: hash }; - return this._post('/rescan', options); + return this._post('/reset', options); }; /** diff --git a/lib/http/server.js b/lib/http/server.js index 53327123..6390c047 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -731,6 +731,18 @@ HTTPServer.prototype._init = function _init() { send(200, { rate: utils.btc(fee) }); }); + // Reset chain + this.post('/reset', con(function* (req, res, send, next) { + var options = req.options; + var hash = options.hash || options.height; + + enforce(hash != null, 'Hash or height is required.'); + + yield this.chain.reset(hash); + + send(200, { success: true }); + })); + // Rescan this.post('/rescan', con(function* (req, res, send, next) { var options = req.options;