Skip to content

Commit

Permalink
Database indexing: fix mismatching balances and add db file locks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHolyRoger committed Dec 19, 2019
1 parent 7e3085b commit f434e83
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ function update_address(hash, txid, amount, type, cb) {
var tx_array = address.txs;
var received = address.received;
var sent = address.sent;
if (type == 'vin') {
sent = sent + amount;
} else {
received = received + amount;
}
if (unique == true) {
if ((unique == true) || (type != tx_array[index].type)) {
if (type == 'vin') {
sent = sent + amount;
} else {
received = received + amount;
}
tx_array.push({addresses: txid, type: type});
if ( tx_array.length > settings.txcount ) {
tx_array.shift();
Expand All @@ -77,18 +77,7 @@ function update_address(hash, txid, amount, type, cb) {
return cb();
});
} else {
if (type == tx_array[index].type) {
return cb(); //duplicate
} else {
Address.update({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
balance: received - sent
}, function() {
return cb();
});
}
return cb(); //duplicate
}
});
}
Expand Down

0 comments on commit f434e83

Please sign in to comment.