Added fixes for blocks route.
This commit is contained in:
parent
c61490ed62
commit
5a49f5c6c2
@ -7,6 +7,7 @@ var pools = require('../pools.json');
|
|||||||
var BN = bitcore.crypto.BN;
|
var BN = bitcore.crypto.BN;
|
||||||
var LRU = require('lru-cache');
|
var LRU = require('lru-cache');
|
||||||
var Common = require('./common');
|
var Common = require('./common');
|
||||||
|
var bcoin = require('bcoin');
|
||||||
|
|
||||||
function BlockController(options) {
|
function BlockController(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -77,7 +78,6 @@ BlockController.prototype.block = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self._header.getBlockHeader(hash, function(err, info) {
|
self._header.getBlockHeader(hash, function(err, info) {
|
||||||
console.log(info);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
@ -125,28 +125,28 @@ BlockController.prototype._normalizePrevHash = function(hash) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
BlockController.prototype.transformBlock = function(block, info) {
|
BlockController.prototype.transformBlock = function(block, info) {
|
||||||
var blockObj = block.toObject();
|
var transactionIds = block.txs.map(function(tx) {
|
||||||
var transactionIds = blockObj.transactions.map(function(tx) {
|
return tx.txid();
|
||||||
return tx.hash;
|
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
hash: block.hash,
|
hash: block.rhash(),
|
||||||
size: block.toBuffer().length,
|
size: block.size,
|
||||||
|
virtualSize: block.virtualSize,
|
||||||
height: info.height,
|
height: info.height,
|
||||||
version: blockObj.header.version,
|
version: block.version,
|
||||||
merkleroot: blockObj.header.merkleRoot,
|
merkleroot: block.merkleRoot,
|
||||||
tx: transactionIds,
|
tx: transactionIds,
|
||||||
time: blockObj.header.time,
|
time: block.ts,
|
||||||
nonce: blockObj.header.nonce,
|
nonce: block.nonce,
|
||||||
bits: blockObj.header.bits.toString(16),
|
bits: block.bits,
|
||||||
difficulty: block.header.getDifficulty(),
|
difficulty: null,
|
||||||
chainwork: info.chainWork,
|
chainwork: null,
|
||||||
confirmations: info.confirmations,
|
confirmations: null,
|
||||||
previousblockhash: this._normalizePrevHash(blockObj.header.prevHash),
|
previousblockhash: bcoin.util.revHex(block.prevBlock),
|
||||||
nextblockhash: info.nextHash,
|
nextblockhash: null,
|
||||||
reward: this.getBlockReward(info.height) / 1e8,
|
reward: null,
|
||||||
isMainChain: (info.confirmations !== -1),
|
isMainChain: null,
|
||||||
poolInfo: this.getPoolInfo(block)
|
poolInfo: null
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,7 @@
|
|||||||
"bitcoreNode": "lib",
|
"bitcoreNode": "lib",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "*",
|
"async": "*",
|
||||||
|
"bcoin": "bcoin-org/bcoin#886008a1822ce1da7fa8395ee7db4bcc1750a28a",
|
||||||
"bitcore-lib": "bitpay/bitcore-lib#transitional",
|
"bitcore-lib": "bitpay/bitcore-lib#transitional",
|
||||||
"bitcore-message": "^1.0.1",
|
"bitcore-message": "^1.0.1",
|
||||||
"body-parser": "^1.13.3",
|
"body-parser": "^1.13.3",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user