aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorGavin Andresen <[email protected]>2011-01-20 13:10:01 -0500
committerGavin Andresen <[email protected]>2011-01-20 13:10:01 -0500
commitd9574c2f14028297ad5121695a0c10e517bf638e (patch)
tree6f5adb8c454cf303c63ba7363e675501ac4b9b51 /main.cpp
parentReacceptWalletTransactions bugfix (diff)
downloaddiscoin-d9574c2f14028297ad5121695a0c10e517bf638e.tar.xz
discoin-d9574c2f14028297ad5121695a0c10e517bf638e.zip
Reconcile getbalance and listaccounts 0 in the shared-wallet case
If you copied your wallet and used it on two different machines, the balance reported by getbalance and the sum(listaccounts) could disagree, because you might receive payments for an address that is in your wallet but not your address book. Now all such transactions are credited to the default empty-string account.
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/main.cpp b/main.cpp
index ac0c563ec..3079d3846 100644
--- a/main.cpp
+++ b/main.cpp
@@ -442,8 +442,13 @@ void CWalletTx::GetAmounts(int64& nGenerated, list<pair<string, int64> >& listRe
else if (ExtractPubKey(txout.scriptPubKey, false, vchPubKey))
address = PubKeyToAddress(vchPubKey);
else
- address = " unknown "; // some type of weird non-standard transaction?
+ {
+ printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
+ this->GetHash().ToString().c_str());
+ address = " unknown ";
+ }
+ // Don't report 'change' txouts
if (nDebit > 0 && txout.IsChange())
continue;
@@ -479,8 +484,19 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i
CRITICAL_BLOCK(cs_mapAddressBook)
{
foreach(const PAIRTYPE(string,int64)& r, listReceived)
- if (mapAddressBook.count(r.first) && mapAddressBook[r.first] == strAccount)
+ {
+ if (mapAddressBook.count(r.first))
+ {
+ if (mapAddressBook[r.first] == strAccount)
+ {
+ nReceived += r.second;
+ }
+ }
+ else if (strAccount.empty())
+ {
nReceived += r.second;
+ }
+ }
}
}