Skip to content

Commit

Permalink
Fixed order parameter in the listforwards command
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vincenzopalazzo committed Jul 21, 2021
1 parent ceb40de commit ee245e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2669,13 +2669,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);

Expand Down
15 changes: 15 additions & 0 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ee245e4

Please sign in to comment.