From f20cb814832125d2a859367fab5acbab93e03ea7 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Fri, 10 Aug 2018 15:06:54 -0400 Subject: [PATCH] more work on #45 --- app/utils.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/utils.js b/app/utils.js index 4f1a654..3909fcf 100644 --- a/app/utils.js +++ b/app/utils.js @@ -216,21 +216,23 @@ function getMinerFromCoinbaseTx(tx) { 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 < tx.vin.length; i++) { - var txInput = txInputs[i]; + if (tx.vin[i].coinbase) { + totalInputValue = totalInputValue.plus(new Decimal(coinConfig.blockRewardFunction(blockHeight))); + + } else { + var txInput = txInputs[i]; - if (txInput) { - try { - var vout = txInput.vout[tx.vin[i].vout]; - if (vout.value) { - totalInputValue = totalInputValue.plus(new Decimal(vout.value)); + if (txInput) { + try { + var vout = txInput.vout[tx.vin[i].vout]; + if (vout.value) { + totalInputValue = totalInputValue.plus(new Decimal(vout.value)); + } + } catch (err) { + console.log("Error getting tx.totalInputValue: err=" + err + ", txid=" + tx.txid + ", index=tx.vin[" + i + "]"); } - } catch { - console.log("Error getting tx.totalInputValue: txid=" + tx.txid + ", index=tx.vin[" + i + "]"); } } }