| 74 | } |
| 75 | |
| 76 | void RPCTypeCheckObj(const UniValue& o, |
| 77 | const std::map<std::string, UniValueType>& typesExpected, |
| 78 | bool fAllowNull, |
| 79 | bool fStrict) |
| 80 | { |
| 81 | for (const auto& t : typesExpected) { |
| 82 | const UniValue& v = find_value(o, t.first); |
| 83 | if (!fAllowNull && v.isNull()) |
| 84 | throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first)); |
| 85 | |
| 86 | if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) { |
| 87 | std::string err = strprintf("Expected type %s for %s, got %s", |
| 88 | uvTypeName(t.second.type), t.first, uvTypeName(v.type())); |
| 89 | throw JSONRPCError(RPC_TYPE_ERROR, err); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (fStrict) |
| 94 | { |
| 95 | for (const std::string& k : o.getKeys()) |
| 96 | { |
| 97 | if (typesExpected.count(k) == 0) |
| 98 | { |
| 99 | std::string err = strprintf("Unexpected key %s", k); |
| 100 | throw JSONRPCError(RPC_TYPE_ERROR, err); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | CAmount AmountFromValue(const UniValue& value) |
| 107 | { |
no test coverage detected