diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -227,7 +227,7 @@ } int timeout = 0; - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { timeout = request.params[0].get_int(); } @@ -285,7 +285,7 @@ uint256 hash = uint256S(request.params[0].get_str()); - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { timeout = request.params[1].get_int(); } @@ -339,7 +339,7 @@ int height = request.params[0].get_int(); - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { timeout = request.params[1].get_int(); } @@ -497,7 +497,7 @@ } bool fVerbose = false; - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { fVerbose = request.params[0].get_bool(); } @@ -534,7 +534,7 @@ } bool fVerbose = false; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { fVerbose = request.params[1].get_bool(); } @@ -604,7 +604,9 @@ } bool fVerbose = false; - if (request.params.size() > 1) fVerbose = request.params[1].get_bool(); + if (!request.params[1].isNull()) { + fVerbose = request.params[1].get_bool(); + } uint256 hash = ParseHashV(request.params[0], "parameter 1"); @@ -755,7 +757,7 @@ uint256 hash(uint256S(strHash)); bool fVerbose = true; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { fVerbose = request.params[1].get_bool(); } @@ -847,7 +849,7 @@ uint256 hash(uint256S(strHash)); int verbosity = 1; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { if (request.params[1].isNum()) { verbosity = request.params[1].get_int(); } else { @@ -1120,7 +1122,7 @@ int n = request.params[1].get_int(); COutPoint out(hash, n); bool fMempool = true; - if (request.params.size() > 2) { + if (!request.params[2].isNull()) { fMempool = request.params[2].get_bool(); } @@ -1179,10 +1181,10 @@ LOCK(cs_main); - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { nCheckLevel = request.params[0].get_int(); } - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { nCheckDepth = request.params[1].get_int(); } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -108,8 +108,8 @@ LOCK(cs_main); return GetNetworkHashPS( - request.params.size() > 0 ? request.params[0].get_int() : 120, - request.params.size() > 1 ? request.params[1].get_int() : -1); + !request.params[0].isNull() ? request.params[0].get_int() : 120, + !request.params[1].isNull() ? request.params[1].get_int() : -1); } UniValue generateBlocks(const Config &config, @@ -203,7 +203,7 @@ int nGenerate = request.params[0].get_int(); uint64_t nMaxTries = 1000000; - if (request.params.size() > 2) { + if (!request.params[2].isNull()) { nMaxTries = request.params[2].get_int(); } @@ -446,7 +446,7 @@ std::string strMode = "template"; UniValue lpval = NullUniValue; std::set setClientRules; - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { const UniValue &oparam = request.params[0].get_obj(); const UniValue &modeval = find_value(oparam, "mode"); if (modeval.isStr()) { diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -385,7 +385,7 @@ std::vector vInfo = g_connman->GetAddedNodeInfo(); - if (request.params.size() == 1) { + if (request.params.size() == 1 && !request.params[0].isNull()) { bool found = false; for (const AddedNodeInfo &info : vInfo) { if (info.strAddedNode == request.params[0].get_str()) { diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -154,7 +154,7 @@ // Accept either a bool (true) or a num (>=1) to indicate verbose output. bool fVerbose = false; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { if (request.params[1].isNum()) { if (request.params[1].get_int() != 0) { fVerbose = true; @@ -249,7 +249,7 @@ CBlockIndex *pblockindex = nullptr; uint256 hashBlock; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { hashBlock = uint256S(request.params[1].get_str()); if (!mapBlockIndex.count(hashBlock)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -107,13 +107,13 @@ std::string strSecret = request.params[0].get_str(); std::string strLabel = ""; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { strLabel = request.params[1].get_str(); } // Whether to perform rescan after import bool fRescan = true; - if (request.params.size() > 2) { + if (!request.params[2].isNull()) { fRescan = request.params[2].get_bool(); } @@ -273,13 +273,13 @@ } std::string strLabel = ""; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { strLabel = request.params[1].get_str(); } // Whether to perform rescan after import bool fRescan = true; - if (request.params.size() > 2) { + if (!request.params[2].isNull()) { fRescan = request.params[2].get_bool(); } @@ -290,7 +290,7 @@ // Whether to import a p2sh version, too bool fP2SH = false; - if (request.params.size() > 3) { + if (!request.params[3].isNull()) { fP2SH = request.params[3].get_bool(); } @@ -481,13 +481,13 @@ } std::string strLabel = ""; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { strLabel = request.params[1].get_str(); } // Whether to perform rescan after import bool fRescan = true; - if (request.params.size() > 2) { + if (!request.params[2].isNull()) { fRescan = request.params[2].get_bool(); } @@ -1302,7 +1302,7 @@ // Default options bool fRescan = true; - if (mainRequest.params.size() > 1) { + if (!mainRequest.params[1].isNull()) { const UniValue &options = mainRequest.params[1]; if (options.exists("rescan")) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -172,7 +172,7 @@ // Parse the label first so we don't generate a key if there's an error std::string label; - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { label = LabelFromValue(request.params[0]); } @@ -249,7 +249,7 @@ return NullUniValue; } - if (request.fHelp || request.params.size() > 1) { + if (request.fHelp || request.params.size() > 0) { throw std::runtime_error( "getrawchangeaddress\n" "\nReturns a new Bitcoin address, for receiving change.\n" @@ -583,7 +583,7 @@ return NullUniValue; } - if (request.fHelp) { + if (request.fHelp || request.params.size() != 0) { throw std::runtime_error( "listaddressgroupings\n" "\nLists groups of addresses which have had their common " @@ -773,7 +773,7 @@ // Minimum confirmations int nMinDepth = 1; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { nMinDepth = request.params[1].get_int(); } @@ -844,7 +844,7 @@ // Minimum confirmations int nMinDepth = 1; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { nMinDepth = request.params[1].get_int(); } @@ -950,12 +950,12 @@ : nullptr; int nMinDepth = 1; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { nMinDepth = request.params[1].get_int(); } isminefilter filter = ISMINE_SPENDABLE; - if (request.params.size() > 2 && request.params[2].get_bool()) { + if (!request.params[2].isNull() && request.params[2].get_bool()) { filter = filter | ISMINE_WATCH_ONLY; } @@ -1266,7 +1266,7 @@ std::string strAccount = LabelFromValue(request.params[0]); UniValue sendTo = request.params[1].get_obj(); int nMinDepth = 1; - if (request.params.size() > 2) { + if (!request.params[2].isNull()) { nMinDepth = request.params[2].get_int(); } @@ -1435,13 +1435,13 @@ const UniValue ¶ms, bool by_label) { // Minimum confirmations int nMinDepth = 1; - if (params.size() > 0) { + if (!params[0].isNull()) { nMinDepth = params[0].get_int(); } // Whether to include empty labels bool fIncludeEmpty = false; - if (params.size() > 1) { + if (!params[1].isNull()) { fIncludeEmpty = params[1].get_bool(); } @@ -1922,22 +1922,22 @@ LOCK2(cs_main, pwallet->cs_wallet); std::string strAccount = "*"; - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { strAccount = request.params[0].get_str(); } int nCount = 10; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { nCount = request.params[1].get_int(); } int nFrom = 0; - if (request.params.size() > 2) { + if (!request.params[2].isNull()) { nFrom = request.params[2].get_int(); } isminefilter filter = ISMINE_SPENDABLE; - if (request.params.size() > 3 && request.params[3].get_bool()) { + if (!request.params[3].isNull() && request.params[3].get_bool()) { filter = filter | ISMINE_WATCH_ONLY; } @@ -2112,7 +2112,7 @@ return NullUniValue; } - if (request.fHelp) { + if (request.fHelp || request.params.size() > 3) { throw std::runtime_error( "listsinceblock ( \"blockhash\" target_confirmations " "include_watchonly)\n" @@ -2205,7 +2205,7 @@ int target_confirms = 1; isminefilter filter = ISMINE_SPENDABLE; - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { uint256 blockId; blockId.SetHex(request.params[0].get_str()); @@ -2221,7 +2221,7 @@ } } - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { target_confirms = request.params[1].get_int(); if (target_confirms < 1) { @@ -2360,7 +2360,7 @@ txid.SetHex(request.params[0].get_str()); isminefilter filter = ISMINE_SPENDABLE; - if (request.params.size() > 1 && request.params[1].get_bool()) { + if (!request.params[1].isNull() && request.params[1].get_bool()) { filter = filter | ISMINE_WATCH_ONLY; } @@ -2510,7 +2510,7 @@ // 0 is interpreted by TopUpKeyPool() as the default keypool size given by // -keypool unsigned int kpSize = 0; - if (request.params.size() > 0) { + if (!request.params[0].isNull()) { if (request.params[0].get_int() < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size."); @@ -3497,7 +3497,7 @@ UniValue subtractFeeFromOutputs; std::set setSubtractFeeFromOutputs; - if (request.params.size() > 1) { + if (!request.params[1].isNull()) { if (request.params[1].type() == UniValue::VBOOL) { // backward compatibility bool only fallback coinControl.fAllowWatchOnly = request.params[1].get_bool();