mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
lightningd: trigger changed wait when delinvoice desconly used.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
cbdfc75bde
commit
6782c2fef5
5 changed files with 43 additions and 8 deletions
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue