MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / RPCTypeCheckObj

Function RPCTypeCheckObj

src/rpc/util.cpp:56–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56void RPCTypeCheckObj(const UniValue& o,
57 const std::map<std::string, UniValueType>& typesExpected,
58 bool fAllowNull,
59 bool fStrict)
60{
61 for (const auto& t : typesExpected) {
62 const UniValue& v = o.find_value(t.first);
63 if (!fAllowNull && v.isNull())
64 throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
65
66 if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull())))
67 throw JSONRPCError(RPC_TYPE_ERROR, strprintf("JSON value of type %s for field %s is not of expected type %s", uvTypeName(v.type()), t.first, uvTypeName(t.second.type)));
68 }
69
70 if (fStrict)
71 {
72 for (const std::string& k : o.getKeys())
73 {
74 if (!typesExpected.contains(k))
75 {
76 std::string err = strprintf("Unexpected key %s", k);
77 throw JSONRPCError(RPC_TYPE_ERROR, err);
78 }
79 }
80 }
81}
82
83int ParseVerbosity(const UniValue& arg, int default_verbosity, bool allow_bool)
84{

Callers 6

lockunspentFunction · 0.85
listunspentFunction · 0.85
FundTransactionFunction · 0.85
bumpfee_helperFunction · 0.85
gettxspendingprevoutFunction · 0.85
ParsePrevoutsFunction · 0.85

Calls 5

JSONRPCErrorFunction · 0.85
uvTypeNameFunction · 0.85
isNullMethod · 0.80
typeMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected