From da4adedc05fbaabf387d36fb4e6e8c82f875bef8 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Thu, 9 Aug 2018 16:21:59 -0400 Subject: [PATCH] minor reorganization, prepping for code reuse improvements --- app/utils.js | 29 ++++++++++++++++++++++- views/includes/transaction-io-details.pug | 20 +++------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/app/utils.js b/app/utils.js index fea5b55..183182a 100644 --- a/app/utils.js +++ b/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 }; diff --git a/views/includes/transaction-io-details.pug b/views/includes/transaction-io-details.pug index 3a839a8..f695226 100644 --- a/views/includes/transaction-io-details.pug +++ b/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