Get rid of redundant RPC params.size() checks

No change in behavior.
This commit is contained in:
Russell Yanofsky 2017-08-14 19:38:18 -04:00
parent c2704ec98a
commit e666efcdba
6 changed files with 33 additions and 33 deletions

View File

@ -1489,11 +1489,11 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
const CBlockIndex* pindex; const CBlockIndex* pindex;
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
if (request.params.size() > 0 && !request.params[0].isNull()) { if (!request.params[0].isNull()) {
blockcount = request.params[0].get_int(); blockcount = request.params[0].get_int();
} }
bool havehash = request.params.size() > 1 && !request.params[1].isNull(); bool havehash = !request.params[1].isNull();
uint256 hash; uint256 hash;
if (havehash) { if (havehash) {
hash = uint256S(request.params[1].get_str()); hash = uint256S(request.params[1].get_str());

View File

@ -842,7 +842,7 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
RPCTypeCheckArgument(request.params[0], UniValue::VNUM); RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
unsigned int conf_target = ParseConfirmTarget(request.params[0]); unsigned int conf_target = ParseConfirmTarget(request.params[0]);
bool conservative = true; bool conservative = true;
if (request.params.size() > 1 && !request.params[1].isNull()) { if (!request.params[1].isNull()) {
FeeEstimateMode fee_mode; FeeEstimateMode fee_mode;
if (!FeeModeFromString(request.params[1].get_str(), fee_mode)) { if (!FeeModeFromString(request.params[1].get_str(), fee_mode)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");

View File

@ -552,7 +552,7 @@ UniValue getmemoryinfo(const JSONRPCRequest& request)
+ HelpExampleRpc("getmemoryinfo", "") + HelpExampleRpc("getmemoryinfo", "")
); );
std::string mode = (request.params.size() < 1 || request.params[0].isNull()) ? "stats" : request.params[0].get_str(); std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str();
if (mode == "stats") { if (mode == "stats") {
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("locked", RPCLockedMemoryInfo())); obj.push_back(Pair("locked", RPCLockedMemoryInfo()));
@ -603,11 +603,11 @@ UniValue logging(const JSONRPCRequest& request)
} }
uint32_t originalLogCategories = logCategories; uint32_t originalLogCategories = logCategories;
if (request.params.size() > 0 && request.params[0].isArray()) { if (request.params[0].isArray()) {
logCategories |= getCategoryMask(request.params[0]); logCategories |= getCategoryMask(request.params[0]);
} }
if (request.params.size() > 1 && request.params[1].isArray()) { if (request.params[1].isArray()) {
logCategories &= ~getCategoryMask(request.params[1]); logCategories &= ~getCategoryMask(request.params[1]);
} }

View File

@ -258,7 +258,7 @@ UniValue disconnectnode(const JSONRPCRequest& request)
bool success; bool success;
const UniValue &address_arg = request.params[0]; const UniValue &address_arg = request.params[0];
const UniValue &id_arg = request.params.size() < 2 ? NullUniValue : request.params[1]; const UniValue &id_arg = request.params[1];
if (!address_arg.isNull() && id_arg.isNull()) { if (!address_arg.isNull() && id_arg.isNull()) {
/* handle disconnect-by-address */ /* handle disconnect-by-address */
@ -311,7 +311,7 @@ UniValue getaddednodeinfo(const JSONRPCRequest& request)
std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo(); std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo();
if (request.params.size() == 1 && !request.params[0].isNull()) { if (!request.params[0].isNull()) {
bool found = false; bool found = false;
for (const AddedNodeInfo& info : vInfo) { for (const AddedNodeInfo& info : vInfo) {
if (info.strAddedNode == request.params[0].get_str()) { if (info.strAddedNode == request.params[0].get_str()) {
@ -534,11 +534,11 @@ UniValue setban(const JSONRPCRequest& request)
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned"); throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
int64_t banTime = 0; //use standard bantime if not specified int64_t banTime = 0; //use standard bantime if not specified
if (request.params.size() >= 3 && !request.params[2].isNull()) if (!request.params[2].isNull())
banTime = request.params[2].get_int64(); banTime = request.params[2].get_int64();
bool absolute = false; bool absolute = false;
if (request.params.size() == 4 && request.params[3].isTrue()) if (request.params[3].isTrue())
absolute = true; absolute = true;
isSubnet ? g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute); isSubnet ? g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);

View File

@ -339,14 +339,14 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
CMutableTransaction rawTx; CMutableTransaction rawTx;
if (request.params.size() > 2 && !request.params[2].isNull()) { if (!request.params[2].isNull()) {
int64_t nLockTime = request.params[2].get_int64(); int64_t nLockTime = request.params[2].get_int64();
if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max()) if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
rawTx.nLockTime = nLockTime; rawTx.nLockTime = nLockTime;
} }
bool rbfOptIn = request.params.size() > 3 ? request.params[3].isTrue() : false; bool rbfOptIn = request.params[3].isTrue();
for (unsigned int idx = 0; idx < inputs.size(); idx++) { for (unsigned int idx = 0; idx < inputs.size(); idx++) {
const UniValue& input = inputs[idx]; const UniValue& input = inputs[idx];
@ -735,7 +735,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
bool fGivenKeys = false; bool fGivenKeys = false;
CBasicKeyStore tempKeystore; CBasicKeyStore tempKeystore;
if (request.params.size() > 2 && !request.params[2].isNull()) { if (!request.params[2].isNull()) {
fGivenKeys = true; fGivenKeys = true;
UniValue keys = request.params[2].get_array(); UniValue keys = request.params[2].get_array();
for (unsigned int idx = 0; idx < keys.size(); idx++) { for (unsigned int idx = 0; idx < keys.size(); idx++) {
@ -757,7 +757,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
#endif #endif
// Add previous txouts given in the RPC call: // Add previous txouts given in the RPC call:
if (request.params.size() > 1 && !request.params[1].isNull()) { if (!request.params[1].isNull()) {
UniValue prevTxs = request.params[1].get_array(); UniValue prevTxs = request.params[1].get_array();
for (unsigned int idx = 0; idx < prevTxs.size(); idx++) { for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
const UniValue& p = prevTxs[idx]; const UniValue& p = prevTxs[idx];
@ -828,7 +828,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
#endif #endif
int nHashType = SIGHASH_ALL; int nHashType = SIGHASH_ALL;
if (request.params.size() > 3 && !request.params[3].isNull()) { if (!request.params[3].isNull()) {
static std::map<std::string, int> mapSigHashValues = { static std::map<std::string, int> mapSigHashValues = {
{std::string("ALL"), int(SIGHASH_ALL)}, {std::string("ALL"), int(SIGHASH_ALL)},
{std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)}, {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},

View File

@ -462,26 +462,26 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
// Wallet comments // Wallet comments
CWalletTx wtx; CWalletTx wtx;
if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty()) if (!request.params[2].isNull() && !request.params[2].get_str().empty())
wtx.mapValue["comment"] = request.params[2].get_str(); wtx.mapValue["comment"] = request.params[2].get_str();
if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty()) if (!request.params[3].isNull() && !request.params[3].get_str().empty())
wtx.mapValue["to"] = request.params[3].get_str(); wtx.mapValue["to"] = request.params[3].get_str();
bool fSubtractFeeFromAmount = false; bool fSubtractFeeFromAmount = false;
if (request.params.size() > 4 && !request.params[4].isNull()) { if (!request.params[4].isNull()) {
fSubtractFeeFromAmount = request.params[4].get_bool(); fSubtractFeeFromAmount = request.params[4].get_bool();
} }
CCoinControl coin_control; CCoinControl coin_control;
if (request.params.size() > 5 && !request.params[5].isNull()) { if (!request.params[5].isNull()) {
coin_control.signalRbf = request.params[5].get_bool(); coin_control.signalRbf = request.params[5].get_bool();
} }
if (request.params.size() > 6 && !request.params[6].isNull()) { if (!request.params[6].isNull()) {
coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]); coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]);
} }
if (request.params.size() > 7 && !request.params[7].isNull()) { if (!request.params[7].isNull()) {
if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) { if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
} }
@ -904,9 +904,9 @@ UniValue sendfrom(const JSONRPCRequest& request)
CWalletTx wtx; CWalletTx wtx;
wtx.strFromAccount = strAccount; wtx.strFromAccount = strAccount;
if (request.params.size() > 4 && !request.params[4].isNull() && !request.params[4].get_str().empty()) if (!request.params[4].isNull() && !request.params[4].get_str().empty())
wtx.mapValue["comment"] = request.params[4].get_str(); wtx.mapValue["comment"] = request.params[4].get_str();
if (request.params.size() > 5 && !request.params[5].isNull() && !request.params[5].get_str().empty()) if (!request.params[5].isNull() && !request.params[5].get_str().empty())
wtx.mapValue["to"] = request.params[5].get_str(); wtx.mapValue["to"] = request.params[5].get_str();
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
@ -986,23 +986,23 @@ UniValue sendmany(const JSONRPCRequest& request)
CWalletTx wtx; CWalletTx wtx;
wtx.strFromAccount = strAccount; wtx.strFromAccount = strAccount;
if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty()) if (!request.params[3].isNull() && !request.params[3].get_str().empty())
wtx.mapValue["comment"] = request.params[3].get_str(); wtx.mapValue["comment"] = request.params[3].get_str();
UniValue subtractFeeFromAmount(UniValue::VARR); UniValue subtractFeeFromAmount(UniValue::VARR);
if (request.params.size() > 4 && !request.params[4].isNull()) if (!request.params[4].isNull())
subtractFeeFromAmount = request.params[4].get_array(); subtractFeeFromAmount = request.params[4].get_array();
CCoinControl coin_control; CCoinControl coin_control;
if (request.params.size() > 5 && !request.params[5].isNull()) { if (!request.params[5].isNull()) {
coin_control.signalRbf = request.params[5].get_bool(); coin_control.signalRbf = request.params[5].get_bool();
} }
if (request.params.size() > 6 && !request.params[6].isNull()) { if (!request.params[6].isNull()) {
coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]); coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]);
} }
if (request.params.size() > 7 && !request.params[7].isNull()) { if (!request.params[7].isNull()) {
if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) { if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
} }
@ -2670,19 +2670,19 @@ UniValue listunspent(const JSONRPCRequest& request)
); );
int nMinDepth = 1; int nMinDepth = 1;
if (request.params.size() > 0 && !request.params[0].isNull()) { if (!request.params[0].isNull()) {
RPCTypeCheckArgument(request.params[0], UniValue::VNUM); RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
nMinDepth = request.params[0].get_int(); nMinDepth = request.params[0].get_int();
} }
int nMaxDepth = 9999999; int nMaxDepth = 9999999;
if (request.params.size() > 1 && !request.params[1].isNull()) { if (!request.params[1].isNull()) {
RPCTypeCheckArgument(request.params[1], UniValue::VNUM); RPCTypeCheckArgument(request.params[1], UniValue::VNUM);
nMaxDepth = request.params[1].get_int(); nMaxDepth = request.params[1].get_int();
} }
std::set<CBitcoinAddress> setAddress; std::set<CBitcoinAddress> setAddress;
if (request.params.size() > 2 && !request.params[2].isNull()) { if (!request.params[2].isNull()) {
RPCTypeCheckArgument(request.params[2], UniValue::VARR); RPCTypeCheckArgument(request.params[2], UniValue::VARR);
UniValue inputs = request.params[2].get_array(); UniValue inputs = request.params[2].get_array();
for (unsigned int idx = 0; idx < inputs.size(); idx++) { for (unsigned int idx = 0; idx < inputs.size(); idx++) {
@ -2697,7 +2697,7 @@ UniValue listunspent(const JSONRPCRequest& request)
} }
bool include_unsafe = true; bool include_unsafe = true;
if (request.params.size() > 3 && !request.params[3].isNull()) { if (!request.params[3].isNull()) {
RPCTypeCheckArgument(request.params[3], UniValue::VBOOL); RPCTypeCheckArgument(request.params[3], UniValue::VBOOL);
include_unsafe = request.params[3].get_bool(); include_unsafe = request.params[3].get_bool();
} }
@ -3112,7 +3112,7 @@ UniValue generate(const JSONRPCRequest& request)
int num_generate = request.params[0].get_int(); int num_generate = request.params[0].get_int();
uint64_t max_tries = 1000000; uint64_t max_tries = 1000000;
if (request.params.size() > 1 && !request.params[1].isNull()) { if (!request.params[1].isNull()) {
max_tries = request.params[1].get_int(); max_tries = request.params[1].get_int();
} }