From 72e962cf5589d708a6ba636c07ab7db7165ba965 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Mon, 18 Apr 2011 20:40:50 -0400 Subject: [PATCH] getbalance '*' was ignoring minconf param. --- rpc.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/rpc.cpp b/rpc.cpp index 0866bb50..90e7f15a 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 vAccounts; for (map::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 > listReceived; list > 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);