Skip to content

Commit

Permalink
Integrate the status flow in the listsendpays command
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Jun 14, 2021
1 parent f5fa3f1 commit bb02f7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,13 +1524,13 @@ static struct command_result *json_listsendpays(struct command *cmd,
const struct wallet_payment **payments;
struct json_stream *response;
struct sha256 *rhash;
const char *invstring, *status;
const char *invstring, *status_str;

if (!param(cmd, buffer, params,
/* FIXME: parameter should be invstring now */
p_opt("bolt11", param_string, &invstring),
p_opt("payment_hash", param_sha256, &rhash),
p_opt("status", param_string, &status),
p_opt("status", param_string, &status_str),
NULL))
return command_param_failed();

Expand Down Expand Up @@ -1562,7 +1562,14 @@ static struct command_result *json_listsendpays(struct command *cmd,
}
}

payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, NULL);
if (status_str) {
enum wallet_payment_status status;

if (!string_to_payment_status(status_str, &status))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Unrecognized status: %s", status_str);
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, &status);
} else
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, NULL);

response = json_stream_success(cmd);

Expand Down
23 changes: 23 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4304,3 +4304,26 @@ def test_pay_low_max_htlcs(node_factory):
l1.daemon.wait_for_log(
r'Number of pre-split HTLCs \([0-9]+\) exceeds our HTLC budget \([0-9]+\), skipping pre-splitter'
)


def test_listpays_with_filter_by_status(node_factory, bitcoind):
"""
This test check if the filtering by status of the command listpays
has some mistakes.
"""

# Create the line graph l2 -> l1 with a channel of 10 ** 5 sat!
l2, l1 = node_factory.line_graph(2, fundamount=10**5, wait_for_announce=True)

inv = l1.rpc.invoice(10 ** 5, 'inv', 'inv')
l2.rpc.pay(inv['bolt11'])

wait_for(lambda: l2.rpc.listpays(inv['bolt11'])['pays'][0]['status'] == 'complete')

# test if the node is still ready
payments = l2.rpc.call("listpays", {"status": 'failed'})

assert len(payments['payments']) == 0

payments = l2.rpc.listpays()
assert len(l2.rpc.listpays()['payments']) == 1

0 comments on commit bb02f7d

Please sign in to comment.