Skip to content

Commit

Permalink
Fix getbalance discrepency
Browse files Browse the repository at this point in the history
Two changes:

Use IsConfirmed() instead of IsFinal(), so 'getbalance "*" 0' uses the same
'is this output spendable' criteria as 'getbalance'. Fixes issue #172.

And a tiny refactor to CWallet::GetBalance() (redundant call to IsFinal -- IsConfirmed
calls IsFinal).
getbalance with no arguments and 'getbalance "*" 0' could return different different results,
  • Loading branch information
gavinandresen committed Feb 4, 2013
1 parent 77b97d6 commit d758cb9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,12 @@ Value getbalance(const Array& params, bool fHelp)
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.
// getbalance and getbalance '*' 0 should return the same number
int64 nBalance = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (!wtx.IsFinal())
if (!wtx.IsConfirmed())
continue;

int64 allFee;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ int64 CWallet::GetBalance() const
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsFinal() && pcoin->IsConfirmed())
if (pcoin->IsConfirmed())
nTotal += pcoin->GetAvailableCredit();
}
}
Expand Down

0 comments on commit d758cb9

Please sign in to comment.