@@ -853,8 +853,9 @@ static UniValue getbalance(const JSONRPCRequest& request)
853853 return NullUniValue;
854854 }
855855
856- if (request.fHelp || (request.params .size () > 3 && IsDeprecatedRPCEnabled ( " accounts " )) || (request. params . size () != 0 && ! IsDeprecatedRPCEnabled ( " accounts " ) ))
856+ if (request.fHelp || (request.params .size () > 3 ))
857857 throw std::runtime_error (
858+ (IsDeprecatedRPCEnabled (" accounts" ) ? std::string (
858859 " getbalance ( \" account\" minconf include_watchonly )\n "
859860 " \n If account is not specified, returns the server's total available balance.\n "
860861 " The available balance is what the wallet considers currently spendable, and is\n "
@@ -876,8 +877,17 @@ static UniValue getbalance(const JSONRPCRequest& request)
876877 " balances. In general, account balance calculation is not considered\n "
877878 " reliable and has resulted in confusing outcomes, so it is recommended to\n "
878879 " avoid passing this argument.\n "
879- " 2. minconf (numeric, optional, default=1) DEPRECATED. Only valid when an account is specified. This argument will be removed in V0.18. To use this deprecated argument, start bitcoind with -deprecatedrpc=accounts. Only include transactions confirmed at least this many times.\n "
880- " 3. include_watchonly (bool, optional, default=false) DEPRECATED. Only valid when an account is specified. This argument will be removed in V0.18. To use this deprecated argument, start bitcoind with -deprecatedrpc=accounts. Also include balance in watch-only addresses (see 'importaddress')\n "
880+ " 2. minconf (numeric, optional) Only include transactions confirmed at least this many times. \n "
881+ " The default is 1 if an account is provided or 0 if no account is provided\n " )
882+ : std::string (
883+ " getbalance ( \" (dummy)\" minconf include_watchonly )\n "
884+ " \n Returns the total available balance.\n "
885+ " The available balance is what the wallet considers currently spendable, and is\n "
886+ " thus affected by options which limit spendability such as -spendzeroconfchange.\n "
887+ " \n Arguments:\n "
888+ " 1. (dummy) (string, optional) Remains for backward compatibility. Must be excluded or set to \" *\" .\n "
889+ " 2. minconf (numeric, optional, default=0) Only include transactions confirmed at least this many times.\n " )) +
890+ " 3. include_watchonly (bool, optional, default=false) Also include balance in watch-only addresses (see 'importaddress')\n "
881891 " \n Result:\n "
882892 " amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n "
883893 " \n Examples:\n "
@@ -895,38 +905,35 @@ static UniValue getbalance(const JSONRPCRequest& request)
895905
896906 LOCK2 (cs_main, pwallet->cs_wallet );
897907
898- if (IsDeprecatedRPCEnabled (" accounts" )) {
899- const UniValue& account_value = request.params [0 ];
900- const UniValue& minconf = request.params [1 ];
901- const UniValue& include_watchonly = request.params [2 ];
908+ const UniValue& account_value = request.params [0 ];
902909
903- if (account_value.isNull ()) {
904- if (!minconf.isNull ()) {
905- throw JSONRPCError (RPC_INVALID_PARAMETER,
906- " getbalance minconf option is only currently supported if an account is specified" );
907- }
908- if (!include_watchonly.isNull ()) {
909- throw JSONRPCError (RPC_INVALID_PARAMETER,
910- " getbalance include_watchonly option is only currently supported if an account is specified" );
911- }
912- return ValueFromAmount (pwallet->GetBalance ());
913- }
910+ int min_depth = 0 ;
911+ if (IsDeprecatedRPCEnabled (" accounts" ) && !account_value.isNull ()) {
912+ // Default min_depth to 1 when an account is provided.
913+ min_depth = 1 ;
914+ }
915+ if (!request.params [1 ].isNull ()) {
916+ min_depth = request.params [1 ].get_int ();
917+ }
918+
919+ isminefilter filter = ISMINE_SPENDABLE;
920+ if (!request.params [2 ].isNull () && request.params [2 ].get_bool ()) {
921+ filter = filter | ISMINE_WATCH_ONLY;
922+ }
923+
924+ if (!account_value.isNull ()) {
914925
915926 const std::string& account_param = account_value.get_str ();
916927 const std::string* account = account_param != " *" ? &account_param : nullptr ;
917928
918- int nMinDepth = 1 ;
919- if (!minconf.isNull ())
920- nMinDepth = minconf.get_int ();
921- isminefilter filter = ISMINE_SPENDABLE;
922- if (!include_watchonly.isNull ())
923- if (include_watchonly.get_bool ())
924- filter = filter | ISMINE_WATCH_ONLY;
925-
926- return ValueFromAmount (pwallet->GetLegacyBalance (filter, nMinDepth, account));
929+ if (!IsDeprecatedRPCEnabled (" accounts" ) && account_param != " *" ) {
930+ throw JSONRPCError (RPC_METHOD_DEPRECATED, " dummy first argument must be excluded or set to \" *\" ." );
931+ } else if (IsDeprecatedRPCEnabled (" accounts" )) {
932+ return ValueFromAmount (pwallet->GetLegacyBalance (filter, min_depth, account));
933+ }
927934 }
928935
929- return ValueFromAmount (pwallet->GetBalance ());
936+ return ValueFromAmount (pwallet->GetBalance (filter, min_depth ));
930937}
931938
932939static UniValue getunconfirmedbalance (const JSONRPCRequest &request)
@@ -4416,7 +4423,7 @@ static const CRPCCommand commands[] =
44164423 { " wallet" , " dumpwallet" , &dumpwallet, {" filename" } },
44174424 { " wallet" , " encryptwallet" , &encryptwallet, {" passphrase" } },
44184425 { " wallet" , " getaddressinfo" , &getaddressinfo, {" address" } },
4419- { " wallet" , " getbalance" , &getbalance, {" account" ," minconf" ," include_watchonly" } },
4426+ { " wallet" , " getbalance" , &getbalance, {" account|dummy " ," minconf" ," include_watchonly" } },
44204427 { " wallet" , " getnewaddress" , &getnewaddress, {" label|account" ," address_type" } },
44214428 { " wallet" , " getrawchangeaddress" , &getrawchangeaddress, {" address_type" } },
44224429 { " wallet" , " getreceivedbyaddress" , &getreceivedbyaddress, {" address" ," minconf" } },
0 commit comments