From fc9b24a7466ad829c1f5c98b4ef31ca17cfec177 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 26 May 2021 15:15:01 +0930 Subject: [PATCH] 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 Changelog-Added: JSONRPC: `close` returns `type` "unopened" if it simply discards channel instead of empty object. --- lightningd/peer_control.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 93b31c17f..f1ddbf6cb 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -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 = {