aboutsummaryrefslogtreecommitdiff
path: root/src/rpcwallet.cpp
diff options
context:
space:
mode:
authorJaSK <temp@temp.temp>2014-04-08 15:23:50 +0200
committerJaSK <temp@temp.temp>2014-07-02 15:48:38 +0200
commitd4640d7d8c3ba373195d33ab75db9c8cb43f8806 (patch)
tree7966357313fbf458c8fadf1bd99f3f80e879e111 /src/rpcwallet.cpp
parentd2692f61164730322547871f2124de06ade0436b (diff)
Added argument to getbalance to include watchonly addresses and fixed errors in balance calculation.
Diffstat (limited to 'src/rpcwallet.cpp')
-rw-r--r--src/rpcwallet.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 38e96133b4..79b438d417 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -557,7 +557,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
}
-int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth)
+int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter = MINE_SPENDABLE)
{
int64_t nBalance = 0;
@@ -569,7 +569,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
continue;
int64_t nReceived, nSent, nFee;
- wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee);
+ wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
nBalance += nReceived;
@@ -582,18 +582,18 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
return nBalance;
}
-int64_t GetAccountBalance(const string& strAccount, int nMinDepth)
+int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter = MINE_SPENDABLE)
{
CWalletDB walletdb(pwalletMain->strWalletFile);
- return GetAccountBalance(walletdb, strAccount, nMinDepth);
+ return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
}
Value getbalance(const Array& params, bool fHelp)
{
- if (fHelp || params.size() > 2)
+ if (fHelp || params.size() > 3)
throw runtime_error(
- "getbalance ( \"account\" minconf )\n"
+ "getbalance ( \"account\" minconf includeWatchonly )\n"
"\nIf account is not specified, returns the server's total available balance.\n"
"If account is specified, returns the balance in the account.\n"
"Note that the account \"\" is not the same as leaving the parameter out.\n"
@@ -601,6 +601,7 @@ Value getbalance(const Array& params, bool fHelp)
"\nArguments:\n"
"1. \"account\" (string, optional) The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
+ "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n"
"\nResult:\n"
"amount (numeric) The total amount in btc received for this account.\n"
"\nExamples:\n"
@@ -620,8 +621,14 @@ Value getbalance(const Array& params, bool fHelp)
return ValueFromAmount(pwalletMain->GetBalance());
int nMinDepth = 1;
+ isminefilter filter = MINE_SPENDABLE;
if (params.size() > 1)
+ {
nMinDepth = params[1].get_int();
+ if(params.size() > 2)
+ if(params[2].get_bool())
+ filter = filter | MINE_WATCH_ONLY;
+ }
if (params[0].get_str() == "*") {
// Calculate total balance a different way from GetBalance()
@@ -638,7 +645,7 @@ Value getbalance(const Array& params, bool fHelp)
string strSentAccount;
list<pair<CTxDestination, int64_t> > listReceived;
list<pair<CTxDestination, int64_t> > listSent;
- wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount);
+ wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
if (wtx.GetDepthInMainChain() >= nMinDepth)
{
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
@@ -653,7 +660,7 @@ Value getbalance(const Array& params, bool fHelp)
string strAccount = AccountFromValue(params[0]);
- int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
+ int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
return ValueFromAmount(nBalance);
}