From 97b52ed8c3869116cbb7e2835a8df6f2a296f333 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 26 May 2021 15:13:01 +0930 Subject: [PATCH] autoclean: don't return a raw string as result. This is hard to parse, and not extensible in future, and disagrees with the man page (and caught by schema). Technically this is an API break, but it can't be done neatly anyway and it's unlikely someone is relying on this today :( Signed-off-by: Rusty Russell Changelog-Changed: JSONRPC: `autocleaninvoice` now returns an object, not a raw string. --- plugins/autoclean.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/autoclean.c b/plugins/autoclean.c index 21f0c8d30..3b80815b0 100644 --- a/plugins/autoclean.c +++ b/plugins/autoclean.c @@ -39,6 +39,7 @@ static struct command_result *json_autocleaninvoice(struct command *cmd, { u64 *cycle; u64 *exby; + struct json_stream *response; if (!param(cmd, buffer, params, p_opt_def("cycle_seconds", param_u64, &cycle, 3600), @@ -50,18 +51,19 @@ static struct command_result *json_autocleaninvoice(struct command *cmd, expired_by = *exby; if (cycle_seconds == 0) { - tal_free(cleantimer); - return command_success_str(cmd, "Autoclean timer disabled"); + response = jsonrpc_stream_success(cmd); + json_add_bool(response, "enabled", false); + return command_finished(cmd, response); } tal_free(cleantimer); cleantimer = plugin_timer(cmd->plugin, time_from_sec(cycle_seconds), do_clean, cmd->plugin); - return command_success_str(cmd, - tal_fmt(cmd, "Autocleaning %"PRIu64 - "-second old invoices every %"PRIu64 - " seconds", - expired_by, cycle_seconds)); + response = jsonrpc_stream_success(cmd); + json_add_bool(response, "enabled", true); + json_add_u64(response, "cycle_seconds", cycle_seconds); + json_add_u64(response, "expired_by", expired_by); + return command_finished(cmd, response); } static const char *init(struct plugin *p,