Browse Source

minor reorganization, prepping for code reuse improvements

fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
da4adedc05
  1. 29
      app/utils.js
  2. 20
      views/includes/transaction-io-details.pug

29
app/utils.js

@ -214,6 +214,32 @@ function getMinerFromCoinbaseTx(tx) {
return null;
}
function getTxTotalInputOutputValues(tx, txInputs, blockHeight) {
var totalInputValue = new Decimal(0);
if (tx.vin[0].coinbase)
totalInputValue = totalInputValue.plus(new Decimal(coinConfig.blockRewardFunction(blockHeight)));
for (var i = 0; i < txInputs.length; i++) {
var txInput = txInputs[i];
if (txInput) {
var vout = txInput.vout[tx.vin[i].vout];
if (vout.value) {
totalInputValue = totalInputValue.plus(new Decimal(vout.value));
}
}
}
var totalOutputValue = new Decimal(0);
for (var i = 0; i < tx.vout.length; i++) {
totalOutputValue = totalOutputValue.plus(new Decimal(tx.vout[i].value));
}
return {input:totalInputValue, output:totalOutputValue};
}
function getBlockTotalFeesFromCoinbaseTxAndBlockHeight(coinbaseTx, blockHeight) {
if (coinbaseTx == null) {
return 0;
@ -360,5 +386,6 @@ module.exports = {
refreshExchangeRate: refreshExchangeRate,
parseExponentStringDouble: parseExponentStringDouble,
formatLargeNumber: formatLargeNumber,
geoLocateIpAddresses: geoLocateIpAddresses
geoLocateIpAddresses: geoLocateIpAddresses,
getTxTotalInputOutputValues: getTxTotalInputOutputValues
};

20
views/includes/transaction-io-details.pug

@ -1,21 +1,7 @@
- var fontawesomeInputName = "sign-in-alt";
- var fontawesomeOutputName = "sign-out-alt";
- var totalInputValue = new Decimal(0);
if (tx.vin[0].coinbase)
- totalInputValue = totalInputValue.plus(new Decimal(coinConfig.blockRewardFunction(blockHeight)));
each txInput, txInputIndex in txInputs
if (txInput)
- var vout = txInput.vout[tx.vin[txInputIndex].vout];
if (vout.value)
- totalInputValue = totalInputValue.plus(new Decimal(vout.value));
- var totalOutputValue = new Decimal(0);
each vout, voutIndex in tx.vout
- totalOutputValue = totalOutputValue.plus(new Decimal(vout.value));
- var totalIOValues = utils.getTxTotalInputOutputValues(tx, txInputs, blockHeight);
div(class="row")
div(class="col-md-6")
@ -65,7 +51,7 @@ div(class="row")
th
td
td(class="text-right font-weight-bold")
- var currencyValue = totalInputValue;
- var currencyValue = totalIOValues.input;
include ./value-display.pug
@ -115,7 +101,7 @@ div(class="row")
th
td
td(class="text-right font-weight-bold")
- var currencyValue = totalOutputValue;
- var currencyValue = totalIOValues.output;
include ./value-display.pug

Loading…
Cancel
Save