| 54 | } |
| 55 | |
| 56 | void 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 | |
| 83 | int ParseVerbosity(const UniValue& arg, int default_verbosity, bool allow_bool) |
| 84 | { |
no test coverage detected