improve getBlock.
This commit is contained in:
parent
cbed3bbc4f
commit
e10c3d2547
@ -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) {
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user