From bbf4f312a41fabd65970e0742db0928f190e4ed7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 22 Jul 2023 17:16:18 +0930 Subject: [PATCH] invoice: include invoice label to wait subsystem when it's paid. Signed-off-by: Rusty Russell --- lightningd/invoice.c | 3 ++- lightningd/test/run-invoice-select-inchan.c | 3 ++- tests/test_invoices.py | 4 +--- wallet/invoices.c | 6 +++--- wallet/invoices.h | 4 +++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 867c3f5b2..e44646329 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -315,7 +315,8 @@ invoice_payment_hooks_done(struct invoice_payment_hook_payload *payload STEALS) } /* Paid or expired in the meantime. */ - if (!invoices_resolve(ld->wallet->invoices, inv_dbid, payload->msat)) { + if (!invoices_resolve(ld->wallet->invoices, inv_dbid, payload->msat, + payload->label)) { htlc_set_fail(payload->set, take(failmsg_incorrect_or_unknown( NULL, ld, payload->set->htlcs[0]))); return; diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index a7e2a127f..bab040aa9 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -414,7 +414,8 @@ struct db_stmt *invoices_next(struct invoices *invoices UNNEEDED, /* Generated stub for invoices_resolve */ bool invoices_resolve(struct invoices *invoices UNNEEDED, u64 inv_dbid UNNEEDED, - struct amount_msat received UNNEEDED) + struct amount_msat received UNNEEDED, + const struct json_escape *label UNNEEDED) { fprintf(stderr, "invoices_resolve called!\n"); abort(); } /* Generated stub for invoices_waitany */ void invoices_waitany(const tal_t *ctx UNNEEDED, diff --git a/tests/test_invoices.py b/tests/test_invoices.py index d09419208..3626165eb 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -744,9 +744,7 @@ def test_wait_invoices(node_factory, executor): waitres = waitfut.result(TIMEOUT) assert waitres == {'subsystem': 'invoices', 'updated': 1, - # FIXME: fill in details! - # {'label': 'invlabel', 'bolt11': inv['bolt11'], 'status': 'paid'} - 'details': {'status': 'paid'}} + 'details': {'label': 'invlabel', 'status': 'paid'}} # Second returns instantly, without any details. waitres = l2.rpc.call('wait', {'subsystem': 'invoices', 'indexname': 'updated', 'nextvalue': 1}) diff --git a/wallet/invoices.c b/wallet/invoices.c index 361f78d9e..3c6fd7f70 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -545,7 +545,8 @@ static void maybe_mark_offer_used(struct db *db, u64 inv_dbid) bool invoices_resolve(struct invoices *invoices, u64 inv_dbid, - struct amount_msat received) + struct amount_msat received, + const struct json_escape *label) { struct db_stmt *stmt; s64 pay_index; @@ -571,10 +572,9 @@ bool invoices_resolve(struct invoices *invoices, db_bind_u64(stmt, pay_index); db_bind_amount_msat(stmt, &received); db_bind_u64(stmt, paid_timestamp); - /* FIXME: populate label */ db_bind_u64(stmt, invoice_index_update_status(invoices->wallet->ld, - NULL, PAID)); + label, PAID)); db_bind_u64(stmt, inv_dbid); db_exec_prepared_v2(take(stmt)); diff --git a/wallet/invoices.h b/wallet/invoices.h index 001c285a0..16ca3584d 100644 --- a/wallet/invoices.h +++ b/wallet/invoices.h @@ -165,12 +165,14 @@ struct db_stmt *invoices_next(struct invoices *invoices, * @invoices - the invoice handler. * @inv_dbid - the invoice to mark as paid. * @received - the actual amount received. + * @label - the label of the invoice. * * If the invoice is not UNPAID, returns false. */ bool invoices_resolve(struct invoices *invoices, u64 inv_dbid, - struct amount_msat received); + struct amount_msat received, + const struct json_escape *label); /** * invoices_waitany - Wait for any invoice to be paid.