From 6e78c83d40401a2e99d1da2ddec501d9b64559d1 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Sat, 23 Feb 2019 11:53:44 -0500 Subject: [PATCH] Fix #106 When computing send/receive values for an address, don't improperly attribute all previous-tx sends as coming from the address of interest --- routes/baseActionsRouter.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index ee2af94..90a7d32 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -678,16 +678,15 @@ router.get("/address/:address", function(req, res) { for (var j = 0; j < tx.vin.length; j++) { var txInput = txInputs[j]; + var vinJ = tx.vin[j]; if (txInput != null) { - for (var k = 0; k < txInput.vout.length; k++) { - if (txInput.vout[k] && txInput.vout[k].scriptPubKey && txInput.vout[k].scriptPubKey.addresses && txInput.vout[k].scriptPubKey.addresses.includes(address)) { - if (addrLossesByTx[tx.txid] == null) { - addrLossesByTx[tx.txid] = new Decimal(0); - } - - addrLossesByTx[tx.txid] = addrLossesByTx[tx.txid].plus(new Decimal(txInput.vout[k].value)); + if (txInput.vout[vinJ.vout] && txInput.vout[vinJ.vout].scriptPubKey && txInput.vout[vinJ.vout].scriptPubKey.addresses && txInput.vout[vinJ.vout].scriptPubKey.addresses.includes(address)) { + if (addrLossesByTx[tx.txid] == null) { + addrLossesByTx[tx.txid] = new Decimal(0); } + + addrLossesByTx[tx.txid] = addrLossesByTx[tx.txid].plus(new Decimal(txInput.vout[vinJ.vout].value)); } } }