@@ -853,8 +853,9 @@ static UniValue getbalance(const JSONRPCRequest& request)
853
853
return NullUniValue;
854
854
}
855
855
856
- if (request.fHelp || (request.params .size () > 3 && IsDeprecatedRPCEnabled ( " accounts " )) || (request. params . size () != 0 && ! IsDeprecatedRPCEnabled ( " accounts " ) ))
856
+ if (request.fHelp || (request.params .size () > 3 ))
857
857
throw std::runtime_error (
858
+ (IsDeprecatedRPCEnabled (" accounts" ) ? std::string (
858
859
" getbalance ( \" account\" minconf include_watchonly )\n "
859
860
" \n If account is not specified, returns the server's total available balance.\n "
860
861
" The available balance is what the wallet considers currently spendable, and is\n "
@@ -876,8 +877,17 @@ static UniValue getbalance(const JSONRPCRequest& request)
876
877
" balances. In general, account balance calculation is not considered\n "
877
878
" reliable and has resulted in confusing outcomes, so it is recommended to\n "
878
879
" 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 "
881
891
" \n Result:\n "
882
892
" amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n "
883
893
" \n Examples:\n "
@@ -895,38 +905,35 @@ static UniValue getbalance(const JSONRPCRequest& request)
895
905
896
906
LOCK2 (cs_main, pwallet->cs_wallet );
897
907
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 ];
902
909
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 ()) {
914
925
915
926
const std::string& account_param = account_value.get_str ();
916
927
const std::string* account = account_param != " *" ? &account_param : nullptr ;
917
928
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
+ }
927
934
}
928
935
929
- return ValueFromAmount (pwallet->GetBalance ());
936
+ return ValueFromAmount (pwallet->GetBalance (filter, min_depth ));
930
937
}
931
938
932
939
static UniValue getunconfirmedbalance (const JSONRPCRequest &request)
@@ -4416,7 +4423,7 @@ static const CRPCCommand commands[] =
4416
4423
{ " wallet" , " dumpwallet" , &dumpwallet, {" filename" } },
4417
4424
{ " wallet" , " encryptwallet" , &encryptwallet, {" passphrase" } },
4418
4425
{ " wallet" , " getaddressinfo" , &getaddressinfo, {" address" } },
4419
- { " wallet" , " getbalance" , &getbalance, {" account" ," minconf" ," include_watchonly" } },
4426
+ { " wallet" , " getbalance" , &getbalance, {" account|dummy " ," minconf" ," include_watchonly" } },
4420
4427
{ " wallet" , " getnewaddress" , &getnewaddress, {" label|account" ," address_type" } },
4421
4428
{ " wallet" , " getrawchangeaddress" , &getrawchangeaddress, {" address_type" } },
4422
4429
{ " wallet" , " getreceivedbyaddress" , &getreceivedbyaddress, {" address" ," minconf" } },
0 commit comments