From 78eb49c9ba0933a5a645611df3e12c3dacd15950 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 21 Jul 2021 21:11:17 +0200 Subject: [PATCH] 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 --- lightningd/peer_htlcs.c | 21 +++++++++++++++++++-- tests/test_gossip.py | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 40663d17051c..9408a4f14462 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -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); diff --git a/tests/test_gossip.py b/tests/test_gossip.py index 1cc3a5443bbf..7325d6fdb32f 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -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