diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index ea5ca8e0..d96b4783 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -49,6 +49,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listtransactions", 1 }, { "listtransactions", 2 }, { "listaccounts", 0 }, + { "listaccounts", 1 }, { "walletpassphrase", 1 }, { "getblocktemplate", 0 }, { "listsinceblock", 1 }, diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 79b438d4..d52a4bc5 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1302,12 +1302,13 @@ Value listtransactions(const Array& params, bool fHelp) Value listaccounts(const Array& params, bool fHelp) { - if (fHelp || params.size() > 1) + if (fHelp || params.size() > 2) throw runtime_error( - "listaccounts ( minconf )\n" + "listaccounts ( minconf includeWatchonly)\n" "\nReturns Object that has account names as keys, account balances as values.\n" "\nArguments:\n" - "1. minconf (numeric, optional, default=1) Only onclude transactions with at least this many confirmations\n" + "1. minconf (numeric, optional, default=1) Only onclude transactions with at least this many confirmations\n" + "2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n" "\nResult:\n" "{ (json object where keys are account names, and values are numeric balances\n" " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n" @@ -1325,12 +1326,18 @@ Value listaccounts(const Array& params, bool fHelp) ); int nMinDepth = 1; + isminefilter includeWatchonly = MINE_SPENDABLE; if (params.size() > 0) + { nMinDepth = params[0].get_int(); + if(params.size() > 1) + if(params[1].get_bool()) + includeWatchonly = includeWatchonly | MINE_WATCH_ONLY; + } map mapAccountBalances; BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) { - if (IsMine(*pwalletMain, entry.first)) // This address belongs to me + if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me mapAccountBalances[entry.second.name] = 0; } @@ -1344,7 +1351,7 @@ Value listaccounts(const Array& params, bool fHelp) int nDepth = wtx.GetDepthInMainChain(); if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) continue; - wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); + wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly); mapAccountBalances[strSentAccount] -= nFee; BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent) mapAccountBalances[strSentAccount] -= s.second;