From 9d71a26766d45ca7b01e7967796197a3f9a7efb0 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 18 Feb 2014 19:31:08 -0300 Subject: [PATCH] fix spents in first part of key matching errors --- app/models/Address.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/models/Address.js b/app/models/Address.js index 6f9e06d..9c80452 100644 --- a/app/models/Address.js +++ b/app/models/Address.js @@ -77,20 +77,27 @@ function spec() { var db = new TransactionDb(); async.series([ function (cb) { + var seen={}; db.fromAddr(self.addrStr, function(err,txOut){ if (err) return cb(err); txOut.forEach(function(txItem){ - + var add=0, addSpend=0; var v = txItem.value_sat; - txs.push({txid: txItem.txid, ts: txItem.ts}); + if ( !seen[txItem.txid] ) { + txs.push({txid: txItem.txid, ts: txItem.ts}); + seen[txItem.txid]=1; + add=1; + } - if (txItem.spentTxId) { + if (txItem.spentTxId && !seen[txItem.spentTxId] ) { txs.push({txid: txItem.spentTxId, ts: txItem.spentTs}); + seen[txItem.spentTxId]=1; + addSpend=1; } if (txItem.isConfirmed) { - self.txApperances += 1; + self.txApperances += add; self.totalReceivedSat += v; if (! txItem.spentTxId ) { //unspent @@ -100,17 +107,17 @@ function spec() { // unspent self.balanceSat += v; self.unconfirmedBalanceSat -= v; - self.unconfirmedTxApperances += 1; + self.unconfirmedTxApperances += addSpend; } else { // spent self.totalSentSat += v; - self.txApperances += 1; + self.txApperances += addSpend; } } else { self.unconfirmedBalanceSat += v; - self.unconfirmedTxApperances += 1; + self.unconfirmedTxApperances += add; } }); return cb();