From 9d71a26766d45ca7b01e7967796197a3f9a7efb0 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 18 Feb 2014 19:31:08 -0300 Subject: [PATCH 1/2] 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 6f9e06df..9c804524 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(); From c2221a9ece77918c1345b5501faddd6d3d9c96df Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 18 Feb 2014 19:31:23 -0300 Subject: [PATCH 2/2] fix repeating TXs in addr pages --- lib/TransactionDb.js | 17 ++++++++--------- public/src/js/controllers/transactions.js | 3 +-- public/views/transaction/tx.html | 17 +++++++++++++---- test/integration/addr.json | 22 +++++++++++++++++----- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/lib/TransactionDb.js b/lib/TransactionDb.js index 2a407b71..00c9faeb 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 72f15d48..e22897cb 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 65a465d0..f38005f9 100644 --- a/public/views/transaction/tx.html +++ b/public/views/transaction/tx.html @@ -26,7 +26,8 @@
-
+
+
{{$root.currency.getConvertion(vin.value)}}
@@ -41,7 +42,10 @@
-
+
+
+
{{$root.currency.getConvertion(vin.value)}}
@@ -67,6 +71,7 @@
+
-
+
+
@@ -97,7 +103,9 @@
-
+
+
+
{{$root.currency.getConvertion(vout.value)}} (U) @@ -126,6 +134,7 @@
+
diff --git a/test/integration/addr.json b/test/integration/addr.json index b68d913a..15c47af9 100644 --- a/test/integration/addr.json +++ b/test/integration/addr.json @@ -1,5 +1,4 @@ [ - { "addr": "mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS", "balance": 0, @@ -37,7 +36,7 @@ }, { "addr": "mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ", - "txApperances": 28, + "txApperances": 27, "balance": 0, "totalReceived": 54.81284116 }, @@ -46,11 +45,11 @@ "balance": 1199.74393853, "totalReceived": 1199.74393853, "totalSent": 0, - "txApperances": 6049 + "txApperances": 6048 }, { "addr": "mjRmkmYzvZN3cA3aBKJgYJ65epn3WCG84H", - "txApperances": 13343, + "txApperances": 7164, "balance": 46413.0, "totalReceived": 357130.17644359, "totalSent": 310717.17644359 @@ -68,7 +67,7 @@ "balance": 10580.50027254, "totalReceived": 12157.65075053, "totalSent": 1577.15047799, - "txApperances": 459, + "txApperances": 441, "transactions": [ "91800d80bb4c69b238c9bfd94eb5155ab821e6b25cae5c79903d12853bbb4ed5", "f6e80d4fd1a2377406856c67d0cee5ac7e5120993ff97e617ca9aac33b4c6b1e", @@ -111,7 +110,20 @@ "a3789e113041db907a1217ddb5c3aaf0eff905cc3d913e68d977e1ab4d19acea", "80b460922faf0ad1e8b8a55533654c9a9f3039bfff0fff2bcf8536b8adf95939" ] + }, + { + "addr": "mtA6woo1wjCeu1dLkWgpSD3tRnRfrHt3FL", + "balance": 349.845, + "totalReceived": 349.845, + "totalSent": 0, + "txApperances": 13, + "transactions": [ + "794eafc0ad68a3576034eb137d7d20d3bdf1777ecf27e0e20e96e1adcfc66659", + "0130721f29f50b773858c3c9081678bdddebcd18078c5fa2436d979b54ed5cef", + "fb1024947b48d90255aedd3f0f1df3673a7e98d06346bb2ac89b116aa19c5db4" + ] } + ]