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 "".
This commit is contained in:
24
rpc.cpp
24
rpc.cpp
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user