diff --git a/lightningd/invoice.c b/lightningd/invoice.c index b3ab3913b..867c3f5b2 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -1371,7 +1371,8 @@ static struct command_result *json_delinvoice(struct command *cmd, return command_fail(cmd, INVOICE_NO_DESCRIPTION, "Invoice description already removed"); - if (!invoices_delete_description(wallet->invoices, inv_dbid)) { + if (!invoices_delete_description(wallet->invoices, inv_dbid, + details->label, details->description)) { log_broken(cmd->ld->log, "Error attempting to delete description of invoice %"PRIu64, inv_dbid); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 1fe147b4e..a7e2a127f 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -374,7 +374,9 @@ bool invoices_delete(struct invoices *invoices UNNEEDED, { fprintf(stderr, "invoices_delete called!\n"); abort(); } /* Generated stub for invoices_delete_description */ bool invoices_delete_description(struct invoices *invoices UNNEEDED, - u64 inv_dbid UNNEEDED) + u64 inv_dbid UNNEEDED, + const struct json_escape *label UNNEEDED, + const char *description UNNEEDED) { fprintf(stderr, "invoices_delete_description called!\n"); abort(); } /* Generated stub for invoices_delete_expired */ void invoices_delete_expired(struct invoices *invoices UNNEEDED, diff --git a/tests/test_invoices.py b/tests/test_invoices.py index 16c724d3f..d09419208 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -799,7 +799,7 @@ def test_wait_invoices(node_factory, executor): # Creating a new on gives us 3, not another 2! waitfut = executor.submit(l2.rpc.call, 'wait', {'subsystem': 'invoices', 'indexname': 'created', 'nextvalue': 3}) time.sleep(1) - inv = l2.rpc.invoice(42, 'invlabel2', 'invdesc2') + inv = l2.rpc.invoice(42, 'invlabel2', 'invdesc2', deschashonly=True) waitres = waitfut.result(TIMEOUT) assert waitres == {'subsystem': 'invoices', 'created': 3, @@ -807,6 +807,15 @@ def test_wait_invoices(node_factory, executor): 'bolt11': inv['bolt11'], 'status': 'unpaid'}} + # Deleting a description causes updated to fire! + waitfut = executor.submit(l2.rpc.call, 'wait', {'subsystem': 'invoices', 'indexname': 'updated', 'nextvalue': 3}) + time.sleep(1) + l2.rpc.delinvoice('invlabel2', status='unpaid', desconly=True) + waitres = waitfut.result(TIMEOUT) + assert waitres == {'subsystem': 'invoices', + 'updated': 3, + 'details': {'label': 'invlabel2', 'description': 'invdesc2'}} + def test_invoice_deschash(node_factory, chainparams): l1, l2 = node_factory.line_graph(2) diff --git a/wallet/invoices.c b/wallet/invoices.c index 3dca73897..361f78d9e 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -421,14 +421,21 @@ bool invoices_delete(struct invoices *invoices, u64 inv_dbid, return true; } -bool invoices_delete_description(struct invoices *invoices, u64 inv_dbid) +bool invoices_delete_description(struct invoices *invoices, u64 inv_dbid, + const struct json_escape *label, + const char *description) { struct db_stmt *stmt; int changes; - stmt = db_prepare_v2(invoices->wallet->db, SQL("UPDATE invoices" - " SET description = NULL" - " WHERE ID = ?;")); + stmt = db_prepare_v2(invoices->wallet->db, + SQL("UPDATE invoices" + " SET description = NULL," + " updated_index = ?" + " WHERE ID = ?;")); + db_bind_u64(stmt, + invoice_index_update_deldesc(invoices->wallet->ld, + label, description)); db_bind_u64(stmt, inv_dbid); db_exec_prepared_v2(stmt); @@ -746,3 +753,12 @@ u64 invoice_index_update_status(struct lightningd *ld, return invoice_index_inc(ld, &state, label, NULL, NULL, WAIT_INDEX_UPDATED); } + +u64 invoice_index_update_deldesc(struct lightningd *ld, + const struct json_escape *label, + const char *description) +{ + assert(description); + return invoice_index_inc(ld, NULL, label, NULL, description, + WAIT_INDEX_UPDATED); +} diff --git a/wallet/invoices.h b/wallet/invoices.h index e0cbccd28..001c285a0 100644 --- a/wallet/invoices.h +++ b/wallet/invoices.h @@ -121,7 +121,9 @@ bool invoices_delete(struct invoices *invoices, * Return false on failure. */ bool invoices_delete_description(struct invoices *invoices, - u64 inv_dbid); + u64 inv_dbid, + const struct json_escape *label, + const char *description); /** * invoices_delete_expired - Delete all expired invoices @@ -237,6 +239,11 @@ u64 invoice_index_update_status(struct lightningd *ld, const struct json_escape *label, enum invoice_status state); +/* Returns the current updated_index, and increments it. */ +u64 invoice_index_update_deldesc(struct lightningd *ld, + const struct json_escape *label, + const char *description); + void invoice_index_deleted(struct lightningd *ld, enum invoice_status state, const struct json_escape *label,