Fixed order parameter in the listforwards command

Changelog-Changed: Change order parameters in the listforwards command

Changelog-Deprecated: Change order of the status parameter in the listforwards rpc command.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo 2021-07-21 21:11:17 +02:00 committed by Rusty Russell
parent 0a05bcd05e
commit 3b65a4caca
2 changed files with 34 additions and 3 deletions

View file

@ -2661,13 +2661,30 @@ static struct command_result *json_listforwards(struct command *cmd,
const char *status_str;
enum forward_status status = FORWARD_ANY;
// TODO: We will remove soon after the deprecated period.
if (params && deprecated_apis && params->type == JSMN_ARRAY) {
struct short_channel_id scid;
/* We need to catch [ null, null, "settled" ], and
* [ "1x2x3" ] as old-style */
if ((params->size > 0 && json_to_short_channel_id(buffer, params + 1, &scid)) ||
(params->size == 3 && !json_to_short_channel_id(buffer, params + 3, &scid))) {
if (!param(cmd, buffer, params,
p_opt("in_channel", param_short_channel_id, &chan_in),
p_opt("out_channel", param_short_channel_id, &chan_out),
p_opt("status", param_string, &status_str),
NULL))
return command_param_failed();
goto parsed;
}
}
if (!param(cmd, buffer, params,
p_opt("status", param_string, &status_str),
p_opt("in_channel", param_short_channel_id, &chan_in),
p_opt("out_channel", param_short_channel_id, &chan_out),
p_opt("status", param_string, &status_str),
NULL))
return command_param_failed();
parsed:
if (status_str && !string_to_forward_status(status_str, &status))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Unrecognized status: %s", status_str);
@ -2683,5 +2700,4 @@ static const struct json_command listforwards_command = {
json_listforwards,
"List all forwarded payments and their information optionally filtering by [in_channel] [out_channel] and [state]"
};
AUTODATA(json_command, &listforwards_command);

View file

@ -1964,3 +1964,18 @@ def test_addgossip(node_factory):
with pytest.raises(RpcError, match='Bad signature'):
l3.rpc.addgossip(badupdate)
def test_parms_listforwards(node_factory):
"""
Simple test to ensure that the order of the listforwards
is correct as describe in the documentation.
This test is written by a issue report in the IR channel,
it is simple and not useful, but it is good to have to avoid
simile errors in the future.
"""
l1, _ = node_factory.line_graph(2)
forwards = l1.rpc.listforwards("settled")["forwards"]
assert len(forwards) == 0