getbalance '*' was ignoring minconf param.

This commit is contained in:
Gavin Andresen 2011-04-18 20:40:50 -04:00
parent 6a76c60e6c
commit 72e962cf55
1 changed files with 10 additions and 11 deletions

21
rpc.cpp
View File

@ -640,40 +640,39 @@ Value getbalance(const Array& params, bool fHelp)
if (params.size() == 0) if (params.size() == 0)
return ValueFromAmount(GetBalance()); return ValueFromAmount(GetBalance());
int nMinDepth = 1;
if (params.size() > 1)
nMinDepth = params[1].get_int();
if (params[0].get_str() == "*") { if (params[0].get_str() == "*") {
// Calculate total balance a different way from GetBalance() // Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts) // (GetBalance() sums up all unspent TxOuts)
// getbalance and getbalance '*' should always return the same number. // getbalance and getbalance '*' should always return the same number.
int64 nBalance = 0; int64 nBalance = 0;
vector<string> vAccounts;
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
if (!wtx.IsFinal())
continue;
int64 allGeneratedImmature, allGeneratedMature, allFee; int64 allGeneratedImmature, allGeneratedMature, allFee;
allGeneratedImmature = allGeneratedMature = allFee = 0; allGeneratedImmature = allGeneratedMature = allFee = 0;
string strSentAccount; string strSentAccount;
list<pair<string, int64> > listReceived; list<pair<string, int64> > listReceived;
list<pair<string, int64> > listSent; list<pair<string, int64> > listSent;
wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount); wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
foreach(const PAIRTYPE(string,int64)& r, listReceived) if (wtx.GetDepthInMainChain() >= nMinDepth)
{ foreach(const PAIRTYPE(string,int64)& r, listReceived)
nBalance += r.second; nBalance += r.second;
if (!count(vAccounts.begin(), vAccounts.end(), r.first))
vAccounts.push_back(r.first);
}
foreach(const PAIRTYPE(string,int64)& r, listSent) foreach(const PAIRTYPE(string,int64)& r, listSent)
nBalance -= r.second; nBalance -= r.second;
nBalance -= allFee; nBalance -= allFee;
nBalance += allGeneratedMature; nBalance += allGeneratedMature;
} }
printf("Found %d accounts\n", vAccounts.size());
return ValueFromAmount(nBalance); return ValueFromAmount(nBalance);
} }
string strAccount = AccountFromValue(params[0]); string strAccount = AccountFromValue(params[0]);
int nMinDepth = 1;
if (params.size() > 1)
nMinDepth = params[1].get_int();
int64 nBalance = GetAccountBalance(strAccount, nMinDepth); int64 nBalance = GetAccountBalance(strAccount, nMinDepth);