Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed order parameter in the listforwards command #4668

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
22 changes: 22 additions & 0 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,3 +1964,25 @@ 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, l2 = node_factory.line_graph(2)

l2.stop()
l2.daemon.opts['allow-deprecated-apis'] = True
l2.start()

forwards_new = l1.rpc.listforwards("settled")["forwards"]
forwards_dep = l2.rpc.call("listforwards", {"in_channel": "0x1x2", "out_channel": "0x2x3", "status": "settled"})["forwards"]

assert len(forwards_new) == 0
assert len(forwards_dep) == 0