jsonrpc: declare up front whether a response is success or fail.

Such an API is required for when we stream it directly.  Almost all our
handlers fit this pattern already, or nearly do.

We remove new_json_result() in favor of explicit json_stream_success()
and json_stream_fail(), but still allowing command_fail() if you just
want a simple all-in-one fail wrapper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-10-19 11:47:48 +10:30
parent 12adcda370
commit e46ce0fc84
21 changed files with 224 additions and 195 deletions

View File

@@ -718,7 +718,7 @@ bool json_tok_loglevel(struct command *cmd, const char *name,
static void json_getlog(struct command *cmd,
const char *buffer, const jsmntok_t * params)
{
struct json_result *response = new_json_result(cmd);
struct json_result *response;
enum log_level *minlevel;
struct log_book *lr = cmd->ld->log_book;
@@ -728,6 +728,7 @@ static void json_getlog(struct command *cmd,
NULL))
return;
response = json_stream_success(cmd);
json_object_start(response, NULL);
json_add_time(response, "created_at", log_init_time(lr)->ts);
json_add_num(response, "bytes_used", (unsigned int) log_used(lr));