Skip to content

Commit 8acd25d

Browse files
author
MarcoFalke
committed
rpc: Allow typeAny in RPCTypeCheck
1 parent e4ffcac commit 8acd25d

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/rpc/server.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ void RPCServer::OnStopped(std::function<void ()> slot)
5050
}
5151

5252
void RPCTypeCheck(const UniValue& params,
53-
const std::list<UniValue::VType>& typesExpected,
53+
const std::list<UniValueType>& typesExpected,
5454
bool fAllowNull)
5555
{
5656
unsigned int i = 0;
57-
for (UniValue::VType t : typesExpected)
58-
{
57+
for (const UniValueType& t : typesExpected) {
5958
if (params.size() <= i)
6059
break;
6160

@@ -67,10 +66,10 @@ void RPCTypeCheck(const UniValue& params,
6766
}
6867
}
6968

70-
void RPCTypeCheckArgument(const UniValue& value, UniValue::VType typeExpected)
69+
void RPCTypeCheckArgument(const UniValue& value, const UniValueType& typeExpected)
7170
{
72-
if (value.type() != typeExpected) {
73-
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Expected type %s, got %s", uvTypeName(typeExpected), uvTypeName(value.type())));
71+
if (!typeExpected.typeAny && value.type() != typeExpected.type) {
72+
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Expected type %s, got %s", uvTypeName(typeExpected.type), uvTypeName(value.type())));
7473
}
7574
}
7675

src/rpc/server.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace RPCServer
3030
/** Wrapper for UniValue::VType, which includes typeAny:
3131
* Used to denote don't care type. Only used by RPCTypeCheckObj */
3232
struct UniValueType {
33-
explicit UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
33+
UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
3434
UniValueType() : typeAny(true) {}
3535
bool typeAny;
3636
UniValue::VType type;
@@ -69,12 +69,12 @@ bool RPCIsInWarmup(std::string *outStatus);
6969
* the right number of arguments are passed, just that any passed are the correct type.
7070
*/
7171
void RPCTypeCheck(const UniValue& params,
72-
const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
72+
const std::list<UniValueType>& typesExpected, bool fAllowNull=false);
7373

7474
/**
7575
* Type-check one argument; throws JSONRPCError if wrong type given.
7676
*/
77-
void RPCTypeCheckArgument(const UniValue& value, UniValue::VType typeExpected);
77+
void RPCTypeCheckArgument(const UniValue& value, const UniValueType& typeExpected);
7878

7979
/*
8080
Check for expected keys/value types in an Object.

0 commit comments

Comments
 (0)