Skip to content

Commit fd33aed

Browse files
vincenzopalazzorustyrussell
authored andcommitted
rpc: Integrate the status flow in the listsendpays command
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent eaec226 commit fd33aed

File tree

8 files changed

+446
-7
lines changed

8 files changed

+446
-7
lines changed

lightningd/offer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static struct command_result *prev_payment(struct command *cmd,
282282
bool prev_paid = false;
283283

284284
assert(!invreq->payer_info);
285-
payments = wallet_payment_list(cmd, cmd->ld->wallet, NULL);
285+
payments = wallet_payment_list(cmd, cmd->ld->wallet, NULL, NULL);
286286

287287
for (size_t i = 0; i < tal_count(payments); i++) {
288288
const struct tlv_invoice *inv;

lightningd/pay.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ send_payment_core(struct lightningd *ld,
860860
bool have_complete = false;
861861

862862
/* Now, do we already have one or more payments? */
863-
payments = wallet_payment_list(tmpctx, ld->wallet, rhash);
863+
payments = wallet_payment_list(tmpctx, ld->wallet, rhash, NULL);
864864
for (size_t i = 0; i < tal_count(payments); i++) {
865865
log_debug(ld->log, "Payment %zu/%zu: %s %s",
866866
i, tal_count(payments),
@@ -1516,12 +1516,13 @@ static struct command_result *json_listsendpays(struct command *cmd,
15161516
const struct wallet_payment **payments;
15171517
struct json_stream *response;
15181518
struct sha256 *rhash;
1519-
const char *invstring;
1519+
const char *invstring, *status_str;
15201520

15211521
if (!param(cmd, buffer, params,
15221522
/* FIXME: parameter should be invstring now */
15231523
p_opt("bolt11", param_string, &invstring),
15241524
p_opt("payment_hash", param_sha256, &rhash),
1525+
p_opt("status", param_string, &status_str),
15251526
NULL))
15261527
return command_param_failed();
15271528

@@ -1553,7 +1554,14 @@ static struct command_result *json_listsendpays(struct command *cmd,
15531554
}
15541555
}
15551556

1556-
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash);
1557+
if (status_str) {
1558+
enum wallet_payment_status status;
1559+
1560+
if (!string_to_payment_status(status_str, &status))
1561+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Unrecognized status: %s", status_str);
1562+
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, &status);
1563+
} else
1564+
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, NULL);
15571565

15581566
response = json_stream_success(cmd);
15591567

@@ -1606,7 +1614,7 @@ static struct command_result *json_delpay(struct command *cmd,
16061614
payment_status_to_string(status));
16071615
}
16081616

1609-
payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash);
1617+
payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash, NULL);
16101618

16111619
if (tal_count(payments) == 0)
16121620
return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Unknown payment with payment_hash: %s",

tests/test_pay.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4613,3 +4613,26 @@ def test_pay_low_max_htlcs(node_factory):
46134613
l1.daemon.wait_for_log(
46144614
r'Number of pre-split HTLCs \([0-9]+\) exceeds our HTLC budget \([0-9]+\), skipping pre-splitter'
46154615
)
4616+
4617+
4618+
def test_listpays_with_filter_by_status(node_factory, bitcoind):
4619+
"""
4620+
This test check if the filtering by status of the command listpays
4621+
has some mistakes.
4622+
"""
4623+
4624+
# Create the line graph l2 -> l1 with a channel of 10 ** 5 sat!
4625+
l2, l1 = node_factory.line_graph(2, fundamount=10**5, wait_for_announce=True)
4626+
4627+
inv = l1.rpc.invoice(10 ** 5, 'inv', 'inv')
4628+
l2.rpc.pay(inv['bolt11'])
4629+
4630+
wait_for(lambda: l2.rpc.listpays(inv['bolt11'])['pays'][0]['status'] == 'complete')
4631+
4632+
# test if the node is still ready
4633+
payments = l2.rpc.call("listpays", {"status": 'failed'})
4634+
4635+
assert len(payments['pays']) == 0
4636+
4637+
payments = l2.rpc.listpays()
4638+
assert len(l2.rpc.listpays()['pays']) == 1

wallet/db_postgres_sqlgen.c

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wallet/db_sqlite3_sqlgen.c

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)