diff --git a/lib/http/client.js b/lib/http/client.js index 580c59dd..0935c985 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -344,12 +344,12 @@ HTTPClient.prototype.getTX = function getTX(hash) { /** * Retrieve a block from the chain database. - * @param {Hash} hash + * @param {Hash|Number} block * @returns {Promise} - Returns {@link Block}. */ -HTTPClient.prototype.getBlock = function getBlock(hash) { - return this._get('/block/' + hash); +HTTPClient.prototype.getBlock = function getBlock(block) { + return this._get('/block/' + block); }; /** @@ -377,12 +377,12 @@ HTTPClient.prototype.rescan = function rescan(height) { /** * Reset the chain. - * @param {Hash|Number} hash + * @param {Hash|Number} block * @returns {Promise} */ -HTTPClient.prototype.reset = function reset(hash) { - var options = { hash: hash }; +HTTPClient.prototype.reset = function reset(block) { + var options = { block: block }; return this._post('/reset', options); }; diff --git a/lib/http/server.js b/lib/http/server.js index 04f9d4ec..71b5cb35 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -245,18 +245,27 @@ HTTPServer.prototype._init = function _init() { options.id = params.id; } - if (utils.isUInt32(params.hash)) { - options.height = params.hash; - } else if (params.hash) { - enforce(typeof params.hash === 'string', 'Hash must be a string.'); - if (params.hash.length !== 64) { - options.height = Number(params.hash); - enforce(utils.isUInt32(options.height), 'Height must be a number.'); + if (params.block != null) { + if (typeof params.block === 'number') { + assert(utils.isUInt32(params.block), 'Height must be a number.'); + options.height = params.block; } else { - options.hash = utils.revHex(params.hash); + enforce(typeof params.block === 'string', 'Hash must be a string.'); + if (params.block.length !== 64) { + options.height = Number(params.block); + enforce(utils.isUInt32(options.height), 'Height must be a number.'); + } else { + options.hash = utils.revHex(params.block); + } } } + if (params.hash) { + enforce(typeof params.hash === 'string', 'Hash must be a string.'); + enforce(params.hash.length === 64, 'Hash must be a string.'); + options.hash = utils.revHex(params.hash); + } + if (params.index != null) { options.index = Number(params.index); enforce(utils.isUInt32(options.index), 'Index must be a number.'); @@ -681,7 +690,7 @@ HTTPServer.prototype._init = function _init() { })); // Block by hash/height - this.get('/block/:hash', con(function* (req, res, send, next) { + this.get('/block/:block', con(function* (req, res, send, next) { var hash = req.options.hash || req.options.height; var block;