http: expose chain resetting.

This commit is contained in:
Christopher Jeffrey 2016-11-16 09:56:52 -08:00
parent 522a54fd27
commit f6c09af49f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 42 additions and 5 deletions

20
bin/cli
View File

@ -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.');

View File

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

View File

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