MCPcopy Create free account
hub / github.com/ElementsProject/elements / RPCTypeCheckObj

Function RPCTypeCheckObj

src/rpc/util.cpp:63–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63void RPCTypeCheckObj(const UniValue& o,
64 const std::map<std::string, UniValueType>& typesExpected,
65 bool fAllowNull,
66 bool fStrict)
67{
68 for (const auto& t : typesExpected) {
69 const UniValue& v = find_value(o, t.first);
70 if (!fAllowNull && v.isNull())
71 throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
72
73 if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) {
74 std::string err = strprintf("Expected type %s for %s, got %s",
75 uvTypeName(t.second.type), t.first, uvTypeName(v.type()));
76 throw JSONRPCError(RPC_TYPE_ERROR, err);
77 }
78 }
79
80 if (fStrict)
81 {
82 for (const std::string& k : o.getKeys())
83 {
84 if (typesExpected.count(k) == 0)
85 {
86 std::string err = strprintf("Unexpected key %s", k);
87 throw JSONRPCError(RPC_TYPE_ERROR, err);
88 }
89 }
90 }
91}
92
93CAmount AmountFromValue(const UniValue& value, bool check_range, int decimals)
94{

Callers 5

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

Calls 5

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

Tested by

no test coverage detected