This change allows to do
0[&](const RPCContext& ctx) -> UniValue
instead of
0[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
So RPCContext
ties RPCHelpMan
and JSONRPCRequest
. Then ctx
is used to get actual parameter values. For instance, before:
0int timeout = 0;
1if (!request.params[0].isNull())
2 timeout = request.params[0].get_int();
and now
0int timeout = ctx.param<int>(0);
Not that the default value defined in the RPC spec is used.
It is also possible to iterate an array parameter:
0 std::set<std::string> stats;
1 ctx.param(1).forEach([&](const UniValue& stat) {
2 stats.insert(stat.get_str());
3 });
Or even do custom parameter handling:
0 int verbosity = ctx.param(1, [](const UniValue& param) -> int {
1 if (param.isNull()) return 1;
2 if (param.isNum()) return param.get_int();
3 return param.get_bool() ? 1 : 0;
4 });