diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-01-19 16:50:20 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-01-19 16:50:20 -0500 |
commit | 1d23c7436164faa0b1822acf5ce9507bf6ff257a (patch) | |
tree | 1ef71d923e9183521e1338ffa40526b3a73201ec /rpc.cpp | |
parent | c9f70b381dc8ee4197fd5b3d4d20f302632da0ed (diff) |
ReacceptWalletTransactions bugfix
Fix two bugs that can happen if you copy your wallet to another machine
and perform transactions on both.
First, ReacceptWalletTransactions would notice if the other wallet spent coins, and
would correctly mark the receiving transaction spent. However, it did not add the spending
transaction to the wallet. Now it does.
Second, account balances could get out of sync with 'getbalance' because coins received
by the other copy of the wallet were not necessarily detected. Now ReacceptWalletTransactions
will scan the entire blockchain for transactions that should be in the wallet if it runs
across a 'spent in the other wallet' transaction.
Finally, there was a small bug in the accounts getbalance code-- generated coins with between
100 and 119 confirmations were not being counted in the balance of account "".
Diffstat (limited to 'rpc.cpp')
-rw-r--r-- | rpc.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -621,6 +621,30 @@ Value getbalance(const Array& params, bool fHelp) if (params.size() == 0) return ((double)GetBalance() / (double)COIN); + if (params[0].get_str() == "*") { + // Calculate total balance a different way from GetBalance() + // (GetBalance() sums up all unspent TxOuts) + // getbalance and getbalance '*' should always return the same number. + int64 nBalance = 0; + for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx& wtx = (*it).second; + int64 allGenerated, allFee; + allGenerated = allFee = 0; + string strSentAccount; + list<pair<string, int64> > listReceived; + list<pair<string, int64> > listSent; + wtx.GetAmounts(allGenerated, listReceived, listSent, allFee, strSentAccount); + foreach(const PAIRTYPE(string,int64)& r, listReceived) + nBalance += r.second; + foreach(const PAIRTYPE(string,int64)& r, listSent) + nBalance -= r.second; + nBalance -= allFee; + nBalance += allGenerated; + } + return (double)nBalance / (double)COIN; + } + string strAccount = AccountFromValue(params[0]); int nMinDepth = 1; if (params.size() > 1) |