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(); diff --git a/lib/TransactionDb.js b/lib/TransactionDb.js index 2a407b7..00c9fae 100644 --- a/lib/TransactionDb.js +++ b/lib/TransactionDb.js @@ -137,7 +137,7 @@ function spec(b) { }) .on('end', function() { - var k = SPENT_PREFIX + txid; + var k = SPENT_PREFIX + txid + '-'; db.createReadStream({ start: k, end: k + '~' @@ -166,7 +166,7 @@ function spec(b) { if (!info) return cb(); - var k = SPENT_PREFIX + info.txid; + var k = SPENT_PREFIX + info.txid + '-'; db.createReadStream({ start: k, end: k + '~' @@ -311,7 +311,7 @@ isspent */ // spent? - var k = SPENT_PREFIX + txid + '-' + n; + var k = SPENT_PREFIX + txid + '-' + n + '-'; db.createReadStream({ start: k, end: k + '~' @@ -365,7 +365,7 @@ isspent TransactionDb.prototype.fromAddr = function(addr, cb) { var self = this; - var k = ADDR_PREFIX + addr; + var k = ADDR_PREFIX + addr + '-'; var ret = []; db.createReadStream({ @@ -388,7 +388,7 @@ isspent .on('end', function() { async.eachLimit(ret, CONCURRENCY, function(o, e_c) { - var k = SPENT_PREFIX + o.txid + '-' + o.index; + var k = SPENT_PREFIX + o.txid + '-' + o.index + '-'; db.createReadStream({ start: k, end: k + '~' @@ -415,14 +415,13 @@ isspent }; - TransactionDb.prototype.removeFromTxId = function(txid, cb) { async.series([ function(c) { db.createReadStream({ - start: OUTS_PREFIX + txid, + start: OUTS_PREFIX + txid + '-', end: OUTS_PREFIX + txid + '~', }).pipe( db.createWriteStream({ @@ -432,7 +431,7 @@ isspent }, function(c) { db.createReadStream({ - start: SPENT_PREFIX + txid, + start: SPENT_PREFIX + txid + '-', end: SPENT_PREFIX + txid + '~' }) .pipe( @@ -578,7 +577,7 @@ isspent addrs.push(addr); } - // existed? + // existed? var k = OUTS_PREFIX + tx.txid + '-' + o.n; db.get(k, function(err) { if (err && err.notFound) { diff --git a/public/src/js/controllers/transactions.js b/public/src/js/controllers/transactions.js index 72f15d4..e22897c 100644 --- a/public/src/js/controllers/transactions.js +++ b/public/src/js/controllers/transactions.js @@ -59,16 +59,15 @@ function($scope, $rootScope, $routeParams, $location, Global, Transaction, Trans tmp[addr].unconfirmedInput += items[i].unconfirmedInput; tmp[addr].dbError = tmp[addr].dbError || items[i].dbError; tmp[addr].valueSat += items[i].value * COIN; - tmp[addr].value = tmp[addr].valueSat / COIN; tmp[addr].items.push(items[i]); tmp[addr].notAddr = notAddr; tmp[addr].count++; } angular.forEach(tmp, function(v) { + v.value = parseInt(v.valueSat) / COIN; ret.push(v); }); - return ret; }; diff --git a/public/views/transaction/tx.html b/public/views/transaction/tx.html index 65a465d..f38005f 100644 --- a/public/views/transaction/tx.html +++ b/public/views/transaction/tx.html @@ -26,7 +26,8 @@