json-rpc: make commands return 'struct command_result *'.

Usually, this means they return 'command_param_failed()' if param()
fails, and changing 'command_success(); return;' to 'return
command_success()'.

Occasionally, it's more complex: there's a command_its_complicated()
for the case where we can't exactly determine what the status is,
but it should be considered a last resort.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-12-16 15:22:06 +10:30
parent 1ede7bc55b
commit 68bb36b210
19 changed files with 516 additions and 539 deletions

View File

@@ -728,10 +728,10 @@ struct command_result *param_loglevel(struct command *cmd,
return NULL;
}
static void json_getlog(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t * params)
static struct command_result *json_getlog(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t * params)
{
struct json_stream *response;
enum log_level *minlevel;
@@ -740,7 +740,7 @@ static void json_getlog(struct command *cmd,
if (!param(cmd, buffer, params,
p_opt_def("level", param_loglevel, &minlevel, LOG_INFORM),
NULL))
return;
return command_param_failed();
response = json_stream_success(cmd);
json_object_start(response, NULL);
@@ -749,7 +749,7 @@ static void json_getlog(struct command *cmd,
json_add_num(response, "bytes_max", (unsigned int) log_max_mem(lr));
json_add_log(response, lr, *minlevel);
json_object_end(response);
command_success(cmd, response);
return command_success(cmd, response);
}
static const struct json_command getlog_command = {