Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | void RPCServerSignals::OnStarted(std::function<void()> slot) { | ||||
g_rpcSignals.Started.connect(slot); | g_rpcSignals.Started.connect(slot); | ||||
} | } | ||||
void RPCServerSignals::OnStopped(std::function<void()> slot) { | void RPCServerSignals::OnStopped(std::function<void()> slot) { | ||||
g_rpcSignals.Stopped.connect(slot); | g_rpcSignals.Stopped.connect(slot); | ||||
} | } | ||||
void RPCTypeCheck(const UniValue ¶ms, | void RPCTypeCheck(const UniValue ¶ms, | ||||
const std::list<UniValue::VType> &typesExpected, | const std::list<UniValueType> &typesExpected, | ||||
bool fAllowNull) { | bool fAllowNull) { | ||||
unsigned int i = 0; | unsigned int i = 0; | ||||
for (UniValue::VType t : typesExpected) { | for (const UniValueType &t : typesExpected) { | ||||
if (params.size() <= i) { | if (params.size() <= i) { | ||||
break; | break; | ||||
} | } | ||||
const UniValue &v = params[i]; | const UniValue &v = params[i]; | ||||
if (!(fAllowNull && v.isNull())) { | if (!(fAllowNull && v.isNull())) { | ||||
RPCTypeCheckArgument(v, t); | RPCTypeCheckArgument(v, t); | ||||
} | } | ||||
i++; | i++; | ||||
} | } | ||||
} | } | ||||
void RPCTypeCheckArgument(const UniValue &value, UniValue::VType typeExpected) { | void RPCTypeCheckArgument(const UniValue &value, | ||||
if (value.type() != typeExpected) { | const UniValueType &typeExpected) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Expected type %s, got %s", | if (!typeExpected.typeAny && value.type() != typeExpected.type) { | ||||
uvTypeName(typeExpected), | throw JSONRPCError(RPC_TYPE_ERROR, | ||||
strprintf("Expected type %s, got %s", | |||||
uvTypeName(typeExpected.type), | |||||
uvTypeName(value.type()))); | uvTypeName(value.type()))); | ||||
} | } | ||||
} | } | ||||
void RPCTypeCheckObj(const UniValue &o, | void RPCTypeCheckObj(const UniValue &o, | ||||
const std::map<std::string, UniValueType> &typesExpected, | const std::map<std::string, UniValueType> &typesExpected, | ||||
bool fAllowNull, bool fStrict) { | bool fAllowNull, bool fStrict) { | ||||
for (const auto &t : typesExpected) { | for (const auto &t : typesExpected) { | ||||
const UniValue &v = find_value(o, t.first); | const UniValue &v = find_value(o, t.first); | ||||
▲ Show 20 Lines • Show All 486 Lines • Show Last 20 Lines |