close: add "unopened" type if we simply discard channel.

Undocumented (caught by json schema!) if we discard channel because it
wasn't open yet, then close returned the empty object.  Make it return
a new type in this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSONRPC: `close` returns `type` "unopened" if it simply discards channel instead of empty object.
This commit is contained in:
Rusty Russell 2021-05-26 15:15:01 +09:30
parent a4c7ff0f10
commit fc9b24a746

View File

@ -1667,13 +1667,12 @@ static struct command_result *json_close(struct command *cmd,
if (uc) {
/* Easy case: peer can simply be forgotten. */
kill_uncommitted_channel(uc, "close command called");
return command_success(cmd, json_stream_success(cmd));
goto discard_unopened;
}
if ((channel = peer_unsaved_channel(peer))) {
channel_unsaved_close_conn(channel,
"close command called");
return command_success(cmd, json_stream_success(cmd));
goto discard_unopened;
}
return command_fail(cmd, LIGHTNINGD,
"Peer has no active channel");
@ -1833,6 +1832,12 @@ static struct command_result *json_close(struct command *cmd,
/* Wait until close drops down to chain. */
return command_still_pending(cmd);
discard_unopened: {
struct json_stream *result = json_stream_success(cmd);
json_add_string(result, "type", "unopened");
return command_success(cmd, result);
}
}
static const struct json_command close_command = {