Add strict flag to RPCTypeCheckObj

Strict flag forces type check on all object keys.
pull/262/head
João Barbosa 9 years ago committed by Wladimir J. van der Laan
parent a4ca44d276
commit 41e835dd50

@ -89,7 +89,8 @@ void RPCTypeCheck(const UniValue& params,
void RPCTypeCheckObj(const UniValue& o, void RPCTypeCheckObj(const UniValue& o,
const map<string, UniValue::VType>& typesExpected, const map<string, UniValue::VType>& typesExpected,
bool fAllowNull) bool fAllowNull,
bool fStrict)
{ {
BOOST_FOREACH(const PAIRTYPE(string, UniValue::VType)& t, typesExpected) BOOST_FOREACH(const PAIRTYPE(string, UniValue::VType)& t, typesExpected)
{ {
@ -104,6 +105,18 @@ void RPCTypeCheckObj(const UniValue& o,
throw JSONRPCError(RPC_TYPE_ERROR, err); throw JSONRPCError(RPC_TYPE_ERROR, err);
} }
} }
if (fStrict)
{
BOOST_FOREACH(const string& k, o.getKeys())
{
if (typesExpected.count(k) == 0)
{
string err = strprintf("Unexpected key %s", k);
throw JSONRPCError(RPC_TYPE_ERROR, err);
}
}
}
} }
CAmount AmountFromValue(const UniValue& value) CAmount AmountFromValue(const UniValue& value)

@ -70,7 +70,7 @@ void RPCTypeCheck(const UniValue& params,
Use like: RPCTypeCheckObj(object, boost::assign::map_list_of("name", str_type)("value", int_type)); Use like: RPCTypeCheckObj(object, boost::assign::map_list_of("name", str_type)("value", int_type));
*/ */
void RPCTypeCheckObj(const UniValue& o, void RPCTypeCheckObj(const UniValue& o,
const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false); const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false, bool fStrict=false);
/** Opaque base class for timers returned by NewTimerFunc. /** Opaque base class for timers returned by NewTimerFunc.
* This provides no methods at the moment, but makes sure that delete * This provides no methods at the moment, but makes sure that delete

Loading…
Cancel
Save