Minor fixes.

This commit is contained in:
Chris Kleeschulte 2017-10-06 14:50:22 -04:00
parent fbef2d85fa
commit 3923f260e8
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F
2 changed files with 28 additions and 29 deletions

View File

@ -6,7 +6,6 @@ var util = require('util');
var bitcore = require('bitcore-lib');
var _ = bitcore.deps._;
var pools = require('../pools.json');
var BN = bitcore.crypto.BN;
var LRU = require('lru-cache');
var Common = require('./common');
var bcoin = require('bcoin');
@ -110,6 +109,9 @@ BlockController.prototype.rawBlock = function(req, res, next) {
} else if(err) {
return self.common.handleErrors(err, res);
}
if (!blockBuffer) {
return next();
}
req.rawBlock = {
rawblock: blockBuffer.toString('hex')
};
@ -147,9 +149,9 @@ BlockController.prototype.transformBlock = function(block, info) {
chainwork: info.chainwork,
confirmations: this._block.getTip().height - info.height + 1,
previousblockhash: info.prevHash,
nextblockhash: null,
reward: null,
isMainChain: true,
nextblockhash: info.nextHash,
reward: this.getBlockReward(block.txs[0]),
isMainChain: block.isMainChain,
poolInfo: this.getPoolInfo(block.txs[0])
};
};
@ -203,6 +205,10 @@ BlockController.prototype._getBlockSummary = function(hash, moreTimestamp, next)
return next(err);
}
if (!blockBuffer) {
return next();
}
var block = bcoin.block.fromRaw(blockBuffer, 'hex');
self._header.getBlockHeader(hash, function(err, header) {
@ -214,8 +220,8 @@ BlockController.prototype._getBlockSummary = function(hash, moreTimestamp, next)
var summary = {
height: header.height,
size: block.size,
virtualSize: block.virtualSize,
size: block.getSize(),
virtualSize: block.getVirtualSize(),
hash: hash,
time: header.timestamp,
txlength: block.txs.length,
@ -315,6 +321,14 @@ BlockController.prototype.list = function(req, res) {
});
};
BlockController.prototype.getBlockReward = function(tx) {
var amt = 0;
tx.outputs.forEach(function(output) {
amt += output.value;
});
return bitcore.Unit.fromSatoshis(amt).toBTC();
};
BlockController.prototype.getPoolInfo = function(tx) {
if (!tx) {
return {};
@ -339,18 +353,4 @@ BlockController.prototype.formatTimestamp = function(date) {
return yyyy + '-' + (mm[1] ? mm : '0' + mm[0]) + '-' + (dd[1] ? dd : '0' + dd[0]); //padding
};
BlockController.prototype.getBlockReward = function(height) {
var halvings = Math.floor(height / 210000);
// Force block reward to zero when right shift is undefined.
if (halvings >= 64) {
return 0;
}
// Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
var subsidy = new BN(50 * 1e8);
subsidy = subsidy.shrn(halvings);
return parseInt(subsidy.toString(10));
};
module.exports = BlockController;

View File

@ -141,9 +141,9 @@ TxController.prototype.transformInput = function(options, input, index) {
transformed.valueSat = options.inputValues[index];
transformed.value = transformed.valueSat / 1e8;
transformed.doubleSpentTxID = null; // TODO
//transformed.isConfirmed = null; // TODO
//transformed.confirmations = null; // TODO
//transformed.unconfirmedInput = null; // TODO
transformed.isConfirmed = null; // TODO
transformed.confirmations = null; // TODO
transformed.unconfirmedInput = null; // TODO
return transformed;
};
@ -161,12 +161,11 @@ TxController.prototype.transformOutput = function(options, output, index) {
transformed.scriptPubKey.asm = output.script.toASM();
}
//if (!options.noSpent) {
// These aren't implemented in the new api
//transformed.spentTxId = output.spentTxId || null; // we aren't tracking this with the bcoin implementation
//transformed.spentIndex = _.isUndefined(output.spentIndex) ? null : output.spentIndex;
//transformed.spentHeight = output.spentHeight || null;
//}
if (!options.noSpent) {
transformed.spentTxId = output.spentTxId || null; // TODO
transformed.spentIndex = _.isUndefined(output.spentIndex) ? null : output.spentIndex; // TODO
transformed.spentHeight = output.spentHeight || null; // TODO
}
var address = output.getAddress();
if (address) {