diff --git a/lib/bcoin/blockdb.js b/lib/bcoin/blockdb.js index 38422c85..b72d7460 100644 --- a/lib/bcoin/blockdb.js +++ b/lib/bcoin/blockdb.js @@ -858,6 +858,9 @@ BlockDB.prototype.getBlock = function getBlock(hash, callback) { } block._fileOffset = record.offset; block.height = record.height; + block.txs.forEach(function(tx) { + tx.height = block.height; + }); if (self.options.paranoid) { if (typeof hash === 'number') { self._getEntry(hash, function(err, entry) { diff --git a/lib/bcoin/http.js b/lib/bcoin/http.js index bd829e3c..1d445045 100644 --- a/lib/bcoin/http.js +++ b/lib/bcoin/http.js @@ -133,7 +133,12 @@ HTTPServer.prototype._init = function _init() { // Block by hash/height this.get('/block/:hash', function(req, res, next, send) { - self.node.getBlock(req.params.hash, function(err, block) { + var hash = req.params.hash; + + if (utils.isInt(hash)) + hash = +hash; + + self.node.getBlock(hash, function(err, block) { if (err) return next(err); if (!block) diff --git a/lib/bcoin/node.js b/lib/bcoin/node.js index 4cf68c31..375c57a4 100644 --- a/lib/bcoin/node.js +++ b/lib/bcoin/node.js @@ -139,6 +139,21 @@ Node.prototype._init = function _init() { }); }; +Node.prototype.getBlock = function getBlock(hash, callback) { + var self = this; + var coin; + + this.blockdb.getBlock(hash, function(err, block) { + if (err) + return callback(err); + + if (!block) + return callback(); + + return callback(null, block); + }); +}; + Node.prototype.getCoin = function getCoin(hash, index, callback) { var self = this; var coin;