From a2dec037ba1e97ba9af5bf52614896ad1a048465 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Fri, 10 Aug 2018 14:58:25 -0400 Subject: [PATCH] more debugging/armor for #45 --- app/utils.js | 12 ++-- views/includes/transaction-io-details.pug | 85 ++++++++++++----------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/app/utils.js b/app/utils.js index 4153c22..4f1a654 100644 --- a/app/utils.js +++ b/app/utils.js @@ -220,13 +220,17 @@ function getTxTotalInputOutputValues(tx, txInputs, blockHeight) { totalInputValue = totalInputValue.plus(new Decimal(coinConfig.blockRewardFunction(blockHeight))); } - for (var i = 0; i < txInputs.length; i++) { + for (var i = 0; i < tx.vin.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)); + try { + var vout = txInput.vout[tx.vin[i].vout]; + if (vout.value) { + totalInputValue = totalInputValue.plus(new Decimal(vout.value)); + } + } catch { + console.log("Error getting tx.totalInputValue: txid=" + tx.txid + ", index=tx.vin[" + i + "]"); } } } diff --git a/views/includes/transaction-io-details.pug b/views/includes/transaction-io-details.pug index 309e365..4cc86cd 100644 --- a/views/includes/transaction-io-details.pug +++ b/views/includes/transaction-io-details.pug @@ -7,49 +7,52 @@ div(class="row") div(class="col-md-6") if (txInputs) table(class="table monospace mb-0") - if (tx.vin[0].coinbase) - tr - th(class="pl-0 pr-1") - a(data-toggle="tooltip", title="Input #1", style="white-space: nowrap;") - i(class=("fas fa-" + fontawesomeInputName + " mr-2")) - span 1 - - td(class="border-top-0") - span(class="tag") coinbase - span Newly minted coins - - td(class="border-top-0 text-right") - - var currencyValue = coinConfig.blockRewardFunction(result.getblock.height); - include ./value-display.pug - - each txInput, txInputIndex in txInputs - tr - th(class="pl-0 pr-1") - a(data-toggle="tooltip", title=("Input #" + (txInputIndex + 1)), style="white-space: nowrap;") - i(class=("fas fa-" + fontawesomeInputName + " mr-2")) - span #{(txInputIndex + 1)} - - - var vout = null; - if (txInput && txInput.vout && tx.vin && tx.vin[txInputIndex]) - - var vout = txInput.vout[tx.vin[txInputIndex].vout]; - - td(class=(txInputIndex == 0 ? "border-top-0" : false), class="pl-0") - if (vout && vout.scriptPubKey && vout.scriptPubKey.addresses) - div(style="word-break: break-word;") - a(href=("/address/" + vout.scriptPubKey.addresses[0])) #{vout.scriptPubKey.addresses[0]} - span(class="small") via - a(href=("/tx/" + txInput.txid + "#output-" + tx.vin[txInputIndex].vout)) #{txInput.txid.substring(0, 20)}...[#{tx.vin[txInputIndex].vout}] - - else - span(class="text-danger") Unable to decode input - a(data-toggle="popover", title=JSON.stringify(txInput)) - i(class="fas fa-plus-circle") - - td(class=(txInputIndex == 0 ? "border-top-0" : false), class="pl-0 text-right") - if (vout && vout.value) - - var currencyValue = vout.value; + each txVin, txVinIndex in tx.vin + if (txVin.coinbase) + tr + th(class="pl-0 pr-1") + a(data-toggle="tooltip", title="Input #1", style="white-space: nowrap;") + i(class=("fas fa-" + fontawesomeInputName + " mr-2")) + span 1 + + td(class="border-top-0") + span(class="tag") coinbase + span Newly minted coins + + td(class="border-top-0 text-right") + - var currencyValue = coinConfig.blockRewardFunction(result.getblock.height); include ./value-display.pug + else + tr + th(class="pl-0 pr-1") + a(data-toggle="tooltip", title=("Input #" + (txVinIndex + 1)), style="white-space: nowrap;") + i(class=("fas fa-" + fontawesomeInputName + " mr-2")) + span #{(txVinIndex + 1)} + + - var vout = null; + if (txInputs && txInputs[txVinIndex]) + - var txInput = txInputs[txVinIndex]; + if (txInput.vout && txInput.vout[txVin.vout]) + - var vout = txInput.vout[txVin.vout]; + + td(class=(txVinIndex == 0 ? "border-top-0" : false), class="pl-0") + if (vout && vout.scriptPubKey && vout.scriptPubKey.addresses) + div(style="word-break: break-word;") + a(href=("/address/" + vout.scriptPubKey.addresses[0])) #{vout.scriptPubKey.addresses[0]} + span(class="small") via + a(href=("/tx/" + txInput.txid + "#output-" + txVin.vout)) #{txInput.txid.substring(0, 20)}...[#{txVin.vout}] + + else + span(class="text-danger") Unable to decode input + a(data-toggle="popover", title=JSON.stringify(txInput)) + i(class="fas fa-plus-circle") + + td(class=(txInputIndex == 0 ? "border-top-0" : false), class="pl-0 text-right") + if (vout && vout.value) + - var currencyValue = vout.value; + include ./value-display.pug + tr th td