Browse Source

show avg fee in blocks lists

fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
050c9f4148
  1. 2
      app/api/coreApi.js
  2. 1
      app/api/rpcApi.js
  3. 15
      app/utils.js
  4. 8
      views/includes/blocks-list.pug

2
app/api/coreApi.js

@ -280,6 +280,7 @@ function getBlocksByHeight(blockHeights) {
}
resolve(combinedBlocks);
}).catch(function(err) {
console.log("Error 39g2rfyewgf: " + err);
});
@ -420,6 +421,7 @@ function getBlockByHashWithTransactions(blockHash, txLimit, txOffset) {
getRawTransactions(txids).then(function(transactions) {
if (transactions.length == txids.length) {
block.coinbaseTx = transactions[0];
block.totalFees = utils.getBlockTotalFeesFromCoinbaseTxAndBlockHeight(block.coinbaseTx, block.height);
block.miner = utils.getMinerFromCoinbaseTx(block.coinbaseTx);
}

1
app/api/rpcApi.js

@ -114,6 +114,7 @@ function getBlocksByHash(blockHashes) {
getRawTransactions(coinbaseTxids).then(function(coinbaseTxs) {
for (var i = 0; i < blocks.length; i++) {
blocks[i].coinbaseTx = coinbaseTxs[i];
blocks[i].totalFees = utils.getBlockTotalFeesFromCoinbaseTxAndBlockHeight(coinbaseTxs[i], blocks[i].height);
blocks[i].miner = utils.getMinerFromCoinbaseTx(coinbaseTxs[i]);
}

15
app/utils.js

@ -1,6 +1,7 @@
var Decimal = require("decimal.js");
var config = require("./config.js");
var coins = require("./coins.js");
var coinConfig = coins[config.coin];
function redirectToConnectPageIfNeeded(req, res) {
if (!req.session.host) {
@ -183,6 +184,17 @@ function getMinerFromCoinbaseTx(tx) {
return null;
}
function getBlockTotalFeesFromCoinbaseTxAndBlockHeight(coinbaseTx, blockHeight) {
if (coinbaseTx == null) {
return 0;
}
var blockReward = coinConfig.blockRewardFunction(blockHeight);
var totalOutput = coinbaseTx.vout[0].value;
return new Decimal(totalOutput).minus(new Decimal(blockReward));
}
module.exports = {
redirectToConnectPageIfNeeded: redirectToConnectPageIfNeeded,
@ -196,5 +208,6 @@ module.exports = {
formatCurrencyAmountInSmallestUnits: formatCurrencyAmountInSmallestUnits,
seededRandom: seededRandom,
seededRandomIntBetween: seededRandomIntBetween,
getMinerFromCoinbaseTx: getMinerFromCoinbaseTx
getMinerFromCoinbaseTx: getMinerFromCoinbaseTx,
getBlockTotalFeesFromCoinbaseTxAndBlockHeight: getBlockTotalFeesFromCoinbaseTxAndBlockHeight
};

8
views/includes/blocks-list.pug

@ -7,6 +7,7 @@ table(class="table table-striped table-responsive-sm")
th(class="data-header text-right") Age
th(class="data-header") Miner
th(class="data-header text-right") Transactions
th(class="data-header text-right") Avg Fee
th(class="data-header text-right") Size (bytes)
tbody
each block, blockIndex in blocks
@ -24,5 +25,12 @@ table(class="table table-striped table-responsive-sm")
span #{block.miner.name}
else
span ?
td(class="data-cell monospace text-right") #{block.tx.length.toLocaleString()}
td(class="data-cell monospace text-right")
- var currencyValue = new Decimal(block.totalFees).dividedBy(block.tx.length);
include ./value-display.pug
td(class="data-cell monospace text-right") #{block.size.toLocaleString()}
Loading…
Cancel
Save