mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 16:44:22 +01:00
wallet/invoices.c: use BIND_NEXT
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
12
db/exec.c
12
db/exec.c
@@ -62,16 +62,16 @@ void db_set_intvar(struct db *db, const char *varname, s64 val)
|
||||
{
|
||||
size_t changes;
|
||||
struct db_stmt *stmt = db_prepare_v2(db, SQL("UPDATE vars SET intval=? WHERE name=?;"));
|
||||
db_bind_int(stmt, 0, val);
|
||||
db_bind_text(stmt, 1, varname);
|
||||
db_bind_int(stmt, BIND_NEXT, val);
|
||||
db_bind_text(stmt, BIND_NEXT, varname);
|
||||
db_exec_prepared_v2(stmt);
|
||||
changes = db_count_changes(stmt);
|
||||
tal_free(stmt);
|
||||
|
||||
if (changes == 0) {
|
||||
stmt = db_prepare_v2(db, SQL("INSERT INTO vars (name, intval) VALUES (?, ?);"));
|
||||
db_bind_text(stmt, 0, varname);
|
||||
db_bind_int(stmt, 1, val);
|
||||
db_bind_text(stmt, BIND_NEXT, varname);
|
||||
db_bind_int(stmt, BIND_NEXT, val);
|
||||
db_exec_prepared_v2(stmt);
|
||||
tal_free(stmt);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ s64 db_get_intvar(struct db *db, const char *varname, s64 defval)
|
||||
s64 res = defval;
|
||||
struct db_stmt *stmt = db_prepare_v2(
|
||||
db, SQL("SELECT intval FROM vars WHERE name= ? LIMIT 1"));
|
||||
db_bind_text(stmt, 0, varname);
|
||||
db_bind_text(stmt, BIND_NEXT, varname);
|
||||
if (db_query_prepared_canfail(stmt) && db_step(stmt))
|
||||
res = db_col_int(stmt, "intval");
|
||||
|
||||
@@ -110,7 +110,7 @@ static void db_data_version_incr(struct db *db)
|
||||
"SET intval = intval + 1 "
|
||||
"WHERE name = 'data_version'"
|
||||
" AND intval = ?"));
|
||||
db_bind_int(stmt, 0, db->data_version);
|
||||
db_bind_int(stmt, BIND_NEXT, db->data_version);
|
||||
db_exec_prepared_v2(stmt);
|
||||
if (db_count_changes(stmt) != 1)
|
||||
db_fatal(stmt->db, "Optimistic lock on the database failed. There"
|
||||
|
||||
58
wallet/db.c
58
wallet/db.c
@@ -1004,7 +1004,7 @@ static bool db_migrate(struct lightningd *ld, struct db *db,
|
||||
|
||||
/* Finally update the version number in the version table */
|
||||
stmt = db_prepare_v2(db, SQL("UPDATE version SET version=?;"));
|
||||
db_bind_int(stmt, 0, available);
|
||||
db_bind_int(stmt, BIND_NEXT, available);
|
||||
db_exec_prepared_v2(stmt);
|
||||
tal_free(stmt);
|
||||
|
||||
@@ -1012,8 +1012,8 @@ static bool db_migrate(struct lightningd *ld, struct db *db,
|
||||
if (current != orig) {
|
||||
stmt = db_prepare_v2(
|
||||
db, SQL("INSERT INTO db_upgrades VALUES (?, ?);"));
|
||||
db_bind_int(stmt, 0, orig);
|
||||
db_bind_text(stmt, 1, version());
|
||||
db_bind_int(stmt, BIND_NEXT, orig);
|
||||
db_bind_text(stmt, BIND_NEXT, version());
|
||||
db_exec_prepared_v2(stmt);
|
||||
tal_free(stmt);
|
||||
}
|
||||
@@ -1063,8 +1063,8 @@ static void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db
|
||||
struct db_stmt *stmt = db_prepare_v2(
|
||||
db, SQL("UPDATE channels SET feerate_base = ?, feerate_ppm = ?;"));
|
||||
|
||||
db_bind_int(stmt, 0, ld->config.fee_base);
|
||||
db_bind_int(stmt, 1, ld->config.fee_per_satoshi);
|
||||
db_bind_int(stmt, BIND_NEXT, ld->config.fee_base);
|
||||
db_bind_int(stmt, BIND_NEXT, ld->config.fee_per_satoshi);
|
||||
|
||||
db_exec_prepared_v2(stmt);
|
||||
tal_free(stmt);
|
||||
@@ -1160,9 +1160,9 @@ void fillin_missing_scriptpubkeys(struct lightningd *ld, struct db *db)
|
||||
" SET scriptpubkey = ?"
|
||||
" WHERE prev_out_tx = ? "
|
||||
" AND prev_out_index = ?"));
|
||||
db_bind_blob(update_stmt, 0, scriptPubkey, tal_bytelen(scriptPubkey));
|
||||
db_bind_txid(update_stmt, 1, &txid);
|
||||
db_bind_int(update_stmt, 2, outnum);
|
||||
db_bind_blob(update_stmt, BIND_NEXT, scriptPubkey, tal_bytelen(scriptPubkey));
|
||||
db_bind_txid(update_stmt, BIND_NEXT, &txid);
|
||||
db_bind_int(update_stmt, BIND_NEXT, outnum);
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
}
|
||||
@@ -1201,8 +1201,8 @@ static void fillin_missing_channel_id(struct lightningd *ld, struct db *db)
|
||||
update_stmt = db_prepare_v2(db, SQL("UPDATE channels"
|
||||
" SET full_channel_id = ?"
|
||||
" WHERE id = ?;"));
|
||||
db_bind_channel_id(update_stmt, 0, &cid);
|
||||
db_bind_u64(update_stmt, 1, id);
|
||||
db_bind_channel_id(update_stmt, BIND_NEXT, &cid);
|
||||
db_bind_u64(update_stmt, BIND_NEXT, id);
|
||||
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
@@ -1258,13 +1258,13 @@ static void fillin_missing_local_basepoints(struct lightningd *ld,
|
||||
", delayed_payment_basepoint_local = ?"
|
||||
", funding_pubkey_local = ? "
|
||||
"WHERE id = ?;"));
|
||||
db_bind_pubkey(upstmt, 0, &base.revocation);
|
||||
db_bind_pubkey(upstmt, 1, &base.payment);
|
||||
db_bind_pubkey(upstmt, 2, &base.htlc);
|
||||
db_bind_pubkey(upstmt, 3, &base.delayed_payment);
|
||||
db_bind_pubkey(upstmt, 4, &funding_pubkey);
|
||||
db_bind_pubkey(upstmt, BIND_NEXT, &base.revocation);
|
||||
db_bind_pubkey(upstmt, BIND_NEXT, &base.payment);
|
||||
db_bind_pubkey(upstmt, BIND_NEXT, &base.htlc);
|
||||
db_bind_pubkey(upstmt, BIND_NEXT, &base.delayed_payment);
|
||||
db_bind_pubkey(upstmt, BIND_NEXT, &funding_pubkey);
|
||||
|
||||
db_bind_u64(upstmt, 5, dbid);
|
||||
db_bind_u64(upstmt, BIND_NEXT, dbid);
|
||||
|
||||
db_exec_prepared_v2(take(upstmt));
|
||||
}
|
||||
@@ -1380,9 +1380,9 @@ migrate_inflight_last_tx_to_psbt(struct lightningd *ld, struct db *db)
|
||||
" SET last_tx = ?"
|
||||
" WHERE channel_id = ?"
|
||||
" AND funding_tx_id = ?;"));
|
||||
db_bind_psbt(update_stmt, 0, last_tx->psbt);
|
||||
db_bind_int(update_stmt, 1, cdb_id);
|
||||
db_bind_txid(update_stmt, 2, &funding_txid);
|
||||
db_bind_psbt(update_stmt, BIND_NEXT, last_tx->psbt);
|
||||
db_bind_int(update_stmt, BIND_NEXT, cdb_id);
|
||||
db_bind_txid(update_stmt, BIND_NEXT, &funding_txid);
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
}
|
||||
@@ -1474,8 +1474,8 @@ void migrate_last_tx_to_psbt(struct lightningd *ld, struct db *db)
|
||||
update_stmt = db_prepare_v2(db, SQL("UPDATE channels"
|
||||
" SET last_tx = ?"
|
||||
" WHERE id = ?;"));
|
||||
db_bind_psbt(update_stmt, 0, last_tx->psbt);
|
||||
db_bind_int(update_stmt, 1, cdb_id);
|
||||
db_bind_psbt(update_stmt, BIND_NEXT, last_tx->psbt);
|
||||
db_bind_int(update_stmt, BIND_NEXT, cdb_id);
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
}
|
||||
@@ -1511,8 +1511,8 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld,
|
||||
stmt = db_prepare_v2(db, SQL("UPDATE channels"
|
||||
" SET scid = ?"
|
||||
" WHERE short_channel_id = ?"));
|
||||
db_bind_short_channel_id(stmt, 0, &scid);
|
||||
db_bind_text(stmt, 1, scids[i]);
|
||||
db_bind_short_channel_id(stmt, BIND_NEXT, &scid);
|
||||
db_bind_text(stmt, BIND_NEXT, scids[i]);
|
||||
db_exec_prepared_v2(stmt);
|
||||
|
||||
/* This was reported to happen with an (old, closed) channel: that we'd have
|
||||
@@ -1566,8 +1566,8 @@ static void migrate_payments_scids_as_integers(struct lightningd *ld,
|
||||
update_stmt = db_prepare_v2(db, SQL("UPDATE payments SET"
|
||||
" failscid = ?"
|
||||
" WHERE id = ?"));
|
||||
db_bind_short_channel_id(update_stmt, 0, &scid);
|
||||
db_bind_u64(update_stmt, 1, db_col_u64(stmt, "id"));
|
||||
db_bind_short_channel_id(update_stmt, BIND_NEXT, &scid);
|
||||
db_bind_u64(update_stmt, BIND_NEXT, db_col_u64(stmt, "id"));
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
}
|
||||
@@ -1624,8 +1624,8 @@ static void migrate_fill_in_channel_type(struct lightningd *ld,
|
||||
update_stmt = db_prepare_v2(db, SQL("UPDATE channels SET"
|
||||
" channel_type = ?"
|
||||
" WHERE id = ?"));
|
||||
db_bind_channel_type(update_stmt, 0, type);
|
||||
db_bind_u64(update_stmt, 1, id);
|
||||
db_bind_channel_type(update_stmt, BIND_NEXT, type);
|
||||
db_bind_u64(update_stmt, BIND_NEXT, id);
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
}
|
||||
@@ -1697,8 +1697,8 @@ static void migrate_invalid_last_tx_psbts(struct lightningd *ld,
|
||||
update_stmt = db_prepare_v2(db, SQL("UPDATE channels"
|
||||
" SET last_tx = ?"
|
||||
" WHERE id = ?;"));
|
||||
db_bind_psbt(update_stmt, 0, psbt);
|
||||
db_bind_u64(update_stmt, 1, id);
|
||||
db_bind_psbt(update_stmt, BIND_NEXT, psbt);
|
||||
db_bind_u64(update_stmt, BIND_NEXT, id);
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ static void install_expiration_timer(struct invoices *invoices)
|
||||
stmt = db_prepare_v2(invoices->wallet->db, SQL("SELECT MIN(expiry_time)"
|
||||
" FROM invoices"
|
||||
" WHERE state = ?;"));
|
||||
db_bind_int(stmt, 0, UNPAID);
|
||||
db_bind_int(stmt, BIND_NEXT, UNPAID);
|
||||
|
||||
db_query_prepared(stmt);
|
||||
|
||||
@@ -333,7 +333,7 @@ bool invoices_find_by_label(struct invoices *invoices,
|
||||
stmt = db_prepare_v2(invoices->wallet->db, SQL("SELECT id"
|
||||
" FROM invoices"
|
||||
" WHERE label = ?;"));
|
||||
db_bind_json_escape(stmt, 0, label);
|
||||
db_bind_json_escape(stmt, BIND_NEXT, label);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
if (!db_step(stmt)) {
|
||||
@@ -355,7 +355,7 @@ bool invoices_find_by_rhash(struct invoices *invoices,
|
||||
stmt = db_prepare_v2(invoices->wallet->db, SQL("SELECT id"
|
||||
" FROM invoices"
|
||||
" WHERE payment_hash = ?;"));
|
||||
db_bind_sha256(stmt, 0, rhash);
|
||||
db_bind_sha256(stmt, BIND_NEXT, rhash);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
if (!db_step(stmt)) {
|
||||
@@ -377,8 +377,8 @@ bool invoices_find_unpaid(struct invoices *invoices,
|
||||
" FROM invoices"
|
||||
" WHERE payment_hash = ?"
|
||||
" AND state = ?;"));
|
||||
db_bind_sha256(stmt, 0, rhash);
|
||||
db_bind_int(stmt, 1, UNPAID);
|
||||
db_bind_sha256(stmt, BIND_NEXT, rhash);
|
||||
db_bind_int(stmt, BIND_NEXT, UNPAID);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
if (!db_step(stmt)) {
|
||||
@@ -398,7 +398,7 @@ bool invoices_delete(struct invoices *invoices, u64 inv_dbid)
|
||||
/* Delete from database. */
|
||||
stmt = db_prepare_v2(invoices->wallet->db,
|
||||
SQL("DELETE FROM invoices WHERE id=?;"));
|
||||
db_bind_u64(stmt, 0, inv_dbid);
|
||||
db_bind_u64(stmt, BIND_NEXT, inv_dbid);
|
||||
db_exec_prepared_v2(stmt);
|
||||
|
||||
changes = db_count_changes(stmt);
|
||||
@@ -420,7 +420,7 @@ bool invoices_delete_description(struct invoices *invoices, u64 inv_dbid)
|
||||
stmt = db_prepare_v2(invoices->wallet->db, SQL("UPDATE invoices"
|
||||
" SET description = NULL"
|
||||
" WHERE ID = ?;"));
|
||||
db_bind_u64(stmt, 0, inv_dbid);
|
||||
db_bind_u64(stmt, BIND_NEXT, inv_dbid);
|
||||
db_exec_prepared_v2(stmt);
|
||||
|
||||
changes = db_count_changes(stmt);
|
||||
@@ -437,8 +437,8 @@ void invoices_delete_expired(struct invoices *invoices,
|
||||
"DELETE FROM invoices"
|
||||
" WHERE state = ?"
|
||||
" AND expiry_time <= ?;"));
|
||||
db_bind_int(stmt, 0, EXPIRED);
|
||||
db_bind_u64(stmt, 1, max_expiry_time);
|
||||
db_bind_int(stmt, BIND_NEXT, EXPIRED);
|
||||
db_bind_u64(stmt, BIND_NEXT, max_expiry_time);
|
||||
db_exec_prepared_v2(take(stmt));
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ static enum invoice_status invoice_get_status(struct invoices *invoices,
|
||||
|
||||
stmt = db_prepare_v2(
|
||||
invoices->wallet->db, SQL("SELECT state FROM invoices WHERE id = ?;"));
|
||||
db_bind_u64(stmt, 0, inv_dbid);
|
||||
db_bind_u64(stmt, BIND_NEXT, inv_dbid);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
res = db_step(stmt);
|
||||
@@ -502,7 +502,7 @@ static void maybe_mark_offer_used(struct db *db, u64 inv_dbid)
|
||||
|
||||
stmt = db_prepare_v2(
|
||||
db, SQL("SELECT local_offer_id FROM invoices WHERE id = ?;"));
|
||||
db_bind_u64(stmt, 0, inv_dbid);
|
||||
db_bind_u64(stmt, BIND_NEXT, inv_dbid);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
db_step(stmt);
|
||||
@@ -596,7 +596,7 @@ void invoices_waitany(const tal_t *ctx,
|
||||
" WHERE pay_index IS NOT NULL"
|
||||
" AND pay_index > ?"
|
||||
" ORDER BY pay_index ASC LIMIT 1;"));
|
||||
db_bind_u64(stmt, 0, lastpay_index);
|
||||
db_bind_u64(stmt, BIND_NEXT, lastpay_index);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
if (db_step(stmt)) {
|
||||
@@ -656,7 +656,7 @@ struct invoice_details *invoices_get_details(const tal_t *ctx,
|
||||
", local_offer_id"
|
||||
" FROM invoices"
|
||||
" WHERE id = ?;"));
|
||||
db_bind_u64(stmt, 0, inv_dbid);
|
||||
db_bind_u64(stmt, BIND_NEXT, inv_dbid);
|
||||
db_query_prepared(stmt);
|
||||
res = db_step(stmt);
|
||||
assert(res);
|
||||
|
||||
Reference in New Issue
Block a user