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

@@ -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);