libplugin: use json_stream helpers for RPC calls

This adds helpers to start and send a jsonrpc request using json_stream
in order to benefit from the helpers.

This then simplifies existing plugins RPC requests by using json_stream
helpers.
This commit is contained in:
darosior
2020-01-30 00:55:55 +01:00
committed by Rusty Russell
parent 0546728819
commit 2bff80e3de
5 changed files with 226 additions and 281 deletions

View File

@@ -23,16 +23,13 @@ static struct command_result *ignore(struct command *timer,
static struct command_result *do_clean(struct plugin *p)
{
struct json_out *params = json_out_new(NULL);
json_out_start(params, NULL, '{');
json_out_add(params, "maxexpirytime", false, "%"PRIu64,
time_now().ts.tv_sec - expired_by);
json_out_end(params, '}');
json_out_finished(params);
/* FIXME: delexpiredinvoice should be in our plugin too! */
return send_outreq(p, NULL, "delexpiredinvoice", ignore, ignore, p,
take(params));
struct out_req *req = jsonrpc_request_start(p, NULL, "delexpiredinvoice",
ignore, ignore, p);
json_add_u64(req->js, "maxexpirytime",
time_now().ts.tv_sec - expired_by);
return send_outreq(p, req);
}
static struct command_result *json_autocleaninvoice(struct command *cmd,