aboutsummaryrefslogtreecommitdiff
path: root/rpc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rpc.cpp')
-rw-r--r--rpc.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/rpc.cpp b/rpc.cpp
index f80b24ea72..055e0cf1e7 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -621,6 +621,36 @@ 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;
+ vector<string> vAccounts;
+ 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;
+ if (!count(vAccounts.begin(), vAccounts.end(), r.first))
+ vAccounts.push_back(r.first);
+ }
+ foreach(const PAIRTYPE(string,int64)& r, listSent)
+ nBalance -= r.second;
+ nBalance -= allFee;
+ nBalance += allGenerated;
+ }
+ printf("Found %d accounts\n", vAccounts.size());
+ return (double)nBalance / (double)COIN;
+ }
+
string strAccount = AccountFromValue(params[0]);
int nMinDepth = 1;
if (params.size() > 1)
@@ -1056,6 +1086,8 @@ Value listaccounts(const Array& params, bool fHelp)
foreach(const PAIRTYPE(string, int64)& r, listReceived)
if (mapAddressBook.count(r.first))
mapAccountBalances[mapAddressBook[r.first]] += r.second;
+ else
+ mapAccountBalances[""] += r.second;
}
}
}