mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
rpc: Allow typeAny in RPCTypeCheck
This commit is contained in:
parent
e4ffcacc21
commit
8acd25d854
2 changed files with 8 additions and 9 deletions
|
@ -50,12 +50,11 @@ void RPCServer::OnStopped(std::function<void ()> slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
void RPCTypeCheck(const UniValue& params,
|
void RPCTypeCheck(const UniValue& params,
|
||||||
const std::list<UniValue::VType>& typesExpected,
|
const std::list<UniValueType>& typesExpected,
|
||||||
bool fAllowNull)
|
bool fAllowNull)
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (UniValue::VType t : typesExpected)
|
for (const UniValueType& t : typesExpected) {
|
||||||
{
|
|
||||||
if (params.size() <= i)
|
if (params.size() <= i)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -67,10 +66,10 @@ void RPCTypeCheck(const UniValue& params,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RPCTypeCheckArgument(const UniValue& value, UniValue::VType typeExpected)
|
void RPCTypeCheckArgument(const UniValue& value, const UniValueType& typeExpected)
|
||||||
{
|
{
|
||||||
if (value.type() != typeExpected) {
|
if (!typeExpected.typeAny && value.type() != typeExpected.type) {
|
||||||
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Expected type %s, got %s", uvTypeName(typeExpected), uvTypeName(value.type())));
|
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Expected type %s, got %s", uvTypeName(typeExpected.type), uvTypeName(value.type())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace RPCServer
|
||||||
/** Wrapper for UniValue::VType, which includes typeAny:
|
/** Wrapper for UniValue::VType, which includes typeAny:
|
||||||
* Used to denote don't care type. Only used by RPCTypeCheckObj */
|
* Used to denote don't care type. Only used by RPCTypeCheckObj */
|
||||||
struct UniValueType {
|
struct UniValueType {
|
||||||
explicit UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
|
UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
|
||||||
UniValueType() : typeAny(true) {}
|
UniValueType() : typeAny(true) {}
|
||||||
bool typeAny;
|
bool typeAny;
|
||||||
UniValue::VType type;
|
UniValue::VType type;
|
||||||
|
@ -69,12 +69,12 @@ bool RPCIsInWarmup(std::string *outStatus);
|
||||||
* the right number of arguments are passed, just that any passed are the correct type.
|
* the right number of arguments are passed, just that any passed are the correct type.
|
||||||
*/
|
*/
|
||||||
void RPCTypeCheck(const UniValue& params,
|
void RPCTypeCheck(const UniValue& params,
|
||||||
const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
|
const std::list<UniValueType>& typesExpected, bool fAllowNull=false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-check one argument; throws JSONRPCError if wrong type given.
|
* Type-check one argument; throws JSONRPCError if wrong type given.
|
||||||
*/
|
*/
|
||||||
void RPCTypeCheckArgument(const UniValue& value, UniValue::VType typeExpected);
|
void RPCTypeCheckArgument(const UniValue& value, const UniValueType& typeExpected);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check for expected keys/value types in an Object.
|
Check for expected keys/value types in an Object.
|
||||||
|
|
Loading…
Reference in a new issue