From e302d6193c8e8eb47544a8e17ac6a15aafe6a6db Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 21 Nov 2017 16:57:28 +1030 Subject: [PATCH] invoice: store expiry time in db. This is backwards-compat: sets existing expiry for invoices to ~infinity. Signed-off-by: Rusty Russell --- wallet/db.c | 3 +++ wallet/wallet.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index a8a341c2e..2904c779c 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -131,6 +131,9 @@ char *dbmigrations[] = { " PRIMARY KEY (id)," " UNIQUE (payment_hash)" ");", + /* Add expiry field to invoices (effectively infinite). */ + "ALTER TABLE invoices ADD expiry_time INTEGER;", + "UPDATE invoices SET expiry_time=9223372036854775807;", NULL, }; diff --git a/wallet/wallet.c b/wallet/wallet.c index ae398aba3..77d340961 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1057,13 +1057,14 @@ void wallet_invoice_save(struct wallet *wallet, struct invoice *inv) sqlite3_stmt *stmt; if (!inv->id) { stmt = db_prepare(wallet->db, - "INSERT INTO invoices (payment_hash, payment_key, state, msatoshi, label) VALUES (?, ?, ?, ?, ?);"); + "INSERT INTO invoices (payment_hash, payment_key, state, msatoshi, label, expiry_time) VALUES (?, ?, ?, ?, ?, ?);"); sqlite3_bind_blob(stmt, 1, &inv->rhash, sizeof(inv->rhash), SQLITE_TRANSIENT); sqlite3_bind_blob(stmt, 2, &inv->r, sizeof(inv->r), SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 3, inv->state); sqlite3_bind_int64(stmt, 4, inv->msatoshi); sqlite3_bind_text(stmt, 5, inv->label, strlen(inv->label), SQLITE_TRANSIENT); + sqlite3_bind_int64(stmt, 6, inv->expiry_time); db_exec_prepared(wallet->db, stmt); @@ -1091,6 +1092,7 @@ 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->msatoshi = sqlite3_column_int64(stmt, 5); + inv->expiry_time = sqlite3_column_int64(stmt, 6); return true; } @@ -1100,7 +1102,7 @@ bool wallet_invoices_load(struct wallet *wallet, struct invoices *invs) int count = 0; sqlite3_stmt *stmt = db_query(__func__, wallet->db, "SELECT id, state, payment_key, payment_hash, " - "label, msatoshi FROM invoices;"); + "label, msatoshi, expiry_time FROM invoices;"); if (!stmt) { log_broken(wallet->log, "Could not load invoices"); return false;