Various repairs.
This commit is contained in:
parent
d866dd7a65
commit
21e30645cd
@ -125,9 +125,11 @@ BlockController.prototype._normalizePrevHash = function(hash) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
BlockController.prototype.transformBlock = function(block, info) {
|
BlockController.prototype.transformBlock = function(block, info) {
|
||||||
|
|
||||||
var transactionIds = block.txs.map(function(tx) {
|
var transactionIds = block.txs.map(function(tx) {
|
||||||
return tx.txid();
|
return tx.txid();
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hash: block.rhash(),
|
hash: block.rhash(),
|
||||||
size: block.size,
|
size: block.size,
|
||||||
@ -139,14 +141,14 @@ BlockController.prototype.transformBlock = function(block, info) {
|
|||||||
time: block.ts,
|
time: block.ts,
|
||||||
nonce: block.nonce,
|
nonce: block.nonce,
|
||||||
bits: block.bits,
|
bits: block.bits,
|
||||||
difficulty: null,
|
difficulty: this._header.getDifficulty(),
|
||||||
chainwork: info.chainwork,
|
chainwork: info.chainwork,
|
||||||
confirmations: null,
|
confirmations: this._block.getTip().height - info.height + 1,
|
||||||
previousblockhash: bcoin.util.revHex(block.prevBlock),
|
previousblockhash: info.prevHash,
|
||||||
nextblockhash: null,
|
nextblockhash: null,
|
||||||
reward: null,
|
reward: null,
|
||||||
isMainChain: null,
|
isMainChain: true,
|
||||||
poolInfo: this.getPoolInfo(block)
|
poolInfo: this.getPoolInfo(block.txs[0])
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,36 +196,28 @@ BlockController.prototype._getBlockSummary = function(hash, moreTimestamp, next)
|
|||||||
finish(summaryCache);
|
finish(summaryCache);
|
||||||
} else {
|
} else {
|
||||||
self._block.getRawBlock(hash, function(err, blockBuffer) {
|
self._block.getRawBlock(hash, function(err, blockBuffer) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var br = new bitcore.encoding.BufferReader(blockBuffer);
|
var block = bcoin.block.fromRaw(blockBuffer, 'hex');
|
||||||
|
|
||||||
// TODO: take a shortcut to get number of transactions and the blocksize.
|
self._header.getBlockHeader(hash, function(err, header) {
|
||||||
// Also reads the coinbase transaction and only that.
|
|
||||||
// Old code parsed all transactions in every block _and_ then encoded
|
|
||||||
// them all back together to get the binary size of the block.
|
|
||||||
// FIXME: This code might still read the whole block. Fixing that
|
|
||||||
// would require changes in bitcore-node.
|
|
||||||
var header = bitcore.BlockHeader.fromBufferReader(br);
|
|
||||||
var info = {};
|
|
||||||
var txlength = br.readVarintNum();
|
|
||||||
info.transactions = [bitcore.Transaction().fromBufferReader(br)];
|
|
||||||
|
|
||||||
self._header.getBlockHeader(hash, function(err, blockHeader) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
var height = blockHeader.height;
|
var height = header.height;
|
||||||
|
|
||||||
var summary = {
|
var summary = {
|
||||||
height: height,
|
height: header.height,
|
||||||
size: blockBuffer.length,
|
size: block.size,
|
||||||
|
virtualSize: block.virtualSize,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
time: header.time,
|
time: header.timestamp,
|
||||||
txlength: txlength,
|
txlength: block.txs.length,
|
||||||
poolInfo: self.getPoolInfo(info)
|
poolInfo: self.getPoolInfo(block.txs[0])
|
||||||
};
|
};
|
||||||
|
|
||||||
var _height = self._block.getTip().height;
|
var _height = self._block.getTip().height;
|
||||||
@ -319,8 +313,11 @@ BlockController.prototype.list = function(req, res) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockController.prototype.getPoolInfo = function(block) {
|
BlockController.prototype.getPoolInfo = function(tx) {
|
||||||
var coinbaseBuffer = block.txs[0].inputs[0].script.raw;
|
if (!tx) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
var coinbaseBuffer = tx.inputs[0].script.raw;
|
||||||
|
|
||||||
for(var k in this.poolStrings) {
|
for(var k in this.poolStrings) {
|
||||||
if (coinbaseBuffer.toString('utf-8').match(k)) {
|
if (coinbaseBuffer.toString('utf-8').match(k)) {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ var Common = require('./common');
|
|||||||
function StatusController(node) {
|
function StatusController(node) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.common = new Common({log: this.node.log});
|
this.common = new Common({log: this.node.log});
|
||||||
|
this._header = this.node.services.header;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusController.prototype.show = function(req, res) {
|
StatusController.prototype.show = function(req, res) {
|
||||||
@ -45,7 +46,7 @@ StatusController.prototype.show = function(req, res) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
StatusController.prototype.getInfo = function(callback) {
|
StatusController.prototype.getInfo = function(callback) {
|
||||||
this.node.services.bitcoind.getInfo(function(err, result) {
|
this._header.getInfo(function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ var Common = require('./common');
|
|||||||
|
|
||||||
function UtilsController(node) {
|
function UtilsController(node) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
this._fee = this.node.services.fee;
|
||||||
this.common = new Common({log: this.node.log});
|
this.common = new Common({log: this.node.log});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ UtilsController.prototype.estimateFee = function(req, res) {
|
|||||||
async.map(nbBlocks, function(n, next) {
|
async.map(nbBlocks, function(n, next) {
|
||||||
var num = parseInt(n);
|
var num = parseInt(n);
|
||||||
// Insight and Bitcoin JSON-RPC return bitcoin for this value (instead of satoshis).
|
// Insight and Bitcoin JSON-RPC return bitcoin for this value (instead of satoshis).
|
||||||
self.node.services.bitcoind.estimateFee(num, function(err, fee) {
|
self._fee.estimateFee(num, function(err, fee) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user