lightningd: have json_stream_success start the "result" object.

"result" should always be an object (so that we can add new fields),
so make that implicit in json_stream_success.

This makes our primitives well-formed: we previously used NULL as our
fieldname when calling the first json_object_start, which is a hack
since we're actually in an object and the fieldname is 'result' (which
was already written by json_object_start).

There were only two cases which didn't do this:
1. dev-memdump returned an array.  No API guarantees on this.
2. shutdown returned a string.

I temporarily made shutdown return an empty object, which shouldn't
break anything, but I want to fix that later anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-06-12 10:08:54 +09:30
parent 0e336ac252
commit bb7bbd03c5
17 changed files with 31 additions and 124 deletions

View File

@@ -77,7 +77,7 @@ struct jsonrpc_request {
};
/**
* json_stream_success - start streaming a successful json result.
* json_stream_success - start streaming a successful json result object.
* @cmd: the command we're running.
*
* The returned value should go to command_success() when done.
@@ -86,13 +86,14 @@ struct jsonrpc_request {
struct json_stream *json_stream_success(struct command *cmd);
/**
* json_stream_fail - start streaming a failed json result.
* json_stream_fail - start streaming a failed json result, with data object.
* @cmd: the command we're running.
* @code: the error code from common/jsonrpc_errors.h
* @errmsg: the error string.
*
* The returned value should go to command_failed() when done;
* json_add_* will be placed into the 'data' field of the 'error' JSON reply.
* You need to json_object_end() once you're done!
*/
struct json_stream *json_stream_fail(struct command *cmd,
int code,
@@ -110,12 +111,11 @@ struct json_stream *json_stream_fail_nodata(struct command *cmd,
int code,
const char *errmsg);
struct json_stream *null_response(struct command *cmd);
/* These returned values are never NULL. */
struct command_result *command_success(struct command *cmd,
struct json_stream *response)
WARN_UNUSED_RESULT;
struct command_result *command_failed(struct command *cmd,
struct json_stream *result)
WARN_UNUSED_RESULT;