mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 18:52:29 +02:00
check for null values in rpc args and handle appropriately
This commit is contained in:
@@ -210,7 +210,7 @@ UniValue waitfornewblock(const JSONRPCRequest& request)
|
||||
+ HelpExampleRpc("waitfornewblock", "1000")
|
||||
);
|
||||
int timeout = 0;
|
||||
if (request.params.size() > 0)
|
||||
if (!request.params[0].isNull())
|
||||
timeout = request.params[0].get_int();
|
||||
|
||||
CUpdatedBlock block;
|
||||
@@ -252,7 +252,7 @@ UniValue waitforblock(const JSONRPCRequest& request)
|
||||
|
||||
uint256 hash = uint256S(request.params[0].get_str());
|
||||
|
||||
if (request.params.size() > 1)
|
||||
if (!request.params[1].isNull())
|
||||
timeout = request.params[1].get_int();
|
||||
|
||||
CUpdatedBlock block;
|
||||
@@ -295,7 +295,7 @@ UniValue waitforblockheight(const JSONRPCRequest& request)
|
||||
|
||||
int height = request.params[0].get_int();
|
||||
|
||||
if (request.params.size() > 1)
|
||||
if (!request.params[1].isNull())
|
||||
timeout = request.params[1].get_int();
|
||||
|
||||
CUpdatedBlock block;
|
||||
@@ -434,7 +434,7 @@ UniValue getrawmempool(const JSONRPCRequest& request)
|
||||
);
|
||||
|
||||
bool fVerbose = false;
|
||||
if (request.params.size() > 0)
|
||||
if (!request.params[0].isNull())
|
||||
fVerbose = request.params[0].get_bool();
|
||||
|
||||
return mempoolToJSON(fVerbose);
|
||||
@@ -467,7 +467,7 @@ UniValue getmempoolancestors(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
bool fVerbose = false;
|
||||
if (request.params.size() > 1)
|
||||
if (!request.params[1].isNull())
|
||||
fVerbose = request.params[1].get_bool();
|
||||
|
||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||
@@ -531,7 +531,7 @@ UniValue getmempooldescendants(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
bool fVerbose = false;
|
||||
if (request.params.size() > 1)
|
||||
if (!request.params[1].isNull())
|
||||
fVerbose = request.params[1].get_bool();
|
||||
|
||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||
@@ -666,7 +666,7 @@ UniValue getblockheader(const JSONRPCRequest& request)
|
||||
uint256 hash(uint256S(strHash));
|
||||
|
||||
bool fVerbose = true;
|
||||
if (request.params.size() > 1)
|
||||
if (!request.params[1].isNull())
|
||||
fVerbose = request.params[1].get_bool();
|
||||
|
||||
if (mapBlockIndex.count(hash) == 0)
|
||||
@@ -741,7 +741,7 @@ UniValue getblock(const JSONRPCRequest& request)
|
||||
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
|
||||
@@ -984,7 +984,7 @@ UniValue gettxout(const JSONRPCRequest& request)
|
||||
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();
|
||||
|
||||
Coin coin;
|
||||
@@ -1037,9 +1037,9 @@ UniValue verifychain(const JSONRPCRequest& request)
|
||||
|
||||
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();
|
||||
|
||||
return CVerifyDB().VerifyDB(Params(), pcoinsTip, nCheckLevel, nCheckDepth);
|
||||
|
||||
@@ -101,7 +101,7 @@ UniValue getnetworkhashps(const JSONRPCRequest& request)
|
||||
);
|
||||
|
||||
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);
|
||||
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1);
|
||||
}
|
||||
|
||||
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
|
||||
@@ -171,7 +171,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
UniValue lpval = NullUniValue;
|
||||
std::set<std::string> setClientRules;
|
||||
int64_t nMaxVersionPreVB = -1;
|
||||
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");
|
||||
|
||||
@@ -310,7 +310,7 @@ UniValue getaddednodeinfo(const JSONRPCRequest& request)
|
||||
|
||||
std::vector<AddedNodeInfo> 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()) {
|
||||
|
||||
@@ -137,7 +137,7 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
|
||||
|
||||
// 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;
|
||||
@@ -211,7 +211,7 @@ UniValue gettxoutproof(const JSONRPCRequest& request)
|
||||
CBlockIndex* pblockindex = NULL;
|
||||
|
||||
uint256 hashBlock;
|
||||
if (request.params.size() > 1)
|
||||
if (!request.params[1].isNull())
|
||||
{
|
||||
hashBlock = uint256S(request.params[1].get_str());
|
||||
if (!mapBlockIndex.count(hashBlock))
|
||||
@@ -412,7 +412,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
|
||||
}
|
||||
}
|
||||
|
||||
if (request.params.size() > 3 && rbfOptIn != SignalsOptInRBF(rawTx)) {
|
||||
if (!request.params[3].isNull() && rbfOptIn != SignalsOptInRBF(rawTx)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number(s) contradict replaceable option");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user