mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
invoice: Add pay_index member to struct invoice.
In preparation for change in interface of waitanyinvoice.
This commit is contained in:
parent
202868b677
commit
3003b7346c
@ -184,6 +184,7 @@ static void json_invoice(struct command *cmd,
|
|||||||
invoice = tal(cmd, struct invoice);
|
invoice = tal(cmd, struct invoice);
|
||||||
invoice->id = 0;
|
invoice->id = 0;
|
||||||
invoice->state = UNPAID;
|
invoice->state = UNPAID;
|
||||||
|
invoice->pay_index = 0;
|
||||||
list_head_init(&invoice->invoice_waiters);
|
list_head_init(&invoice->invoice_waiters);
|
||||||
randombytes_buf(invoice->r.r, sizeof(invoice->r.r));
|
randombytes_buf(invoice->r.r, sizeof(invoice->r.r));
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ struct invoice {
|
|||||||
struct preimage r;
|
struct preimage r;
|
||||||
u64 expiry_time;
|
u64 expiry_time;
|
||||||
struct sha256 rhash;
|
struct sha256 rhash;
|
||||||
|
u64 pay_index;
|
||||||
struct list_head invoice_waiters;
|
struct list_head invoice_waiters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1220,7 +1220,6 @@ static enum invoice_status wallet_invoice_db_state(
|
|||||||
void wallet_invoice_save(struct wallet *wallet, struct invoice *inv)
|
void wallet_invoice_save(struct wallet *wallet, struct invoice *inv)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
s64 pay_index;
|
|
||||||
bool unpaid_to_paid = false;
|
bool unpaid_to_paid = false;
|
||||||
|
|
||||||
/* Need to use the lower level API of sqlite3 to bind
|
/* Need to use the lower level API of sqlite3 to bind
|
||||||
@ -1237,8 +1236,8 @@ void wallet_invoice_save(struct wallet *wallet, struct invoice *inv)
|
|||||||
sqlite3_bind_text(stmt, 5, inv->label, strlen(inv->label), SQLITE_TRANSIENT);
|
sqlite3_bind_text(stmt, 5, inv->label, strlen(inv->label), SQLITE_TRANSIENT);
|
||||||
sqlite3_bind_int64(stmt, 6, inv->expiry_time);
|
sqlite3_bind_int64(stmt, 6, inv->expiry_time);
|
||||||
if (inv->state == PAID) {
|
if (inv->state == PAID) {
|
||||||
pay_index = wallet_invoice_next_pay_index(wallet->db);
|
inv->pay_index = wallet_invoice_next_pay_index(wallet->db);
|
||||||
sqlite3_bind_int64(stmt, 7, pay_index);
|
sqlite3_bind_int64(stmt, 7, inv->pay_index);
|
||||||
} else {
|
} else {
|
||||||
sqlite3_bind_null(stmt, 7);
|
sqlite3_bind_null(stmt, 7);
|
||||||
}
|
}
|
||||||
@ -1256,8 +1255,8 @@ void wallet_invoice_save(struct wallet *wallet, struct invoice *inv)
|
|||||||
stmt = db_prepare(wallet->db, "UPDATE invoices SET state=?, pay_index=? WHERE id=?;");
|
stmt = db_prepare(wallet->db, "UPDATE invoices SET state=?, pay_index=? WHERE id=?;");
|
||||||
|
|
||||||
sqlite3_bind_int(stmt, 1, inv->state);
|
sqlite3_bind_int(stmt, 1, inv->state);
|
||||||
pay_index = wallet_invoice_next_pay_index(wallet->db);
|
inv->pay_index = wallet_invoice_next_pay_index(wallet->db);
|
||||||
sqlite3_bind_int64(stmt, 2, pay_index);
|
sqlite3_bind_int64(stmt, 2, inv->pay_index);
|
||||||
sqlite3_bind_int64(stmt, 3, inv->id);
|
sqlite3_bind_int64(stmt, 3, inv->id);
|
||||||
|
|
||||||
db_exec_prepared(wallet->db, stmt);
|
db_exec_prepared(wallet->db, stmt);
|
||||||
@ -1286,6 +1285,8 @@ static bool wallet_stmt2invoice(sqlite3_stmt *stmt, struct invoice *inv)
|
|||||||
inv->label = tal_strndup(inv, sqlite3_column_blob(stmt, 4), sqlite3_column_bytes(stmt, 4));
|
inv->label = tal_strndup(inv, sqlite3_column_blob(stmt, 4), sqlite3_column_bytes(stmt, 4));
|
||||||
inv->msatoshi = sqlite3_column_int64(stmt, 5);
|
inv->msatoshi = sqlite3_column_int64(stmt, 5);
|
||||||
inv->expiry_time = sqlite3_column_int64(stmt, 6);
|
inv->expiry_time = sqlite3_column_int64(stmt, 6);
|
||||||
|
/* Correctly 0 if pay_index is NULL. */
|
||||||
|
inv->pay_index = sqlite3_column_int64(stmt, 7);
|
||||||
|
|
||||||
list_head_init(&inv->invoice_waiters);
|
list_head_init(&inv->invoice_waiters);
|
||||||
return true;
|
return true;
|
||||||
@ -1297,7 +1298,8 @@ bool wallet_invoices_load(struct wallet *wallet, struct invoices *invs)
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
sqlite3_stmt *stmt = db_query(__func__, wallet->db,
|
sqlite3_stmt *stmt = db_query(__func__, wallet->db,
|
||||||
"SELECT id, state, payment_key, payment_hash, "
|
"SELECT id, state, payment_key, payment_hash, "
|
||||||
"label, msatoshi, expiry_time FROM invoices;");
|
"label, msatoshi, expiry_time, pay_index "
|
||||||
|
"FROM invoices;");
|
||||||
if (!stmt) {
|
if (!stmt) {
|
||||||
log_broken(wallet->log, "Could not load invoices");
|
log_broken(wallet->log, "Could not load invoices");
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user