Added fixes for blocks route.

This commit is contained in:
Chris Kleeschulte 2017-08-09 19:41:50 -04:00
parent c61490ed62
commit 5a49f5c6c2
2 changed files with 20 additions and 19 deletions

View File

@ -7,6 +7,7 @@ var pools = require('../pools.json');
var BN = bitcore.crypto.BN;
var LRU = require('lru-cache');
var Common = require('./common');
var bcoin = require('bcoin');
function BlockController(options) {
var self = this;
@ -77,7 +78,6 @@ BlockController.prototype.block = function(req, res, next) {
}
self._header.getBlockHeader(hash, function(err, info) {
console.log(info);
if (err) {
return self.common.handleErrors(err, res);
}
@ -125,28 +125,28 @@ BlockController.prototype._normalizePrevHash = function(hash) {
};
BlockController.prototype.transformBlock = function(block, info) {
var blockObj = block.toObject();
var transactionIds = blockObj.transactions.map(function(tx) {
return tx.hash;
var transactionIds = block.txs.map(function(tx) {
return tx.txid();
});
return {
hash: block.hash,
size: block.toBuffer().length,
hash: block.rhash(),
size: block.size,
virtualSize: block.virtualSize,
height: info.height,
version: blockObj.header.version,
merkleroot: blockObj.header.merkleRoot,
version: block.version,
merkleroot: block.merkleRoot,
tx: transactionIds,
time: blockObj.header.time,
nonce: blockObj.header.nonce,
bits: blockObj.header.bits.toString(16),
difficulty: block.header.getDifficulty(),
chainwork: info.chainWork,
confirmations: info.confirmations,
previousblockhash: this._normalizePrevHash(blockObj.header.prevHash),
nextblockhash: info.nextHash,
reward: this.getBlockReward(info.height) / 1e8,
isMainChain: (info.confirmations !== -1),
poolInfo: this.getPoolInfo(block)
time: block.ts,
nonce: block.nonce,
bits: block.bits,
difficulty: null,
chainwork: null,
confirmations: null,
previousblockhash: bcoin.util.revHex(block.prevBlock),
nextblockhash: null,
reward: null,
isMainChain: null,
poolInfo: null
};
};

View File

@ -61,6 +61,7 @@
"bitcoreNode": "lib",
"dependencies": {
"async": "*",
"bcoin": "bcoin-org/bcoin#886008a1822ce1da7fa8395ee7db4bcc1750a28a",
"bitcore-lib": "bitpay/bitcore-lib#transitional",
"bitcore-message": "^1.0.1",
"body-parser": "^1.13.3",