aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-04-18 20:40:50 -0400
committerGavin Andresen <gavinandresen@gmail.com>2011-04-18 20:57:13 -0400
commit72e962cf5589d708a6ba636c07ab7db7165ba965 (patch)
treebcf646172662157263a94bcfcd44e3569ec9b72d
parent6a76c60e6c4c21c6355c5580f9f770fcc9f978ef (diff)
getbalance '*' was ignoring minconf param.
-rw-r--r--rpc.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/rpc.cpp b/rpc.cpp
index 0866bb50ed..90e7f15a91 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -640,40 +640,39 @@ Value getbalance(const Array& params, bool fHelp)
if (params.size() == 0)
return ValueFromAmount(GetBalance());
+ int nMinDepth = 1;
+ if (params.size() > 1)
+ nMinDepth = params[1].get_int();
+
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;
- vector<string> vAccounts;
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
+ if (!wtx.IsFinal())
+ continue;
+
int64 allGeneratedImmature, allGeneratedMature, allFee;
allGeneratedImmature = allGeneratedMature = allFee = 0;
string strSentAccount;
list<pair<string, int64> > listReceived;
list<pair<string, int64> > listSent;
wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
- foreach(const PAIRTYPE(string,int64)& r, listReceived)
- {
- nBalance += r.second;
- if (!count(vAccounts.begin(), vAccounts.end(), r.first))
- vAccounts.push_back(r.first);
- }
+ if (wtx.GetDepthInMainChain() >= nMinDepth)
+ foreach(const PAIRTYPE(string,int64)& r, listReceived)
+ nBalance += r.second;
foreach(const PAIRTYPE(string,int64)& r, listSent)
nBalance -= r.second;
nBalance -= allFee;
nBalance += allGeneratedMature;
}
- printf("Found %d accounts\n", vAccounts.size());
return ValueFromAmount(nBalance);
}
string strAccount = AccountFromValue(params[0]);
- int nMinDepth = 1;
- if (params.size() > 1)
- nMinDepth = params[1].get_int();
int64 nBalance = GetAccountBalance(strAccount, nMinDepth);