mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
invoice: Assert that an invoice is unresolved when resolving it
This sort of flip-flop is really bad and we should never end up changing the state of a resolved invoice.
This commit is contained in:
committed by
Rusty Russell
parent
2a2341c56c
commit
762ab5f056
@@ -496,6 +496,21 @@ static s64 get_next_pay_index(struct db *db)
|
|||||||
return next_pay_index;
|
return next_pay_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum invoice_status invoice_get_status(struct invoices *invoices, struct invoice invoice)
|
||||||
|
{
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
enum invoice_status state;
|
||||||
|
bool res;
|
||||||
|
|
||||||
|
stmt = db_select_prepare(invoices->db,
|
||||||
|
"state FROM invoices WHERE id = ?;");
|
||||||
|
sqlite3_bind_int64(stmt, 1, invoice.id);
|
||||||
|
res = db_select_step(invoices->db, stmt);
|
||||||
|
assert(res);
|
||||||
|
state = sqlite3_column_int(stmt, 0);
|
||||||
|
db_stmt_done(stmt);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
void invoices_resolve(struct invoices *invoices,
|
void invoices_resolve(struct invoices *invoices,
|
||||||
struct invoice invoice,
|
struct invoice invoice,
|
||||||
@@ -504,6 +519,9 @@ void invoices_resolve(struct invoices *invoices,
|
|||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
s64 pay_index;
|
s64 pay_index;
|
||||||
u64 paid_timestamp;
|
u64 paid_timestamp;
|
||||||
|
enum invoice_status state = invoice_get_status(invoices, invoice);
|
||||||
|
|
||||||
|
assert(state == UNPAID);
|
||||||
|
|
||||||
/* Assign a pay-index. */
|
/* Assign a pay-index. */
|
||||||
pay_index = get_next_pay_index(invoices->db);
|
pay_index = get_next_pay_index(invoices->db);
|
||||||
@@ -589,25 +607,14 @@ void invoices_waitany(const tal_t *ctx,
|
|||||||
|
|
||||||
|
|
||||||
void invoices_waitone(const tal_t *ctx,
|
void invoices_waitone(const tal_t *ctx,
|
||||||
struct invoices *invoices UNUSED,
|
struct invoices *invoices,
|
||||||
struct invoice invoice,
|
struct invoice invoice,
|
||||||
void (*cb)(const struct invoice *, void*),
|
void (*cb)(const struct invoice *, void*),
|
||||||
void *cbarg)
|
void *cbarg)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
|
||||||
bool res;
|
|
||||||
enum invoice_status state;
|
enum invoice_status state;
|
||||||
|
|
||||||
stmt = db_select_prepare(invoices->db,
|
state = invoice_get_status(invoices, invoice);
|
||||||
"state"
|
|
||||||
" FROM invoices"
|
|
||||||
" WHERE id = ?;");
|
|
||||||
sqlite3_bind_int64(stmt, 1, invoice.id);
|
|
||||||
|
|
||||||
res = db_select_step(invoices->db, stmt);
|
|
||||||
assert(res);
|
|
||||||
state = sqlite3_column_int(stmt, 0);
|
|
||||||
db_stmt_done(stmt);
|
|
||||||
|
|
||||||
if (state == PAID || state == EXPIRED) {
|
if (state == PAID || state == EXPIRED) {
|
||||||
cb(&invoice, cbarg);
|
cb(&invoice, cbarg);
|
||||||
|
|||||||
Reference in New Issue
Block a user