diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 4fbae7d20..ce05b9fb8 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -71,6 +71,8 @@ static void json_add_invoice(struct json_stream *response, json_add_string(response, "description", inv->description); json_add_u64(response, "expires_at", inv->expiry_time); + if (inv->local_offer_id) + json_add_sha256(response, "local_offer_id", inv->local_offer_id); } static struct command_result *tell_waiter(struct command *cmd, @@ -698,7 +700,8 @@ static void gossipd_incoming_channels_reply(struct subd *gossipd, info->b11->description, info->b11->features, &info->payment_preimage, - &info->b11->payment_hash)) { + &info->b11->payment_hash, + NULL)) { was_pending(command_fail(info->cmd, INVOICE_LABEL_ALREADY_EXISTS, "Duplicate label '%s'", info->label->s)); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index de19c1211..0a4439070 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -609,7 +609,8 @@ bool wallet_invoice_create(struct wallet *wallet UNNEEDED, const char *description UNNEEDED, const u8 *features UNNEEDED, const struct preimage *r UNNEEDED, - const struct sha256 *rhash UNNEEDED) + const struct sha256 *rhash UNNEEDED, + const struct sha256 *local_offer_id UNNEEDED) { fprintf(stderr, "wallet_invoice_create called!\n"); abort(); } /* Generated stub for wallet_invoice_delete */ bool wallet_invoice_delete(struct wallet *wallet UNNEEDED, diff --git a/wallet/db.c b/wallet/db.c index a8f5305ba..5a0b69002 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -664,6 +664,8 @@ static struct migration dbmigrations[] = { ", status INTEGER" ", PRIMARY KEY (offer_id)" ");"), NULL}, + /* A reference into our own offers table, if it was made from one */ + {SQL("ALTER TABLE invoices ADD COLUMN local_offer_id BLOB DEFAULT NULL;"), NULL}, }; /* Leak tracking. */ diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 28e88d554..ca8f1e9db 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -854,6 +854,12 @@ struct db_query db_postgres_queries[] = { .placeholders = 0, .readonly = false, }, + { + .name = "ALTER TABLE invoices ADD COLUMN local_offer_id BLOB DEFAULT NULL;", + .query = "ALTER TABLE invoices ADD COLUMN local_offer_id BYTEA DEFAULT NULL;", + .placeholders = 0, + .readonly = false, + }, { .name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?", .query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = $1", @@ -969,9 +975,9 @@ struct db_query db_postgres_queries[] = { .readonly = true, }, { - .name = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);", - .query = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( $1, $2, $3 , $4, $5, $6 , NULL, NULL , NULL, $7, $8, $9);", - .placeholders = 9, + .name = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features, local_offer_id) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?, ?);", + .query = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features, local_offer_id) VALUES ( $1, $2, $3 , $4, $5, $6 , NULL, NULL , NULL, $7, $8, $9, $10);", + .placeholders = 10, .readonly = false, }, { @@ -1016,6 +1022,12 @@ struct db_query db_postgres_queries[] = { .placeholders = 1, .readonly = true, }, + { + .name = "SELECT local_offer_id FROM invoices WHERE id = ?;", + .query = "SELECT local_offer_id FROM invoices WHERE id = $1;", + .placeholders = 1, + .readonly = true, + }, { .name = "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;", .query = "UPDATE invoices SET state=$1 , pay_index=$2 , msatoshi_received=$3 , paid_timestamp=$4 WHERE id=$5;", @@ -1029,8 +1041,8 @@ struct db_query db_postgres_queries[] = { .readonly = true, }, { - .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;", - .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = $1;", + .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features, local_offer_id FROM invoices WHERE id = ?;", + .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features, local_offer_id FROM invoices WHERE id = $1;", .placeholders = 1, .readonly = true, }, @@ -1701,8 +1713,8 @@ struct db_query db_postgres_queries[] = { .readonly = false, }, { - .name = "UPDATE invoices SET state=? WHERE state=? AND offer_id = ?;", - .query = "UPDATE invoices SET state=$1 WHERE state=$2 AND offer_id = $3;", + .name = "UPDATE invoices SET state=? WHERE state=? AND local_offer_id = ?;", + .query = "UPDATE invoices SET state=$1 WHERE state=$2 AND local_offer_id = $3;", .placeholders = 3, .readonly = false, }, @@ -1732,10 +1744,10 @@ struct db_query db_postgres_queries[] = { }, }; -#define DB_POSTGRES_QUERY_COUNT 287 +#define DB_POSTGRES_QUERY_COUNT 289 #endif /* HAVE_POSTGRES */ #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:94af743741cd2a2d8725371af12e130a692334a118b52386fb901fadfe25d4cd +// SHA256STAMP:83a4b63d1c5566db35ab00e9da60f6c98c04f8bd30800e51cce294dfcb49c9ec diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index b1331d3b2..6686c5ae3 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -854,6 +854,12 @@ struct db_query db_sqlite3_queries[] = { .placeholders = 0, .readonly = false, }, + { + .name = "ALTER TABLE invoices ADD COLUMN local_offer_id BLOB DEFAULT NULL;", + .query = "ALTER TABLE invoices ADD COLUMN local_offer_id BLOB DEFAULT NULL;", + .placeholders = 0, + .readonly = false, + }, { .name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?", .query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?", @@ -969,9 +975,9 @@ struct db_query db_sqlite3_queries[] = { .readonly = true, }, { - .name = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);", - .query = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);", - .placeholders = 9, + .name = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features, local_offer_id) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?, ?);", + .query = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features, local_offer_id) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?, ?);", + .placeholders = 10, .readonly = false, }, { @@ -1016,6 +1022,12 @@ struct db_query db_sqlite3_queries[] = { .placeholders = 1, .readonly = true, }, + { + .name = "SELECT local_offer_id FROM invoices WHERE id = ?;", + .query = "SELECT local_offer_id FROM invoices WHERE id = ?;", + .placeholders = 1, + .readonly = true, + }, { .name = "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;", .query = "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;", @@ -1029,8 +1041,8 @@ struct db_query db_sqlite3_queries[] = { .readonly = true, }, { - .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;", - .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;", + .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features, local_offer_id FROM invoices WHERE id = ?;", + .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features, local_offer_id FROM invoices WHERE id = ?;", .placeholders = 1, .readonly = true, }, @@ -1701,8 +1713,8 @@ struct db_query db_sqlite3_queries[] = { .readonly = false, }, { - .name = "UPDATE invoices SET state=? WHERE state=? AND offer_id = ?;", - .query = "UPDATE invoices SET state=? WHERE state=? AND offer_id = ?;", + .name = "UPDATE invoices SET state=? WHERE state=? AND local_offer_id = ?;", + .query = "UPDATE invoices SET state=? WHERE state=? AND local_offer_id = ?;", .placeholders = 3, .readonly = false, }, @@ -1732,10 +1744,10 @@ struct db_query db_sqlite3_queries[] = { }, }; -#define DB_SQLITE3_QUERY_COUNT 287 +#define DB_SQLITE3_QUERY_COUNT 289 #endif /* HAVE_SQLITE3 */ #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:94af743741cd2a2d8725371af12e130a692334a118b52386fb901fadfe25d4cd +// SHA256STAMP:83a4b63d1c5566db35ab00e9da60f6c98c04f8bd30800e51cce294dfcb49c9ec diff --git a/wallet/invoices.c b/wallet/invoices.c index e88668ddd..8f5072ee5 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -119,6 +119,12 @@ static struct invoice_details *wallet_stmt2invoice_details(const tal_t *ctx, dtl->features = tal_dup_arr(dtl, u8, db_column_blob(stmt, 11), db_column_bytes(stmt, 11), 0); + if (!db_column_is_null(stmt, 12)) { + dtl->local_offer_id = tal(dtl, struct sha256); + db_column_sha256(stmt, 12, dtl->local_offer_id); + } else + dtl->local_offer_id = NULL; + return dtl; } @@ -258,7 +264,8 @@ bool invoices_create(struct invoices *invoices, const char *description, const u8 *features, const struct preimage *r, - const struct sha256 *rhash) + const struct sha256 *rhash, + const struct sha256 *local_offer_id) { struct db_stmt *stmt; struct invoice dummy; @@ -283,11 +290,11 @@ bool invoices_create(struct invoices *invoices, " ( payment_hash, payment_key, state" " , msatoshi, label, expiry_time" " , pay_index, msatoshi_received" - " , paid_timestamp, bolt11, description, features)" + " , paid_timestamp, bolt11, description, features, local_offer_id)" " VALUES ( ?, ?, ?" " , ?, ?, ?" " , NULL, NULL" - " , NULL, ?, ?, ?);")); + " , NULL, ?, ?, ?, ?);")); db_bind_sha256(stmt, 0, rhash); db_bind_preimage(stmt, 1, r); @@ -301,6 +308,10 @@ bool invoices_create(struct invoices *invoices, db_bind_text(stmt, 6, b11enc); db_bind_text(stmt, 7, description); db_bind_talarr(stmt, 8, features); + if (local_offer_id) + db_bind_sha256(stmt, 9, local_offer_id); + else + db_bind_null(stmt, 9); db_exec_prepared_v2(stmt); @@ -496,6 +507,28 @@ static enum invoice_status invoice_get_status(struct invoices *invoices, struct return state; } +/* If there's an associated offer, mark it used. */ +static void maybe_mark_offer_used(struct db *db, struct invoice invoice) +{ + struct db_stmt *stmt; + struct sha256 local_offer_id; + + stmt = db_prepare_v2( + db, SQL("SELECT local_offer_id FROM invoices WHERE id = ?;")); + db_bind_u64(stmt, 0, invoice.id); + db_query_prepared(stmt); + + db_step(stmt); + if (db_column_is_null(stmt, 0)) { + tal_free(stmt); + return; + } + db_column_sha256(stmt, 0, &local_offer_id); + tal_free(stmt); + + wallet_offer_mark_used(db, &local_offer_id); +} + bool invoices_resolve(struct invoices *invoices, struct invoice invoice, struct amount_msat received) @@ -526,6 +559,8 @@ bool invoices_resolve(struct invoices *invoices, db_bind_u64(stmt, 4, invoice.id); db_exec_prepared_v2(take(stmt)); + maybe_mark_offer_used(invoices->db, invoice); + /* Tell all the waiters about the paid invoice. */ trigger_invoice_waiter_resolve(invoices, invoice.id, &invoice); return true; @@ -632,6 +667,7 @@ const struct invoice_details *invoices_get_details(const tal_t *ctx, ", bolt11" ", description" ", features" + ", local_offer_id" " FROM invoices" " WHERE id = ?;")); db_bind_u64(stmt, 0, invoice.id); diff --git a/wallet/invoices.h b/wallet/invoices.h index 303b9a1dc..0e069cbb7 100644 --- a/wallet/invoices.h +++ b/wallet/invoices.h @@ -52,7 +52,8 @@ bool invoices_create(struct invoices *invoices, const char *description, const u8 *features, const struct preimage *r, - const struct sha256 *rhash); + const struct sha256 *rhash, + const struct sha256 *local_offer_id); /** * invoices_find_by_label - Search for an invoice by label diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 9b76e0113..faab3e85a 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -562,124 +562,132 @@ msgstr "" msgid "CREATE TABLE offers ( offer_id BLOB, bolt12 TEXT, label TEXT, status INTEGER, PRIMARY KEY (offer_id));" msgstr "" -#: wallet/db.c:893 +#: wallet/db.c:668 +msgid "ALTER TABLE invoices ADD COLUMN local_offer_id BLOB DEFAULT NULL;" +msgstr "" + +#: wallet/db.c:895 msgid "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?" msgstr "" -#: wallet/db.c:993 +#: wallet/db.c:995 msgid "SELECT version FROM version LIMIT 1" msgstr "" -#: wallet/db.c:1051 +#: wallet/db.c:1053 msgid "UPDATE version SET version=?;" msgstr "" -#: wallet/db.c:1059 +#: wallet/db.c:1061 msgid "INSERT INTO db_upgrades VALUES (?, ?);" msgstr "" -#: wallet/db.c:1071 +#: wallet/db.c:1073 msgid "SELECT intval FROM vars WHERE name = 'data_version'" msgstr "" -#: wallet/db.c:1098 +#: wallet/db.c:1100 msgid "SELECT intval FROM vars WHERE name= ? LIMIT 1" msgstr "" -#: wallet/db.c:1114 +#: wallet/db.c:1116 msgid "UPDATE vars SET intval=? WHERE name=?;" msgstr "" -#: wallet/db.c:1123 +#: wallet/db.c:1125 msgid "INSERT INTO vars (name, intval) VALUES (?, ?);" msgstr "" -#: wallet/db.c:1137 +#: wallet/db.c:1139 msgid "UPDATE channels SET feerate_base = ?, feerate_ppm = ?;" msgstr "" -#: wallet/db.c:1158 +#: wallet/db.c:1160 msgid "UPDATE channels SET our_funding_satoshi = funding_satoshi WHERE funder = 0;" msgstr "" -#: wallet/db.c:1174 +#: wallet/db.c:1176 msgid "SELECT type, keyindex, prev_out_tx, prev_out_index, channel_id, peer_id, commitment_point FROM outputs WHERE scriptpubkey IS NULL;" msgstr "" -#: wallet/db.c:1236 +#: wallet/db.c:1238 msgid "UPDATE outputs SET scriptpubkey = ? WHERE prev_out_tx = ? AND prev_out_index = ?" msgstr "" -#: wallet/db.c:1261 +#: wallet/db.c:1263 msgid "SELECT id, funding_tx_id, funding_tx_outnum FROM channels;" msgstr "" -#: wallet/db.c:1280 +#: wallet/db.c:1282 msgid "UPDATE channels SET full_channel_id = ? WHERE id = ?;" msgstr "" -#: wallet/db.c:1303 +#: wallet/db.c:1305 msgid "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;" msgstr "" -#: wallet/db.c:1370 +#: wallet/db.c:1372 msgid "UPDATE channels SET last_tx = ? WHERE id = ?;" msgstr "" -#: wallet/invoices.c:129 +#: wallet/invoices.c:135 msgid "UPDATE invoices SET state = ? WHERE state = ? AND expiry_time <= ?;" msgstr "" -#: wallet/invoices.c:177 +#: wallet/invoices.c:183 msgid "SELECT id FROM invoices WHERE state = ? AND expiry_time <= ?" msgstr "" -#: wallet/invoices.c:216 +#: wallet/invoices.c:222 msgid "SELECT MIN(expiry_time) FROM invoices WHERE state = ?;" msgstr "" -#: wallet/invoices.c:282 -msgid "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);" +#: wallet/invoices.c:289 +msgid "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features, local_offer_id) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?, ?);" msgstr "" -#: wallet/invoices.c:330 +#: wallet/invoices.c:341 msgid "SELECT id FROM invoices WHERE label = ?;" msgstr "" -#: wallet/invoices.c:352 +#: wallet/invoices.c:363 msgid "SELECT id FROM invoices WHERE payment_hash = ?;" msgstr "" -#: wallet/invoices.c:373 +#: wallet/invoices.c:384 msgid "SELECT id FROM invoices WHERE payment_hash = ? AND state = ?;" msgstr "" -#: wallet/invoices.c:397 +#: wallet/invoices.c:408 msgid "DELETE FROM invoices WHERE id=?;" msgstr "" -#: wallet/invoices.c:417 +#: wallet/invoices.c:428 msgid "DELETE FROM invoices WHERE state = ? AND expiry_time <= ?;" msgstr "" -#: wallet/invoices.c:431 +#: wallet/invoices.c:442 msgid "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices ORDER BY id;" msgstr "" -#: wallet/invoices.c:488 +#: wallet/invoices.c:499 msgid "SELECT state FROM invoices WHERE id = ?;" msgstr "" -#: wallet/invoices.c:516 +#: wallet/invoices.c:517 +msgid "SELECT local_offer_id FROM invoices WHERE id = ?;" +msgstr "" + +#: wallet/invoices.c:549 msgid "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;" msgstr "" -#: wallet/invoices.c:573 +#: wallet/invoices.c:608 msgid "SELECT id FROM invoices WHERE pay_index IS NOT NULL AND pay_index > ? ORDER BY pay_index ASC LIMIT 1;" msgstr "" -#: wallet/invoices.c:622 -msgid "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;" +#: wallet/invoices.c:657 +msgid "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features, local_offer_id FROM invoices WHERE id = ?;" msgstr "" #: wallet/wallet.c:75 wallet/wallet.c:553 @@ -906,231 +914,231 @@ msgstr "" msgid "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = ? AND channel_id = ? AND hstate != ?" msgstr "" -#: wallet/wallet.c:2378 +#: wallet/wallet.c:2379 msgid "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;" msgstr "" -#: wallet/wallet.c:2412 +#: wallet/wallet.c:2413 msgid "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2465 +#: wallet/wallet.c:2466 msgid "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2483 +#: wallet/wallet.c:2484 msgid "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:2566 +#: wallet/wallet.c:2567 msgid "DELETE FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:2580 +#: wallet/wallet.c:2581 msgid "DELETE FROM payments WHERE payment_hash = ?" msgstr "" -#: wallet/wallet.c:2675 +#: wallet/wallet.c:2676 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:2724 +#: wallet/wallet.c:2725 msgid "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:2734 +#: wallet/wallet.c:2735 msgid "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:2744 +#: wallet/wallet.c:2745 msgid "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2776 +#: wallet/wallet.c:2777 msgid "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:2843 +#: wallet/wallet.c:2844 msgid "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:2902 +#: wallet/wallet.c:2903 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ?;" msgstr "" -#: wallet/wallet.c:2923 +#: wallet/wallet.c:2924 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments ORDER BY id;" msgstr "" -#: wallet/wallet.c:2967 +#: wallet/wallet.c:2968 msgid "DELETE FROM htlc_sigs WHERE channelid = ?" msgstr "" -#: wallet/wallet.c:2974 +#: wallet/wallet.c:2975 msgid "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)" msgstr "" -#: wallet/wallet.c:2986 +#: wallet/wallet.c:2987 msgid "SELECT blobval FROM vars WHERE name='genesis_hash'" msgstr "" -#: wallet/wallet.c:3010 +#: wallet/wallet.c:3011 msgid "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);" msgstr "" -#: wallet/wallet.c:3026 +#: wallet/wallet.c:3027 msgid "DELETE FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:3034 wallet/wallet.c:3144 +#: wallet/wallet.c:3035 wallet/wallet.c:3145 msgid "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);" msgstr "" -#: wallet/wallet.c:3053 +#: wallet/wallet.c:3054 msgid "DELETE FROM blocks WHERE hash = ?" msgstr "" -#: wallet/wallet.c:3059 +#: wallet/wallet.c:3060 msgid "SELECT * FROM blocks WHERE height >= ?;" msgstr "" -#: wallet/wallet.c:3068 +#: wallet/wallet.c:3069 msgid "DELETE FROM blocks WHERE height > ?" msgstr "" -#: wallet/wallet.c:3080 +#: wallet/wallet.c:3081 msgid "UPDATE outputs SET spend_height = ?, status = ? WHERE prev_out_tx = ? AND prev_out_index = ?" msgstr "" -#: wallet/wallet.c:3097 +#: wallet/wallet.c:3098 msgid "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?" msgstr "" -#: wallet/wallet.c:3119 wallet/wallet.c:3155 +#: wallet/wallet.c:3120 wallet/wallet.c:3156 msgid "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3179 +#: wallet/wallet.c:3180 msgid "SELECT height FROM blocks WHERE height = ?" msgstr "" -#: wallet/wallet.c:3192 +#: wallet/wallet.c:3193 msgid "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL" msgstr "" -#: wallet/wallet.c:3234 +#: wallet/wallet.c:3235 msgid "SELECT blockheight, txindex, outnum FROM utxoset WHERE spendheight = ?" msgstr "" -#: wallet/wallet.c:3265 wallet/wallet.c:3425 +#: wallet/wallet.c:3266 wallet/wallet.c:3426 msgid "SELECT blockheight FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3275 +#: wallet/wallet.c:3276 msgid "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3296 +#: wallet/wallet.c:3297 msgid "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3313 +#: wallet/wallet.c:3314 msgid "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;" msgstr "" -#: wallet/wallet.c:3345 +#: wallet/wallet.c:3346 msgid "SELECT type, channel_id FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3361 +#: wallet/wallet.c:3362 msgid "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3380 +#: wallet/wallet.c:3381 msgid "SELECT type FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3403 +#: wallet/wallet.c:3404 msgid "SELECT rawtx FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3449 +#: wallet/wallet.c:3450 msgid "SELECT blockheight, txindex FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3477 +#: wallet/wallet.c:3478 msgid "SELECT id FROM transactions WHERE blockheight=?" msgstr "" -#: wallet/wallet.c:3496 +#: wallet/wallet.c:3497 msgid "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3520 +#: wallet/wallet.c:3521 msgid "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" msgstr "" -#: wallet/wallet.c:3541 +#: wallet/wallet.c:3542 msgid "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;" msgstr "" -#: wallet/wallet.c:3586 +#: wallet/wallet.c:3587 msgid "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?" msgstr "" -#: wallet/wallet.c:3644 +#: wallet/wallet.c:3645 msgid "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3703 +#: wallet/wallet.c:3704 msgid "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;" msgstr "" -#: wallet/wallet.c:3727 +#: wallet/wallet.c:3728 msgid "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id)" msgstr "" -#: wallet/wallet.c:3815 +#: wallet/wallet.c:3816 msgid "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC" msgstr "" -#: wallet/wallet.c:3909 +#: wallet/wallet.c:3910 msgid "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3934 +#: wallet/wallet.c:3935 msgid "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?" msgstr "" -#: wallet/wallet.c:3958 +#: wallet/wallet.c:3959 msgid "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?" msgstr "" -#: wallet/wallet.c:3976 +#: wallet/wallet.c:3977 msgid "SELECT 1 FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:3989 +#: wallet/wallet.c:3990 msgid "INSERT INTO offers ( offer_id, bolt12, label, status) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4017 +#: wallet/wallet.c:4018 msgid "SELECT bolt12, label, status FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4045 +#: wallet/wallet.c:4046 msgid "SELECT offer_id FROM offers;" msgstr "" -#: wallet/wallet.c:4071 +#: wallet/wallet.c:4072 msgid "UPDATE offers SET status=? WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4082 -msgid "UPDATE invoices SET state=? WHERE state=? AND offer_id = ?;" +#: wallet/wallet.c:4083 +msgid "UPDATE invoices SET state=? WHERE state=? AND local_offer_id = ?;" msgstr "" -#: wallet/wallet.c:4110 +#: wallet/wallet.c:4111 msgid "SELECT status FROM offers WHERE offer_id = ?;" msgstr "" @@ -1142,7 +1150,7 @@ msgstr "" msgid "not a valid SQL statement" msgstr "" -#: wallet/test/run-wallet.c:1377 +#: wallet/test/run-wallet.c:1378 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:3c2b67d1ede6a371d5dfbc97c6406cb3152c0a36ff60d714967552de6d02f7d7 +# SHA256STAMP:f7e6df1a958f5eeb00dd1ffb0221fab28816a4807908fe904ae913a248b0f98c diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 70641cc51..68a0bd0be 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -175,7 +175,8 @@ bool invoices_create(struct invoices *invoices UNNEEDED, const char *description UNNEEDED, const u8 *features UNNEEDED, const struct preimage *r UNNEEDED, - const struct sha256 *rhash UNNEEDED) + const struct sha256 *rhash UNNEEDED, + const struct sha256 *local_offer_id UNNEEDED) { fprintf(stderr, "invoices_create called!\n"); abort(); } /* Generated stub for invoices_delete */ bool invoices_delete(struct invoices *invoices UNNEEDED, diff --git a/wallet/wallet.c b/wallet/wallet.c index b02527d51..ccfdf12b4 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2295,9 +2295,10 @@ bool wallet_invoice_create(struct wallet *wallet, const char *description, const u8 *features, const struct preimage *r, - const struct sha256 *rhash) + const struct sha256 *rhash, + const struct sha256 *local_offer_id) { - return invoices_create(wallet->invoices, pinvoice, msat, label, expiry, b11enc, description, features, r, rhash); + return invoices_create(wallet->invoices, pinvoice, msat, label, expiry, b11enc, description, features, r, rhash, local_offer_id); } bool wallet_invoice_find_by_label(struct wallet *wallet, struct invoice *pinvoice, @@ -4081,7 +4082,7 @@ static void offer_status_update(struct db *db, stmt = db_prepare_v2(db, SQL("UPDATE invoices" " SET state=?" - " WHERE state=? AND offer_id = ?;")); + " WHERE state=? AND local_offer_id = ?;")); db_bind_int(stmt, 0, invoice_status_in_db(UNPAID)); db_bind_int(stmt, 1, invoice_status_in_db(EXPIRED)); db_bind_sha256(stmt, 2, offer_id); diff --git a/wallet/wallet.h b/wallet/wallet.h index 0dc5a53f5..8af718dfd 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -726,6 +726,8 @@ struct invoice_details { char *description; /* The features, if any (tal_arr) */ u8 *features; + /* The offer this refers to, if any. */ + struct sha256 *local_offer_id; }; /* An object that handles iteration over the set of invoices */ @@ -768,7 +770,8 @@ bool wallet_invoice_create(struct wallet *wallet, const char *description, const u8 *features, const struct preimage *r, - const struct sha256 *rhash); + const struct sha256 *rhash, + const struct sha256 *local_offer_id); /** * wallet_invoice_find_by_label - Search for an invoice by label