fix spents in first part of key matching errors

This commit is contained in:
Matias Alejo Garcia 2014-02-18 19:31:08 -03:00
parent 5bef701d11
commit 9d71a26766
1 changed files with 14 additions and 7 deletions

View File

@ -77,20 +77,27 @@ function spec() {
var db = new TransactionDb(); var db = new TransactionDb();
async.series([ async.series([
function (cb) { function (cb) {
var seen={};
db.fromAddr(self.addrStr, function(err,txOut){ db.fromAddr(self.addrStr, function(err,txOut){
if (err) return cb(err); if (err) return cb(err);
txOut.forEach(function(txItem){ txOut.forEach(function(txItem){
var add=0, addSpend=0;
var v = txItem.value_sat; 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}); txs.push({txid: txItem.spentTxId, ts: txItem.spentTs});
seen[txItem.spentTxId]=1;
addSpend=1;
} }
if (txItem.isConfirmed) { if (txItem.isConfirmed) {
self.txApperances += 1; self.txApperances += add;
self.totalReceivedSat += v; self.totalReceivedSat += v;
if (! txItem.spentTxId ) { if (! txItem.spentTxId ) {
//unspent //unspent
@ -100,17 +107,17 @@ function spec() {
// unspent // unspent
self.balanceSat += v; self.balanceSat += v;
self.unconfirmedBalanceSat -= v; self.unconfirmedBalanceSat -= v;
self.unconfirmedTxApperances += 1; self.unconfirmedTxApperances += addSpend;
} }
else { else {
// spent // spent
self.totalSentSat += v; self.totalSentSat += v;
self.txApperances += 1; self.txApperances += addSpend;
} }
} }
else { else {
self.unconfirmedBalanceSat += v; self.unconfirmedBalanceSat += v;
self.unconfirmedTxApperances += 1; self.unconfirmedTxApperances += add;
} }
}); });
return cb(); return cb();