Skip to content

Commit e666efc

Browse files
committed
Get rid of redundant RPC params.size() checks
No change in behavior.
1 parent c2704ec commit e666efc

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,11 +1489,11 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
14891489
const CBlockIndex* pindex;
14901490
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
14911491

1492-
if (request.params.size() > 0 && !request.params[0].isNull()) {
1492+
if (!request.params[0].isNull()) {
14931493
blockcount = request.params[0].get_int();
14941494
}
14951495

1496-
bool havehash = request.params.size() > 1 && !request.params[1].isNull();
1496+
bool havehash = !request.params[1].isNull();
14971497
uint256 hash;
14981498
if (havehash) {
14991499
hash = uint256S(request.params[1].get_str());

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
842842
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
843843
unsigned int conf_target = ParseConfirmTarget(request.params[0]);
844844
bool conservative = true;
845-
if (request.params.size() > 1 && !request.params[1].isNull()) {
845+
if (!request.params[1].isNull()) {
846846
FeeEstimateMode fee_mode;
847847
if (!FeeModeFromString(request.params[1].get_str(), fee_mode)) {
848848
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");

src/rpc/misc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ UniValue getmemoryinfo(const JSONRPCRequest& request)
552552
+ HelpExampleRpc("getmemoryinfo", "")
553553
);
554554

555-
std::string mode = (request.params.size() < 1 || request.params[0].isNull()) ? "stats" : request.params[0].get_str();
555+
std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str();
556556
if (mode == "stats") {
557557
UniValue obj(UniValue::VOBJ);
558558
obj.push_back(Pair("locked", RPCLockedMemoryInfo()));
@@ -603,11 +603,11 @@ UniValue logging(const JSONRPCRequest& request)
603603
}
604604

605605
uint32_t originalLogCategories = logCategories;
606-
if (request.params.size() > 0 && request.params[0].isArray()) {
606+
if (request.params[0].isArray()) {
607607
logCategories |= getCategoryMask(request.params[0]);
608608
}
609609

610-
if (request.params.size() > 1 && request.params[1].isArray()) {
610+
if (request.params[1].isArray()) {
611611
logCategories &= ~getCategoryMask(request.params[1]);
612612
}
613613

src/rpc/net.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ UniValue disconnectnode(const JSONRPCRequest& request)
258258

259259
bool success;
260260
const UniValue &address_arg = request.params[0];
261-
const UniValue &id_arg = request.params.size() < 2 ? NullUniValue : request.params[1];
261+
const UniValue &id_arg = request.params[1];
262262

263263
if (!address_arg.isNull() && id_arg.isNull()) {
264264
/* handle disconnect-by-address */
@@ -311,7 +311,7 @@ UniValue getaddednodeinfo(const JSONRPCRequest& request)
311311

312312
std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo();
313313

314-
if (request.params.size() == 1 && !request.params[0].isNull()) {
314+
if (!request.params[0].isNull()) {
315315
bool found = false;
316316
for (const AddedNodeInfo& info : vInfo) {
317317
if (info.strAddedNode == request.params[0].get_str()) {
@@ -534,11 +534,11 @@ UniValue setban(const JSONRPCRequest& request)
534534
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
535535

536536
int64_t banTime = 0; //use standard bantime if not specified
537-
if (request.params.size() >= 3 && !request.params[2].isNull())
537+
if (!request.params[2].isNull())
538538
banTime = request.params[2].get_int64();
539539

540540
bool absolute = false;
541-
if (request.params.size() == 4 && request.params[3].isTrue())
541+
if (request.params[3].isTrue())
542542
absolute = true;
543543

544544
isSubnet ? g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
339339

340340
CMutableTransaction rawTx;
341341

342-
if (request.params.size() > 2 && !request.params[2].isNull()) {
342+
if (!request.params[2].isNull()) {
343343
int64_t nLockTime = request.params[2].get_int64();
344344
if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
345345
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
346346
rawTx.nLockTime = nLockTime;
347347
}
348348

349-
bool rbfOptIn = request.params.size() > 3 ? request.params[3].isTrue() : false;
349+
bool rbfOptIn = request.params[3].isTrue();
350350

351351
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
352352
const UniValue& input = inputs[idx];
@@ -735,7 +735,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
735735

736736
bool fGivenKeys = false;
737737
CBasicKeyStore tempKeystore;
738-
if (request.params.size() > 2 && !request.params[2].isNull()) {
738+
if (!request.params[2].isNull()) {
739739
fGivenKeys = true;
740740
UniValue keys = request.params[2].get_array();
741741
for (unsigned int idx = 0; idx < keys.size(); idx++) {
@@ -757,7 +757,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
757757
#endif
758758

759759
// Add previous txouts given in the RPC call:
760-
if (request.params.size() > 1 && !request.params[1].isNull()) {
760+
if (!request.params[1].isNull()) {
761761
UniValue prevTxs = request.params[1].get_array();
762762
for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
763763
const UniValue& p = prevTxs[idx];
@@ -828,7 +828,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
828828
#endif
829829

830830
int nHashType = SIGHASH_ALL;
831-
if (request.params.size() > 3 && !request.params[3].isNull()) {
831+
if (!request.params[3].isNull()) {
832832
static std::map<std::string, int> mapSigHashValues = {
833833
{std::string("ALL"), int(SIGHASH_ALL)},
834834
{std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},

src/wallet/rpcwallet.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,26 +462,26 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
462462

463463
// Wallet comments
464464
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())
466466
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())
468468
wtx.mapValue["to"] = request.params[3].get_str();
469469

470470
bool fSubtractFeeFromAmount = false;
471-
if (request.params.size() > 4 && !request.params[4].isNull()) {
471+
if (!request.params[4].isNull()) {
472472
fSubtractFeeFromAmount = request.params[4].get_bool();
473473
}
474474

475475
CCoinControl coin_control;
476-
if (request.params.size() > 5 && !request.params[5].isNull()) {
476+
if (!request.params[5].isNull()) {
477477
coin_control.signalRbf = request.params[5].get_bool();
478478
}
479479

480-
if (request.params.size() > 6 && !request.params[6].isNull()) {
480+
if (!request.params[6].isNull()) {
481481
coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]);
482482
}
483483

484-
if (request.params.size() > 7 && !request.params[7].isNull()) {
484+
if (!request.params[7].isNull()) {
485485
if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) {
486486
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
487487
}
@@ -904,9 +904,9 @@ UniValue sendfrom(const JSONRPCRequest& request)
904904

905905
CWalletTx wtx;
906906
wtx.strFromAccount = strAccount;
907-
if (request.params.size() > 4 && !request.params[4].isNull() && !request.params[4].get_str().empty())
907+
if (!request.params[4].isNull() && !request.params[4].get_str().empty())
908908
wtx.mapValue["comment"] = request.params[4].get_str();
909-
if (request.params.size() > 5 && !request.params[5].isNull() && !request.params[5].get_str().empty())
909+
if (!request.params[5].isNull() && !request.params[5].get_str().empty())
910910
wtx.mapValue["to"] = request.params[5].get_str();
911911

912912
EnsureWalletIsUnlocked(pwallet);
@@ -986,23 +986,23 @@ UniValue sendmany(const JSONRPCRequest& request)
986986

987987
CWalletTx wtx;
988988
wtx.strFromAccount = strAccount;
989-
if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty())
989+
if (!request.params[3].isNull() && !request.params[3].get_str().empty())
990990
wtx.mapValue["comment"] = request.params[3].get_str();
991991

992992
UniValue subtractFeeFromAmount(UniValue::VARR);
993-
if (request.params.size() > 4 && !request.params[4].isNull())
993+
if (!request.params[4].isNull())
994994
subtractFeeFromAmount = request.params[4].get_array();
995995

996996
CCoinControl coin_control;
997-
if (request.params.size() > 5 && !request.params[5].isNull()) {
997+
if (!request.params[5].isNull()) {
998998
coin_control.signalRbf = request.params[5].get_bool();
999999
}
10001000

1001-
if (request.params.size() > 6 && !request.params[6].isNull()) {
1001+
if (!request.params[6].isNull()) {
10021002
coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]);
10031003
}
10041004

1005-
if (request.params.size() > 7 && !request.params[7].isNull()) {
1005+
if (!request.params[7].isNull()) {
10061006
if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) {
10071007
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
10081008
}
@@ -2670,19 +2670,19 @@ UniValue listunspent(const JSONRPCRequest& request)
26702670
);
26712671

26722672
int nMinDepth = 1;
2673-
if (request.params.size() > 0 && !request.params[0].isNull()) {
2673+
if (!request.params[0].isNull()) {
26742674
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
26752675
nMinDepth = request.params[0].get_int();
26762676
}
26772677

26782678
int nMaxDepth = 9999999;
2679-
if (request.params.size() > 1 && !request.params[1].isNull()) {
2679+
if (!request.params[1].isNull()) {
26802680
RPCTypeCheckArgument(request.params[1], UniValue::VNUM);
26812681
nMaxDepth = request.params[1].get_int();
26822682
}
26832683

26842684
std::set<CBitcoinAddress> setAddress;
2685-
if (request.params.size() > 2 && !request.params[2].isNull()) {
2685+
if (!request.params[2].isNull()) {
26862686
RPCTypeCheckArgument(request.params[2], UniValue::VARR);
26872687
UniValue inputs = request.params[2].get_array();
26882688
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
@@ -2697,7 +2697,7 @@ UniValue listunspent(const JSONRPCRequest& request)
26972697
}
26982698

26992699
bool include_unsafe = true;
2700-
if (request.params.size() > 3 && !request.params[3].isNull()) {
2700+
if (!request.params[3].isNull()) {
27012701
RPCTypeCheckArgument(request.params[3], UniValue::VBOOL);
27022702
include_unsafe = request.params[3].get_bool();
27032703
}
@@ -3112,7 +3112,7 @@ UniValue generate(const JSONRPCRequest& request)
31123112

31133113
int num_generate = request.params[0].get_int();
31143114
uint64_t max_tries = 1000000;
3115-
if (request.params.size() > 1 && !request.params[1].isNull()) {
3115+
if (!request.params[1].isNull()) {
31163116
max_tries = request.params[1].get_int();
31173117
}
31183118

0 commit comments

Comments
 (0)