| 61 | } |
| 62 | |
| 63 | void 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 | |
| 93 | CAmount AmountFromValue(const UniValue& value, bool check_range, int decimals) |
| 94 | { |
no test coverage detected