@@ -280,7 +280,7 @@ UniValue setaccount(const JSONRPCRequest& request)
280
280
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid Bitcoin address" );
281
281
282
282
std::string strAccount;
283
- if (request.params . size () > 1 )
283
+ if (! request.params [ 1 ]. isNull () )
284
284
strAccount = AccountFromValue (request.params [1 ]);
285
285
286
286
// Only add the account if the address is yours.
@@ -462,26 +462,26 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
462
462
463
463
// Wallet comments
464
464
CWalletTx wtx;
465
- if (request. params . size () > 2 && !request.params [2 ].isNull () && !request.params [2 ].get_str ().empty ())
465
+ if (!request.params [2 ].isNull () && !request.params [2 ].get_str ().empty ())
466
466
wtx.mapValue [" comment" ] = request.params [2 ].get_str ();
467
- if (request. params . size () > 3 && !request.params [3 ].isNull () && !request.params [3 ].get_str ().empty ())
467
+ if (!request.params [3 ].isNull () && !request.params [3 ].get_str ().empty ())
468
468
wtx.mapValue [" to" ] = request.params [3 ].get_str ();
469
469
470
470
bool fSubtractFeeFromAmount = false ;
471
- if (request. params . size () > 4 && !request.params [4 ].isNull ()) {
471
+ if (!request.params [4 ].isNull ()) {
472
472
fSubtractFeeFromAmount = request.params [4 ].get_bool ();
473
473
}
474
474
475
475
CCoinControl coin_control;
476
- if (request. params . size () > 5 && !request.params [5 ].isNull ()) {
476
+ if (!request.params [5 ].isNull ()) {
477
477
coin_control.signalRbf = request.params [5 ].get_bool ();
478
478
}
479
479
480
- if (request. params . size () > 6 && !request.params [6 ].isNull ()) {
480
+ if (!request.params [6 ].isNull ()) {
481
481
coin_control.m_confirm_target = ParseConfirmTarget (request.params [6 ]);
482
482
}
483
483
484
- if (request. params . size () > 7 && !request.params [7 ].isNull ()) {
484
+ if (!request.params [7 ].isNull ()) {
485
485
if (!FeeModeFromString (request.params [7 ].get_str (), coin_control.m_fee_mode )) {
486
486
throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid estimate_mode parameter" );
487
487
}
@@ -768,18 +768,31 @@ UniValue getbalance(const JSONRPCRequest& request)
768
768
769
769
LOCK2 (cs_main, pwallet->cs_wallet );
770
770
771
- if (request.params .size () == 0 )
772
- return ValueFromAmount (pwallet->GetBalance ());
771
+ const UniValue& account_value = request.params [0 ];
772
+ const UniValue& minconf = request.params [1 ];
773
+ const UniValue& include_watchonly = request.params [2 ];
774
+
775
+ if (account_value.isNull ()) {
776
+ if (!minconf.isNull ()) {
777
+ throw JSONRPCError (RPC_INVALID_PARAMETER,
778
+ " getbalance minconf option is only currently supported if an account is specified" );
779
+ }
780
+ if (!include_watchonly.isNull ()) {
781
+ throw JSONRPCError (RPC_INVALID_PARAMETER,
782
+ " getbalance include_watchonly option is only currently supported if an account is specified" );
783
+ }
784
+ return ValueFromAmount (pwallet->GetBalance ());
785
+ }
773
786
774
- const std::string& account_param = request. params [ 0 ] .get_str ();
787
+ const std::string& account_param = account_value .get_str ();
775
788
const std::string* account = account_param != " *" ? &account_param : nullptr ;
776
789
777
790
int nMinDepth = 1 ;
778
- if (!request. params [ 1 ] .isNull ())
779
- nMinDepth = request. params [ 1 ] .get_int ();
791
+ if (!minconf .isNull ())
792
+ nMinDepth = minconf .get_int ();
780
793
isminefilter filter = ISMINE_SPENDABLE;
781
- if (!request. params [ 2 ] .isNull ())
782
- if (request. params [ 2 ] .get_bool ())
794
+ if (!include_watchonly .isNull ())
795
+ if (include_watchonly .get_bool ())
783
796
filter = filter | ISMINE_WATCH_ONLY;
784
797
785
798
return ValueFromAmount (pwallet->GetLegacyBalance (filter, nMinDepth, account));
@@ -838,11 +851,11 @@ UniValue movecmd(const JSONRPCRequest& request)
838
851
CAmount nAmount = AmountFromValue (request.params [2 ]);
839
852
if (nAmount <= 0 )
840
853
throw JSONRPCError (RPC_TYPE_ERROR, " Invalid amount for send" );
841
- if (request.params . size () > 3 )
854
+ if (! request.params [ 3 ]. isNull () )
842
855
// unused parameter, used to be nMinDepth, keep type-checking it though
843
856
(void )request.params [3 ].get_int ();
844
857
std::string strComment;
845
- if (request.params . size () > 4 )
858
+ if (! request.params [ 4 ]. isNull () )
846
859
strComment = request.params [4 ].get_str ();
847
860
848
861
if (!pwallet->AccountMove (strFrom, strTo, nAmount, strComment)) {
@@ -899,14 +912,14 @@ UniValue sendfrom(const JSONRPCRequest& request)
899
912
if (nAmount <= 0 )
900
913
throw JSONRPCError (RPC_TYPE_ERROR, " Invalid amount for send" );
901
914
int nMinDepth = 1 ;
902
- if (request.params . size () > 3 )
915
+ if (! request.params [ 3 ]. isNull () )
903
916
nMinDepth = request.params [3 ].get_int ();
904
917
905
918
CWalletTx wtx;
906
919
wtx.strFromAccount = strAccount;
907
- if (request. params . size () > 4 && !request.params [4 ].isNull () && !request.params [4 ].get_str ().empty ())
920
+ if (!request.params [4 ].isNull () && !request.params [4 ].get_str ().empty ())
908
921
wtx.mapValue [" comment" ] = request.params [4 ].get_str ();
909
- if (request. params . size () > 5 && !request.params [5 ].isNull () && !request.params [5 ].get_str ().empty ())
922
+ if (!request.params [5 ].isNull () && !request.params [5 ].get_str ().empty ())
910
923
wtx.mapValue [" to" ] = request.params [5 ].get_str ();
911
924
912
925
EnsureWalletIsUnlocked (pwallet);
@@ -986,23 +999,23 @@ UniValue sendmany(const JSONRPCRequest& request)
986
999
987
1000
CWalletTx wtx;
988
1001
wtx.strFromAccount = strAccount;
989
- if (request. params . size () > 3 && !request.params [3 ].isNull () && !request.params [3 ].get_str ().empty ())
1002
+ if (!request.params [3 ].isNull () && !request.params [3 ].get_str ().empty ())
990
1003
wtx.mapValue [" comment" ] = request.params [3 ].get_str ();
991
1004
992
1005
UniValue subtractFeeFromAmount (UniValue::VARR);
993
- if (request. params . size () > 4 && !request.params [4 ].isNull ())
1006
+ if (!request.params [4 ].isNull ())
994
1007
subtractFeeFromAmount = request.params [4 ].get_array ();
995
1008
996
1009
CCoinControl coin_control;
997
- if (request. params . size () > 5 && !request.params [5 ].isNull ()) {
1010
+ if (!request.params [5 ].isNull ()) {
998
1011
coin_control.signalRbf = request.params [5 ].get_bool ();
999
1012
}
1000
1013
1001
- if (request. params . size () > 6 && !request.params [6 ].isNull ()) {
1014
+ if (!request.params [6 ].isNull ()) {
1002
1015
coin_control.m_confirm_target = ParseConfirmTarget (request.params [6 ]);
1003
1016
}
1004
1017
1005
- if (request. params . size () > 7 && !request.params [7 ].isNull ()) {
1018
+ if (!request.params [7 ].isNull ()) {
1006
1019
if (!FeeModeFromString (request.params [7 ].get_str (), coin_control.m_fee_mode )) {
1007
1020
throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid estimate_mode parameter" );
1008
1021
}
@@ -1105,7 +1118,7 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
1105
1118
LOCK2 (cs_main, pwallet->cs_wallet );
1106
1119
1107
1120
std::string strAccount;
1108
- if (request.params . size () > 2 )
1121
+ if (! request.params [ 2 ]. isNull () )
1109
1122
strAccount = AccountFromValue (request.params [2 ]);
1110
1123
1111
1124
// Construct using pay-to-script-hash:
@@ -1711,10 +1724,10 @@ UniValue listaccounts(const JSONRPCRequest& request)
1711
1724
LOCK2 (cs_main, pwallet->cs_wallet );
1712
1725
1713
1726
int nMinDepth = 1 ;
1714
- if (request.params . size () > 0 )
1727
+ if (! request.params [ 0 ]. isNull () )
1715
1728
nMinDepth = request.params [0 ].get_int ();
1716
1729
isminefilter includeWatchonly = ISMINE_SPENDABLE;
1717
- if (request.params . size () > 1 )
1730
+ if (! request.params [ 1 ]. isNull () )
1718
1731
if (request.params [1 ].get_bool ())
1719
1732
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
1720
1733
@@ -2363,19 +2376,18 @@ UniValue lockunspent(const JSONRPCRequest& request)
2363
2376
2364
2377
LOCK2 (cs_main, pwallet->cs_wallet );
2365
2378
2366
- if (request.params .size () == 1 )
2367
- RPCTypeCheck (request.params , {UniValue::VBOOL});
2368
- else
2369
- RPCTypeCheck (request.params , {UniValue::VBOOL, UniValue::VARR});
2379
+ RPCTypeCheckArgument (request.params [0 ], UniValue::VBOOL);
2370
2380
2371
2381
bool fUnlock = request.params [0 ].get_bool ();
2372
2382
2373
- if (request.params . size () == 1 ) {
2383
+ if (request.params [ 1 ]. isNull () ) {
2374
2384
if (fUnlock )
2375
2385
pwallet->UnlockAllCoins ();
2376
2386
return true ;
2377
2387
}
2378
2388
2389
+ RPCTypeCheckArgument (request.params [1 ], UniValue::VARR);
2390
+
2379
2391
UniValue outputs = request.params [1 ].get_array ();
2380
2392
for (unsigned int idx = 0 ; idx < outputs.size (); idx++) {
2381
2393
const UniValue& output = outputs[idx];
@@ -2672,19 +2684,19 @@ UniValue listunspent(const JSONRPCRequest& request)
2672
2684
);
2673
2685
2674
2686
int nMinDepth = 1 ;
2675
- if (request. params . size () > 0 && !request.params [0 ].isNull ()) {
2687
+ if (!request.params [0 ].isNull ()) {
2676
2688
RPCTypeCheckArgument (request.params [0 ], UniValue::VNUM);
2677
2689
nMinDepth = request.params [0 ].get_int ();
2678
2690
}
2679
2691
2680
2692
int nMaxDepth = 9999999 ;
2681
- if (request. params . size () > 1 && !request.params [1 ].isNull ()) {
2693
+ if (!request.params [1 ].isNull ()) {
2682
2694
RPCTypeCheckArgument (request.params [1 ], UniValue::VNUM);
2683
2695
nMaxDepth = request.params [1 ].get_int ();
2684
2696
}
2685
2697
2686
2698
std::set<CBitcoinAddress> setAddress;
2687
- if (request. params . size () > 2 && !request.params [2 ].isNull ()) {
2699
+ if (!request.params [2 ].isNull ()) {
2688
2700
RPCTypeCheckArgument (request.params [2 ], UniValue::VARR);
2689
2701
UniValue inputs = request.params [2 ].get_array ();
2690
2702
for (unsigned int idx = 0 ; idx < inputs.size (); idx++) {
@@ -2699,7 +2711,7 @@ UniValue listunspent(const JSONRPCRequest& request)
2699
2711
}
2700
2712
2701
2713
bool include_unsafe = true ;
2702
- if (request. params . size () > 3 && !request.params [3 ].isNull ()) {
2714
+ if (!request.params [3 ].isNull ()) {
2703
2715
RPCTypeCheckArgument (request.params [3 ], UniValue::VBOOL);
2704
2716
include_unsafe = request.params [3 ].get_bool ();
2705
2717
}
@@ -3114,7 +3126,7 @@ UniValue generate(const JSONRPCRequest& request)
3114
3126
3115
3127
int num_generate = request.params [0 ].get_int ();
3116
3128
uint64_t max_tries = 1000000 ;
3117
- if (request. params . size () > 1 && !request.params [1 ].isNull ()) {
3129
+ if (!request.params [1 ].isNull ()) {
3118
3130
max_tries = request.params [1 ].get_int ();
3119
3131
}
3120
3132
0 commit comments