wallet: add invoice features into db.

In a future version, we will use features to insist that payers
provide the secret.  In transition, we may have old invoices which
didn't insist on that, so we need to know this on a per-invoice basis.

Not sure if I got the right syntax for adding an empty blob though!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-11-23 10:49:23 +10:30
parent 09cdbb70eb
commit 81c89aaef8
8 changed files with 19 additions and 3 deletions

View file

@ -502,6 +502,7 @@ static void gossipd_incoming_channels_reply(struct subd *gossipd,
info->b11->expiry,
b11enc,
info->b11->description,
info->b11->features,
&info->payment_preimage,
&info->b11->payment_hash)) {
was_pending(command_fail(info->cmd, INVOICE_LABEL_ALREADY_EXISTS,

View file

@ -510,6 +510,7 @@ bool wallet_invoice_create(struct wallet *wallet UNNEEDED,
u64 expiry UNNEEDED,
const char *b11enc UNNEEDED,
const char *description UNNEEDED,
const u8 *features UNNEEDED,
const struct preimage *r UNNEEDED,
const struct sha256 *rhash UNNEEDED)
{ fprintf(stderr, "wallet_invoice_create called!\n"); abort(); }

View file

@ -480,6 +480,7 @@ static struct migration dbmigrations[] = {
/* See https://github.com/ElementsProject/lightning/issues/3189 */
{SQL("UPDATE forwarded_payments SET received_time=0 WHERE received_time IS NULL;"),
NULL},
{SQL("ALTER TABLE invoices ADD COLUMN features BLOB DEFAULT '';"), NULL},
};
/* Leak tracking. */

View file

@ -116,6 +116,9 @@ static struct invoice_details *wallet_stmt2invoice_details(const tal_t *ctx,
else
dtl->description = NULL;
dtl->features = tal_dup_arr(dtl, u8,
db_column_blob(stmt, 11),
db_column_bytes(stmt, 11), 0);
return dtl;
}
@ -253,6 +256,7 @@ bool invoices_create(struct invoices *invoices,
u64 expiry,
const char *b11enc,
const char *description,
const u8 *features,
const struct preimage *r,
const struct sha256 *rhash)
{
@ -279,11 +283,11 @@ bool invoices_create(struct invoices *invoices,
" ( payment_hash, payment_key, state"
" , msatoshi, label, expiry_time"
" , pay_index, msatoshi_received"
" , paid_timestamp, bolt11, description)"
" , paid_timestamp, bolt11, description, features)"
" VALUES ( ?, ?, ?"
" , ?, ?, ?"
" , NULL, NULL"
" , NULL, ?, ?);"));
" , NULL, ?, ?, ?);"));
db_bind_sha256(stmt, 0, rhash);
db_bind_preimage(stmt, 1, r);
@ -296,6 +300,7 @@ bool invoices_create(struct invoices *invoices,
db_bind_u64(stmt, 5, expiry_time);
db_bind_text(stmt, 6, b11enc);
db_bind_text(stmt, 7, description);
db_bind_blob(stmt, 8, features, tal_bytelen(features));
db_exec_prepared_v2(stmt);
@ -435,6 +440,7 @@ bool invoices_iterate(struct invoices *invoices,
", paid_timestamp"
", bolt11"
", description"
", features"
" FROM invoices;"));
db_query_prepared(stmt);
it->p = stmt;
@ -622,6 +628,7 @@ const struct invoice_details *invoices_get_details(const tal_t *ctx,
", paid_timestamp"
", bolt11"
", description"
", features"
" FROM invoices"
" WHERE id = ?;"));
db_bind_u64(stmt, 0, invoice.id);

View file

@ -50,6 +50,7 @@ bool invoices_create(struct invoices *invoices,
u64 expiry,
const char *b11enc,
const char *description,
const u8 *features,
const struct preimage *r,
const struct sha256 *rhash);

View file

@ -138,6 +138,7 @@ bool invoices_create(struct invoices *invoices UNNEEDED,
u64 expiry UNNEEDED,
const char *b11enc UNNEEDED,
const char *description UNNEEDED,
const u8 *features UNNEEDED,
const struct preimage *r UNNEEDED,
const struct sha256 *rhash UNNEEDED)
{ fprintf(stderr, "invoices_create called!\n"); abort(); }

View file

@ -1931,10 +1931,11 @@ bool wallet_invoice_create(struct wallet *wallet,
u64 expiry,
const char *b11enc,
const char *description,
const u8 *features,
const struct preimage *r,
const struct sha256 *rhash)
{
return invoices_create(wallet->invoices, pinvoice, msat, label, expiry, b11enc, description, r, rhash);
return invoices_create(wallet->invoices, pinvoice, msat, label, expiry, b11enc, description, features, r, rhash);
}
bool wallet_invoice_find_by_label(struct wallet *wallet,
struct invoice *pinvoice,

View file

@ -673,6 +673,8 @@ struct invoice_details {
/* The description of the payment. */
char *description;
/* The features, if any (tal_arr) */
u8 *features;
};
/* An object that handles iteration over the set of invoices */
@ -713,6 +715,7 @@ bool wallet_invoice_create(struct wallet *wallet,
u64 expiry,
const char *b11enc,
const char *description,
const u8 *features,
const struct preimage *r,
const struct sha256 *rhash);