improve getBlock.

This commit is contained in:
Christopher Jeffrey 2016-02-22 05:05:26 -08:00
parent cbed3bbc4f
commit e10c3d2547
3 changed files with 24 additions and 1 deletions

View File

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

View File

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

View File

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