From 27cedeb629e5a03a3b8e249be061178c83edfb30 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 14 Jul 2023 09:58:46 +0930 Subject: [PATCH] wallet: convert to BIND_NEXT. Signed-off-by: Rusty Russell --- wallet/invoices.c | 46 +- wallet/wallet.c | 1068 ++++++++++++++++++++++----------------------- 2 files changed, 557 insertions(+), 557 deletions(-) diff --git a/wallet/invoices.c b/wallet/invoices.c index 17c74fbb1..af17f29b2 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -123,9 +123,9 @@ static void update_db_expirations(struct invoices *invoices, u64 now) " SET state = ?" " WHERE state = ?" " AND expiry_time <= ?;")); - db_bind_int(stmt, 0, EXPIRED); - db_bind_int(stmt, 1, UNPAID); - db_bind_u64(stmt, 2, now); + db_bind_int(stmt, BIND_NEXT, EXPIRED); + db_bind_int(stmt, BIND_NEXT, UNPAID); + db_bind_u64(stmt, BIND_NEXT, now); db_exec_prepared_v2(take(stmt)); } @@ -170,8 +170,8 @@ static void trigger_expiration(struct invoices *invoices) " FROM invoices" " WHERE state = ?" " AND expiry_time <= ?")); - db_bind_int(stmt, 0, UNPAID); - db_bind_u64(stmt, 1, now); + db_bind_int(stmt, BIND_NEXT, UNPAID); + db_bind_u64(stmt, BIND_NEXT, now); db_query_prepared(stmt); while (db_step(stmt)) { @@ -286,25 +286,25 @@ bool invoices_create(struct invoices *invoices, " , NULL, NULL" " , NULL, ?, ?, ?, ?);")); - db_bind_sha256(stmt, 0, rhash); - db_bind_preimage(stmt, 1, r); - db_bind_int(stmt, 2, UNPAID); + db_bind_sha256(stmt, BIND_NEXT, rhash); + db_bind_preimage(stmt, BIND_NEXT, r); + db_bind_int(stmt, BIND_NEXT, UNPAID); if (msat) - db_bind_amount_msat(stmt, 3, msat); + db_bind_amount_msat(stmt, BIND_NEXT, msat); else - db_bind_null(stmt, 3); - db_bind_json_escape(stmt, 4, label); - db_bind_u64(stmt, 5, expiry_time); - db_bind_text(stmt, 6, b11enc); + db_bind_null(stmt, BIND_NEXT); + db_bind_json_escape(stmt, BIND_NEXT, label); + db_bind_u64(stmt, BIND_NEXT, expiry_time); + db_bind_text(stmt, BIND_NEXT, b11enc); if (!description) - db_bind_null(stmt, 7); + db_bind_null(stmt, BIND_NEXT); else - db_bind_text(stmt, 7, description); - db_bind_talarr(stmt, 8, features); + db_bind_text(stmt, BIND_NEXT, description); + db_bind_talarr(stmt, BIND_NEXT, features); if (local_offer_id) - db_bind_sha256(stmt, 9, local_offer_id); + db_bind_sha256(stmt, BIND_NEXT, local_offer_id); else - db_bind_null(stmt, 9); + db_bind_null(stmt, BIND_NEXT); db_exec_prepared_v2(stmt); @@ -539,11 +539,11 @@ bool invoices_resolve(struct invoices *invoices, " , msatoshi_received=?" " , paid_timestamp=?" " WHERE id=?;")); - db_bind_int(stmt, 0, PAID); - db_bind_u64(stmt, 1, pay_index); - db_bind_amount_msat(stmt, 2, &received); - db_bind_u64(stmt, 3, paid_timestamp); - db_bind_u64(stmt, 4, inv_dbid); + db_bind_int(stmt, BIND_NEXT, PAID); + db_bind_u64(stmt, BIND_NEXT, pay_index); + db_bind_amount_msat(stmt, BIND_NEXT, &received); + db_bind_u64(stmt, BIND_NEXT, paid_timestamp); + db_bind_u64(stmt, BIND_NEXT, inv_dbid); db_exec_prepared_v2(take(stmt)); maybe_mark_offer_used(invoices->wallet->db, inv_dbid); diff --git a/wallet/wallet.c b/wallet/wallet.c index aa220d083..6db304e72 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -132,8 +132,8 @@ static bool wallet_add_utxo(struct wallet *w, struct utxo *utxo, stmt = db_prepare_v2(w->db, SQL("SELECT * from outputs WHERE " "prev_out_tx=? AND prev_out_index=?")); - db_bind_txid(stmt, 0, &utxo->outpoint.txid); - db_bind_int(stmt, 1, utxo->outpoint.n); + db_bind_txid(stmt, BIND_NEXT, &utxo->outpoint.txid); + db_bind_int(stmt, BIND_NEXT, utxo->outpoint.n); db_query_prepared(stmt); /* If we get a result, that means a clash. */ @@ -161,41 +161,41 @@ static bool wallet_add_utxo(struct wallet *w, struct utxo *utxo, ", scriptpubkey" ", is_in_coinbase" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); - db_bind_txid(stmt, 0, &utxo->outpoint.txid); - db_bind_int(stmt, 1, utxo->outpoint.n); - db_bind_amount_sat(stmt, 2, &utxo->amount); - db_bind_int(stmt, 3, wallet_output_type_in_db(type)); - db_bind_int(stmt, 4, OUTPUT_STATE_AVAILABLE); - db_bind_int(stmt, 5, utxo->keyindex); + db_bind_txid(stmt, BIND_NEXT, &utxo->outpoint.txid); + db_bind_int(stmt, BIND_NEXT, utxo->outpoint.n); + db_bind_amount_sat(stmt, BIND_NEXT, &utxo->amount); + db_bind_int(stmt, BIND_NEXT, wallet_output_type_in_db(type)); + db_bind_int(stmt, BIND_NEXT, OUTPUT_STATE_AVAILABLE); + db_bind_int(stmt, BIND_NEXT, utxo->keyindex); if (utxo->close_info) { - db_bind_u64(stmt, 6, utxo->close_info->channel_id); - db_bind_node_id(stmt, 7, &utxo->close_info->peer_id); + db_bind_u64(stmt, BIND_NEXT, utxo->close_info->channel_id); + db_bind_node_id(stmt, BIND_NEXT, &utxo->close_info->peer_id); if (utxo->close_info->commitment_point) - db_bind_pubkey(stmt, 8, utxo->close_info->commitment_point); + db_bind_pubkey(stmt, BIND_NEXT, utxo->close_info->commitment_point); else - db_bind_null(stmt, 8); - db_bind_int(stmt, 9, utxo->close_info->option_anchors); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, utxo->close_info->option_anchors); } else { - db_bind_null(stmt, 6); - db_bind_null(stmt, 7); - db_bind_null(stmt, 8); - db_bind_null(stmt, 9); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); } if (utxo->blockheight) { - db_bind_int(stmt, 10, *utxo->blockheight); + db_bind_int(stmt, BIND_NEXT, *utxo->blockheight); } else - db_bind_null(stmt, 10); + db_bind_null(stmt, BIND_NEXT); if (utxo->spendheight) - db_bind_int(stmt, 11, *utxo->spendheight); + db_bind_int(stmt, BIND_NEXT, *utxo->spendheight); else - db_bind_null(stmt, 11); + db_bind_null(stmt, BIND_NEXT); - db_bind_blob(stmt, 12, utxo->scriptPubkey, + db_bind_blob(stmt, BIND_NEXT, utxo->scriptPubkey, tal_bytelen(utxo->scriptPubkey)); - db_bind_int(stmt, 13, utxo->is_in_coinbase); + db_bind_int(stmt, BIND_NEXT, utxo->is_in_coinbase); db_exec_prepared_v2(take(stmt)); return true; } @@ -269,17 +269,17 @@ bool wallet_update_output_status(struct wallet *w, stmt = db_prepare_v2( w->db, SQL("UPDATE outputs SET status=? WHERE status=? AND " "prev_out_tx=? AND prev_out_index=?")); - db_bind_int(stmt, 0, output_status_in_db(newstatus)); - db_bind_int(stmt, 1, output_status_in_db(oldstatus)); - db_bind_txid(stmt, 2, &outpoint->txid); - db_bind_int(stmt, 3, outpoint->n); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(newstatus)); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(oldstatus)); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); } else { stmt = db_prepare_v2(w->db, SQL("UPDATE outputs SET status=? WHERE " "prev_out_tx=? AND prev_out_index=?")); - db_bind_int(stmt, 0, output_status_in_db(newstatus)); - db_bind_txid(stmt, 1, &outpoint->txid); - db_bind_int(stmt, 2, outpoint->n); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(newstatus)); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); } db_exec_prepared_v2(stmt); changes = db_count_changes(stmt); @@ -331,7 +331,7 @@ struct utxo **wallet_get_utxos(const tal_t *ctx, struct wallet *w, const enum ou ", is_in_coinbase " "FROM outputs " "WHERE status= ? ")); - db_bind_int(stmt, 0, output_status_in_db(state)); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(state)); } db_query_prepared(stmt); @@ -410,8 +410,8 @@ struct utxo *wallet_utxo_get(const tal_t *ctx, struct wallet *w, " WHERE prev_out_tx = ?" " AND prev_out_index = ?")); - db_bind_txid(stmt, 0, &outpoint->txid); - db_bind_int(stmt, 1, outpoint->n); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); db_query_prepared(stmt); @@ -438,10 +438,10 @@ static void db_set_utxo(struct db *db, const struct utxo *utxo) stmt = db_prepare_v2( db, SQL("UPDATE outputs SET status=?, reserved_til=? " "WHERE prev_out_tx=? AND prev_out_index=?")); - db_bind_int(stmt, 0, output_status_in_db(utxo->status)); - db_bind_int(stmt, 1, utxo->reserved_til); - db_bind_txid(stmt, 2, &utxo->outpoint.txid); - db_bind_int(stmt, 3, utxo->outpoint.n); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(utxo->status)); + db_bind_int(stmt, BIND_NEXT, utxo->reserved_til); + db_bind_txid(stmt, BIND_NEXT, &utxo->outpoint.txid); + db_bind_int(stmt, BIND_NEXT, utxo->outpoint.n); db_exec_prepared_v2(take(stmt)); } @@ -567,9 +567,9 @@ struct utxo *wallet_find_utxo(const tal_t *ctx, struct wallet *w, " WHERE status = ?" " OR (status = ? AND reserved_til <= ?)" "ORDER BY RANDOM();")); - db_bind_int(stmt, 0, output_status_in_db(OUTPUT_STATE_AVAILABLE)); - db_bind_int(stmt, 1, output_status_in_db(OUTPUT_STATE_RESERVED)); - db_bind_u64(stmt, 2, current_blockheight); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(OUTPUT_STATE_AVAILABLE)); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(OUTPUT_STATE_RESERVED)); + db_bind_u64(stmt, BIND_NEXT, current_blockheight); /* FIXME: Use feerate + estimate of input cost to establish * range for amount_hint */ @@ -618,9 +618,9 @@ bool wallet_has_funds(struct wallet *w, " FROM outputs" " WHERE status = ?" " OR (status = ? AND reserved_til <= ?)")); - db_bind_int(stmt, 0, output_status_in_db(OUTPUT_STATE_AVAILABLE)); - db_bind_int(stmt, 1, output_status_in_db(OUTPUT_STATE_RESERVED)); - db_bind_u64(stmt, 2, current_blockheight); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(OUTPUT_STATE_AVAILABLE)); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(OUTPUT_STATE_RESERVED)); + db_bind_u64(stmt, BIND_NEXT, current_blockheight); db_query_prepared(stmt); while (db_step(stmt)) { @@ -666,8 +666,8 @@ bool wallet_add_onchaind_utxo(struct wallet *w, stmt = db_prepare_v2(w->db, SQL("SELECT * from outputs WHERE " "prev_out_tx=? AND prev_out_index=?")); - db_bind_txid(stmt, 0, &outpoint->txid); - db_bind_int(stmt, 1, outpoint->n); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); db_query_prepared(stmt); /* If we get a result, that means a clash. */ @@ -695,28 +695,28 @@ bool wallet_add_onchaind_utxo(struct wallet *w, ", scriptpubkey" ", csv_lock" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); - db_bind_txid(stmt, 0, &outpoint->txid); - db_bind_int(stmt, 1, outpoint->n); - db_bind_amount_sat(stmt, 2, &amount); - db_bind_int(stmt, 3, wallet_output_type_in_db(p2wpkh)); - db_bind_int(stmt, 4, OUTPUT_STATE_AVAILABLE); - db_bind_int(stmt, 5, 0); - db_bind_u64(stmt, 6, channel->dbid); - db_bind_node_id(stmt, 7, &channel->peer->id); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); + db_bind_amount_sat(stmt, BIND_NEXT, &amount); + db_bind_int(stmt, BIND_NEXT, wallet_output_type_in_db(p2wpkh)); + db_bind_int(stmt, BIND_NEXT, OUTPUT_STATE_AVAILABLE); + db_bind_int(stmt, BIND_NEXT, 0); + db_bind_u64(stmt, BIND_NEXT, channel->dbid); + db_bind_node_id(stmt, BIND_NEXT, &channel->peer->id); if (commitment_point) - db_bind_pubkey(stmt, 8, commitment_point); + db_bind_pubkey(stmt, BIND_NEXT, commitment_point); else - db_bind_null(stmt, 8); + db_bind_null(stmt, BIND_NEXT); - db_bind_int(stmt, 9, + db_bind_int(stmt, BIND_NEXT, channel_type_has_anchors(channel->type)); - db_bind_int(stmt, 10, blockheight); + db_bind_int(stmt, BIND_NEXT, blockheight); /* spendheight */ - db_bind_null(stmt, 11); - db_bind_blob(stmt, 12, scriptpubkey, tal_bytelen(scriptpubkey)); + db_bind_null(stmt, BIND_NEXT); + db_bind_blob(stmt, BIND_NEXT, scriptpubkey, tal_bytelen(scriptpubkey)); - db_bind_int(stmt, 13, csv_lock); + db_bind_int(stmt, BIND_NEXT, csv_lock); db_exec_prepared_v2(take(stmt)); return true; @@ -802,7 +802,7 @@ static void wallet_shachain_init(struct wallet *wallet, stmt = db_prepare_v2( wallet->db, SQL("INSERT INTO shachains (min_index, num_valid) VALUES (?, 0);")); - db_bind_u64(stmt, 0, chain->chain.min_index); + db_bind_u64(stmt, BIND_NEXT, chain->chain.min_index); db_exec_prepared_v2(stmt); chain->id = db_last_insert_id_v2(stmt); @@ -846,18 +846,18 @@ bool wallet_shachain_add_hash(struct wallet *wallet, stmt = db_prepare_v2( wallet->db, SQL("UPDATE shachains SET num_valid=?, min_index=? WHERE id=?")); - db_bind_int(stmt, 0, chain->chain.num_valid); - db_bind_u64(stmt, 1, index); - db_bind_u64(stmt, 2, chain->id); + db_bind_int(stmt, BIND_NEXT, chain->chain.num_valid); + db_bind_u64(stmt, BIND_NEXT, index); + db_bind_u64(stmt, BIND_NEXT, chain->id); db_exec_prepared_v2(take(stmt)); stmt = db_prepare_v2(wallet->db, SQL("UPDATE shachain_known SET idx=?, hash=? " "WHERE shachain_id=? AND pos=?")); - db_bind_u64(stmt, 0, index); - db_bind_secret(stmt, 1, hash); - db_bind_u64(stmt, 2, chain->id); - db_bind_int(stmt, 3, pos); + db_bind_u64(stmt, BIND_NEXT, index); + db_bind_secret(stmt, BIND_NEXT, hash); + db_bind_u64(stmt, BIND_NEXT, chain->id); + db_bind_int(stmt, BIND_NEXT, pos); db_exec_prepared_v2(stmt); updated = db_count_changes(stmt) == 1; tal_free(stmt); @@ -866,10 +866,10 @@ bool wallet_shachain_add_hash(struct wallet *wallet, stmt = db_prepare_v2( wallet->db, SQL("INSERT INTO shachain_known (shachain_id, " "pos, idx, hash) VALUES (?, ?, ?, ?);")); - db_bind_u64(stmt, 0, chain->id); - db_bind_int(stmt, 1, pos); - db_bind_u64(stmt, 2, index); - db_bind_secret(stmt, 3, hash); + db_bind_u64(stmt, BIND_NEXT, chain->id); + db_bind_int(stmt, BIND_NEXT, pos); + db_bind_u64(stmt, BIND_NEXT, index); + db_bind_secret(stmt, BIND_NEXT, hash); db_exec_prepared_v2(take(stmt)); } @@ -887,7 +887,7 @@ static bool wallet_shachain_load(struct wallet *wallet, u64 id, stmt = db_prepare_v2( wallet->db, SQL("SELECT min_index, num_valid FROM shachains WHERE id=?")); - db_bind_u64(stmt, 0, id); + db_bind_u64(stmt, BIND_NEXT, id); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -903,7 +903,7 @@ static bool wallet_shachain_load(struct wallet *wallet, u64 id, stmt = db_prepare_v2(wallet->db, SQL("SELECT idx, hash, pos FROM shachain_known " "WHERE shachain_id=?")); - db_bind_u64(stmt, 0, id); + db_bind_u64(stmt, BIND_NEXT, id); db_query_prepared(stmt); while (db_step(stmt)) { @@ -925,7 +925,7 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid) stmt = db_prepare_v2( w->db, SQL("SELECT id, node_id, address, feature_bits FROM peers WHERE id=?;")); - db_bind_u64(stmt, 0, dbid); + db_bind_u64(stmt, BIND_NEXT, dbid); db_query_prepared(stmt); if (!db_step(stmt)) @@ -968,7 +968,7 @@ wallet_htlc_sigs_load(const tal_t *ctx, struct wallet *w, u64 channelid, stmt = db_prepare_v2( w->db, SQL("SELECT signature FROM htlc_sigs WHERE channelid = ?")); - db_bind_u64(stmt, 0, channelid); + db_bind_u64(stmt, BIND_NEXT, channelid); db_query_prepared(stmt); while (db_step(stmt)) { @@ -1003,7 +1003,7 @@ bool wallet_remote_ann_sigs_load(const tal_t *ctx, struct wallet *w, u64 id, stmt = db_prepare_v2( w->db, SQL("SELECT remote_ann_node_sig, remote_ann_bitcoin_sig" " FROM channels WHERE id = ?")); - db_bind_u64(stmt, 0, id); + db_bind_u64(stmt, BIND_NEXT, id); db_query_prepared(stmt); res = db_step(stmt); @@ -1048,7 +1048,7 @@ static struct fee_states *wallet_channel_fee_states_load(struct wallet *w, struct db_stmt *stmt; stmt = db_prepare_v2(w->db, SQL("SELECT hstate, feerate_per_kw FROM channel_feerates WHERE channel_id = ?")); - db_bind_u64(stmt, 0, id); + db_bind_u64(stmt, BIND_NEXT, id); db_query_prepared(stmt); /* Start with blank slate. */ @@ -1084,7 +1084,7 @@ static struct height_states *wallet_channel_height_states_load(struct wallet *w, struct db_stmt *stmt; stmt = db_prepare_v2(w->db, SQL("SELECT hstate, blockheight FROM channel_blockheights WHERE channel_id = ?")); - db_bind_u64(stmt, 0, id); + db_bind_u64(stmt, BIND_NEXT, id); db_query_prepared(stmt); /* Start with blank slate. */ @@ -1137,33 +1137,33 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight) ") VALUES (" "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); - db_bind_u64(stmt, 0, inflight->channel->dbid); - db_bind_txid(stmt, 1, &inflight->funding->outpoint.txid); - db_bind_int(stmt, 2, inflight->funding->outpoint.n); - db_bind_int(stmt, 3, inflight->funding->feerate); - db_bind_amount_sat(stmt, 4, &inflight->funding->total_funds); - db_bind_amount_sat(stmt, 5, &inflight->funding->our_funds); - db_bind_psbt(stmt, 6, inflight->funding_psbt); - db_bind_int(stmt, 7, inflight->remote_tx_sigs ? 1 : 0); - db_bind_psbt(stmt, 8, inflight->last_tx->psbt); - db_bind_signature(stmt, 9, &inflight->last_sig.s); + db_bind_u64(stmt, BIND_NEXT, inflight->channel->dbid); + db_bind_txid(stmt, BIND_NEXT, &inflight->funding->outpoint.txid); + db_bind_int(stmt, BIND_NEXT, inflight->funding->outpoint.n); + db_bind_int(stmt, BIND_NEXT, inflight->funding->feerate); + db_bind_amount_sat(stmt, BIND_NEXT, &inflight->funding->total_funds); + db_bind_amount_sat(stmt, BIND_NEXT, &inflight->funding->our_funds); + db_bind_psbt(stmt, BIND_NEXT, inflight->funding_psbt); + db_bind_int(stmt, BIND_NEXT, inflight->remote_tx_sigs ? 1 : 0); + db_bind_psbt(stmt, BIND_NEXT, inflight->last_tx->psbt); + db_bind_signature(stmt, BIND_NEXT, &inflight->last_sig.s); if (inflight->lease_expiry != 0) { - db_bind_signature(stmt, 10, inflight->lease_commit_sig); - db_bind_int(stmt, 11, inflight->lease_chan_max_msat); - db_bind_int(stmt, 12, inflight->lease_chan_max_ppt); - db_bind_int(stmt, 13, inflight->lease_expiry); - db_bind_int(stmt, 14, inflight->lease_blockheight_start); - db_bind_amount_msat(stmt, 15, &inflight->lease_fee); - db_bind_amount_sat(stmt, 16, &inflight->lease_amt); + db_bind_signature(stmt, BIND_NEXT, inflight->lease_commit_sig); + db_bind_int(stmt, BIND_NEXT, inflight->lease_chan_max_msat); + db_bind_int(stmt, BIND_NEXT, inflight->lease_chan_max_ppt); + db_bind_int(stmt, BIND_NEXT, inflight->lease_expiry); + db_bind_int(stmt, BIND_NEXT, inflight->lease_blockheight_start); + db_bind_amount_msat(stmt, BIND_NEXT, &inflight->lease_fee); + db_bind_amount_sat(stmt, BIND_NEXT, &inflight->lease_amt); } else { - db_bind_null(stmt, 10); - db_bind_null(stmt, 11); - db_bind_null(stmt, 12); - db_bind_int(stmt, 13, 0); - db_bind_null(stmt, 14); - db_bind_null(stmt, 15); - db_bind_int(stmt, 16, 0); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, 0); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, 0); } db_exec_prepared_v2(stmt); @@ -1187,11 +1187,11 @@ void wallet_inflight_save(struct wallet *w, " channel_id=?" // 2 " AND funding_tx_id=?" // 3 " AND funding_tx_outnum=?")); // 4 - db_bind_psbt(stmt, 0, inflight->funding_psbt); - db_bind_int(stmt, 1, inflight->remote_tx_sigs); - db_bind_u64(stmt, 2, inflight->channel->dbid); - db_bind_txid(stmt, 3, &inflight->funding->outpoint.txid); - db_bind_int(stmt, 4, inflight->funding->outpoint.n); + db_bind_psbt(stmt, BIND_NEXT, inflight->funding_psbt); + db_bind_int(stmt, BIND_NEXT, inflight->remote_tx_sigs); + db_bind_u64(stmt, BIND_NEXT, inflight->channel->dbid); + db_bind_txid(stmt, BIND_NEXT, &inflight->funding->outpoint.txid); + db_bind_int(stmt, BIND_NEXT, inflight->funding->outpoint.n); db_exec_prepared_v2(take(stmt)); } @@ -1205,7 +1205,7 @@ void wallet_channel_clear_inflights(struct wallet *w, /* Remove all the inflights for the channel */ stmt = db_prepare_v2(w->db, SQL("DELETE FROM channel_funding_inflights" " WHERE channel_id = ?")); - db_bind_u64(stmt, 0, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); db_exec_prepared_v2(take(stmt)); /* Empty out the list too */ @@ -1321,7 +1321,7 @@ static bool wallet_channel_load_inflights(struct wallet *w, " WHERE channel_id = ?" " ORDER BY funding_feerate")); - db_bind_u64(stmt, 0, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); db_query_prepared(stmt); while (db_step(stmt)) { @@ -1347,7 +1347,7 @@ static bool wallet_channel_config_load(struct wallet *w, const u64 id, "max_accepted_htlcs, max_dust_htlc_exposure_msat" " FROM channel_configs WHERE id= ? ;"); struct db_stmt *stmt = db_prepare_v2(w->db, query); - db_bind_u64(stmt, 0, id); + db_bind_u64(stmt, BIND_NEXT, id); db_query_prepared(stmt); if (!db_step(stmt)) @@ -1704,7 +1704,7 @@ struct closed_channel **wallet_load_closed_channels(const tal_t *ctx, " FROM channels" " LEFT JOIN peers p ON p.id = peer_id" " WHERE state = ?;")); - db_bind_int(stmt, 0, CLOSED); + db_bind_int(stmt, BIND_NEXT, CLOSED); db_query_prepared(stmt); while (db_step(stmt)) { @@ -1808,7 +1808,7 @@ static bool wallet_channels_load_active(struct wallet *w) ", alias_remote" " FROM channels" " WHERE state != ?;")); //? 0 - db_bind_int(stmt, 0, CLOSED); + db_bind_int(stmt, BIND_NEXT, CLOSED); db_query_prepared(stmt); while (db_step(stmt)) { @@ -1883,8 +1883,8 @@ void wallet_channel_stats_incr_x(struct wallet *w, fatal("Unknown channel state key (direction %s, type %s)", dir, typ); stmt = db_prepare_v2(w->db, query); - db_bind_amount_msat(stmt, 0, &msat); - db_bind_u64(stmt, 1, cdbid); + db_bind_amount_msat(stmt, BIND_NEXT, &msat); + db_bind_u64(stmt, BIND_NEXT, cdbid); db_exec_prepared_v2(take(stmt)); } @@ -1923,7 +1923,7 @@ void wallet_channel_stats_load(struct wallet *w, ", out_msatoshi_offered, out_msatoshi_fulfilled" " FROM channels" " WHERE id = ?")); - db_bind_u64(stmt, 0, id); + db_bind_u64(stmt, BIND_NEXT, id); db_query_prepared(stmt); res = db_step(stmt); @@ -2002,14 +2002,14 @@ static void wallet_channel_config_save(struct wallet *w, " max_accepted_htlcs=?," " max_dust_htlc_exposure_msat=?" " WHERE id=?;")); - db_bind_amount_sat(stmt, 0, &cc->dust_limit); - db_bind_amount_msat(stmt, 1, &cc->max_htlc_value_in_flight); - db_bind_amount_sat(stmt, 2, &cc->channel_reserve); - db_bind_amount_msat(stmt, 3, &cc->htlc_minimum); - db_bind_int(stmt, 4, cc->to_self_delay); - db_bind_int(stmt, 5, cc->max_accepted_htlcs); - db_bind_amount_msat(stmt, 6, &cc->max_dust_htlc_exposure_msat); - db_bind_u64(stmt, 7, cc->id); + db_bind_amount_sat(stmt, BIND_NEXT, &cc->dust_limit); + db_bind_amount_msat(stmt, BIND_NEXT, &cc->max_htlc_value_in_flight); + db_bind_amount_sat(stmt, BIND_NEXT, &cc->channel_reserve); + db_bind_amount_msat(stmt, BIND_NEXT, &cc->htlc_minimum); + db_bind_int(stmt, BIND_NEXT, cc->to_self_delay); + db_bind_int(stmt, BIND_NEXT, cc->max_accepted_htlcs); + db_bind_amount_msat(stmt, BIND_NEXT, &cc->max_dust_htlc_exposure_msat); + db_bind_u64(stmt, BIND_NEXT, cc->id); db_exec_prepared_v2(take(stmt)); } @@ -2030,9 +2030,9 @@ void wallet_announcement_save(struct wallet *w, u64 id, " remote_ann_bitcoin_sig=?" " WHERE id=?")); - db_bind_signature(stmt, 0, remote_ann_node_sig); - db_bind_signature(stmt, 1, remote_ann_bitcoin_sig); - db_bind_u64(stmt, 2, id); + db_bind_signature(stmt, BIND_NEXT, remote_ann_node_sig); + db_bind_signature(stmt, BIND_NEXT, remote_ann_bitcoin_sig); + db_bind_u64(stmt, BIND_NEXT, id); db_exec_prepared_v2(take(stmt)); } @@ -2091,85 +2091,85 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) " alias_local=?," // 44 " alias_remote=?" // 45 " WHERE id=?")); // 46 - db_bind_u64(stmt, 0, chan->their_shachain.id); + db_bind_u64(stmt, BIND_NEXT, chan->their_shachain.id); if (chan->scid) - db_bind_short_channel_id(stmt, 1, chan->scid); + db_bind_short_channel_id(stmt, BIND_NEXT, chan->scid); else - db_bind_null(stmt, 1); + db_bind_null(stmt, BIND_NEXT); - db_bind_channel_id(stmt, 2, &chan->cid); - db_bind_int(stmt, 3, chan->state); - db_bind_int(stmt, 4, chan->opener); - db_bind_int(stmt, 5, chan->channel_flags); - db_bind_int(stmt, 6, chan->minimum_depth); + db_bind_channel_id(stmt, BIND_NEXT, &chan->cid); + db_bind_int(stmt, BIND_NEXT, chan->state); + db_bind_int(stmt, BIND_NEXT, chan->opener); + db_bind_int(stmt, BIND_NEXT, chan->channel_flags); + db_bind_int(stmt, BIND_NEXT, chan->minimum_depth); - db_bind_u64(stmt, 7, chan->next_index[LOCAL]); - db_bind_u64(stmt, 8, chan->next_index[REMOTE]); - db_bind_u64(stmt, 9, chan->next_htlc_id); + db_bind_u64(stmt, BIND_NEXT, chan->next_index[LOCAL]); + db_bind_u64(stmt, BIND_NEXT, chan->next_index[REMOTE]); + db_bind_u64(stmt, BIND_NEXT, chan->next_htlc_id); - db_bind_sha256d(stmt, 10, &chan->funding.txid.shad); + db_bind_sha256d(stmt, BIND_NEXT, &chan->funding.txid.shad); - db_bind_int(stmt, 11, chan->funding.n); - db_bind_amount_sat(stmt, 12, &chan->funding_sats); - db_bind_amount_sat(stmt, 13, &chan->our_funds); - db_bind_int(stmt, 14, chan->remote_channel_ready); - db_bind_amount_msat(stmt, 15, &chan->push); - db_bind_amount_msat(stmt, 16, &chan->our_msat); + db_bind_int(stmt, BIND_NEXT, chan->funding.n); + db_bind_amount_sat(stmt, BIND_NEXT, &chan->funding_sats); + db_bind_amount_sat(stmt, BIND_NEXT, &chan->our_funds); + db_bind_int(stmt, BIND_NEXT, chan->remote_channel_ready); + db_bind_amount_msat(stmt, BIND_NEXT, &chan->push); + db_bind_amount_msat(stmt, BIND_NEXT, &chan->our_msat); - db_bind_talarr(stmt, 17, chan->shutdown_scriptpubkey[REMOTE]); - db_bind_u64(stmt, 18, chan->final_key_idx); - db_bind_u64(stmt, 19, chan->our_config.id); + db_bind_talarr(stmt, BIND_NEXT, chan->shutdown_scriptpubkey[REMOTE]); + db_bind_u64(stmt, BIND_NEXT, chan->final_key_idx); + db_bind_u64(stmt, BIND_NEXT, chan->our_config.id); if (chan->last_tx) - db_bind_psbt(stmt, 20, chan->last_tx->psbt); + db_bind_psbt(stmt, BIND_NEXT, chan->last_tx->psbt); else - db_bind_null(stmt, 20); - db_bind_signature(stmt, 21, &chan->last_sig.s); - db_bind_int(stmt, 22, chan->last_was_revoke); - db_bind_int(stmt, 23, chan->min_possible_feerate); - db_bind_int(stmt, 24, chan->max_possible_feerate); - db_bind_amount_msat(stmt, 25, &chan->msat_to_us_min); - db_bind_amount_msat(stmt, 26, &chan->msat_to_us_max); - db_bind_int(stmt, 27, chan->feerate_base); - db_bind_int(stmt, 28, chan->feerate_ppm); - db_bind_talarr(stmt, 29, chan->remote_upfront_shutdown_script); - db_bind_u64(stmt, 30, chan->static_remotekey_start[LOCAL]); - db_bind_u64(stmt, 31, chan->static_remotekey_start[REMOTE]); - db_bind_channel_type(stmt, 32, chan->type); - db_bind_talarr(stmt, 33, chan->shutdown_scriptpubkey[LOCAL]); - db_bind_int(stmt, 34, chan->closer); - db_bind_int(stmt, 35, state_change_in_db(chan->state_change_cause)); + db_bind_null(stmt, BIND_NEXT); + db_bind_signature(stmt, BIND_NEXT, &chan->last_sig.s); + db_bind_int(stmt, BIND_NEXT, chan->last_was_revoke); + db_bind_int(stmt, BIND_NEXT, chan->min_possible_feerate); + db_bind_int(stmt, BIND_NEXT, chan->max_possible_feerate); + db_bind_amount_msat(stmt, BIND_NEXT, &chan->msat_to_us_min); + db_bind_amount_msat(stmt, BIND_NEXT, &chan->msat_to_us_max); + db_bind_int(stmt, BIND_NEXT, chan->feerate_base); + db_bind_int(stmt, BIND_NEXT, chan->feerate_ppm); + db_bind_talarr(stmt, BIND_NEXT, chan->remote_upfront_shutdown_script); + db_bind_u64(stmt, BIND_NEXT, chan->static_remotekey_start[LOCAL]); + db_bind_u64(stmt, BIND_NEXT, chan->static_remotekey_start[REMOTE]); + db_bind_channel_type(stmt, BIND_NEXT, chan->type); + db_bind_talarr(stmt, BIND_NEXT, chan->shutdown_scriptpubkey[LOCAL]); + db_bind_int(stmt, BIND_NEXT, chan->closer); + db_bind_int(stmt, BIND_NEXT, state_change_in_db(chan->state_change_cause)); if (chan->shutdown_wrong_funding) { - db_bind_txid(stmt, 36, &chan->shutdown_wrong_funding->txid); - db_bind_int(stmt, 37, chan->shutdown_wrong_funding->n); + db_bind_txid(stmt, BIND_NEXT, &chan->shutdown_wrong_funding->txid); + db_bind_int(stmt, BIND_NEXT, chan->shutdown_wrong_funding->n); } else { - db_bind_null(stmt, 36); - db_bind_null(stmt, 37); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); } - db_bind_int(stmt, 38, chan->lease_expiry); + db_bind_int(stmt, BIND_NEXT, chan->lease_expiry); if (chan->lease_commit_sig) { - db_bind_signature(stmt, 39, chan->lease_commit_sig); - db_bind_int(stmt, 40, chan->lease_chan_max_msat); - db_bind_int(stmt, 41, chan->lease_chan_max_ppt); + db_bind_signature(stmt, BIND_NEXT, chan->lease_commit_sig); + db_bind_int(stmt, BIND_NEXT, chan->lease_chan_max_msat); + db_bind_int(stmt, BIND_NEXT, chan->lease_chan_max_ppt); } else { - db_bind_null(stmt, 39); - db_bind_null(stmt, 40); - db_bind_null(stmt, 41); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); } - db_bind_amount_msat(stmt, 42, &chan->htlc_minimum_msat); - db_bind_amount_msat(stmt, 43, &chan->htlc_maximum_msat); + db_bind_amount_msat(stmt, BIND_NEXT, &chan->htlc_minimum_msat); + db_bind_amount_msat(stmt, BIND_NEXT, &chan->htlc_maximum_msat); if (chan->alias[LOCAL] != NULL) - db_bind_short_channel_id(stmt, 44, chan->alias[LOCAL]); + db_bind_short_channel_id(stmt, BIND_NEXT, chan->alias[LOCAL]); else - db_bind_null(stmt, 44); + db_bind_null(stmt, BIND_NEXT); if (chan->alias[REMOTE] != NULL) - db_bind_short_channel_id(stmt, 45, chan->alias[REMOTE]); + db_bind_short_channel_id(stmt, BIND_NEXT, chan->alias[REMOTE]); else - db_bind_null(stmt, 45); + db_bind_null(stmt, BIND_NEXT); - db_bind_u64(stmt, 46, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); db_exec_prepared_v2(take(stmt)); wallet_channel_config_save(w, &chan->channel_info.their_config); @@ -2184,25 +2184,25 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) " channel_config_remote=?," " future_per_commitment_point=?" " WHERE id=?")); - db_bind_pubkey(stmt, 0, &chan->channel_info.remote_fundingkey); - db_bind_pubkey(stmt, 1, &chan->channel_info.theirbase.revocation); - db_bind_pubkey(stmt, 2, &chan->channel_info.theirbase.payment); - db_bind_pubkey(stmt, 3, &chan->channel_info.theirbase.htlc); - db_bind_pubkey(stmt, 4, &chan->channel_info.theirbase.delayed_payment); - db_bind_pubkey(stmt, 5, &chan->channel_info.remote_per_commit); - db_bind_pubkey(stmt, 6, &chan->channel_info.old_remote_per_commit); - db_bind_u64(stmt, 7, chan->channel_info.their_config.id); + db_bind_pubkey(stmt, BIND_NEXT, &chan->channel_info.remote_fundingkey); + db_bind_pubkey(stmt, BIND_NEXT, &chan->channel_info.theirbase.revocation); + db_bind_pubkey(stmt, BIND_NEXT, &chan->channel_info.theirbase.payment); + db_bind_pubkey(stmt, BIND_NEXT, &chan->channel_info.theirbase.htlc); + db_bind_pubkey(stmt, BIND_NEXT, &chan->channel_info.theirbase.delayed_payment); + db_bind_pubkey(stmt, BIND_NEXT, &chan->channel_info.remote_per_commit); + db_bind_pubkey(stmt, BIND_NEXT, &chan->channel_info.old_remote_per_commit); + db_bind_u64(stmt, BIND_NEXT, chan->channel_info.their_config.id); if (chan->future_per_commitment_point) - db_bind_pubkey(stmt, 8, chan->future_per_commitment_point); + db_bind_pubkey(stmt, BIND_NEXT, chan->future_per_commitment_point); else - db_bind_null(stmt, 8); - db_bind_u64(stmt, 9, chan->dbid); + db_bind_null(stmt, BIND_NEXT); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); db_exec_prepared_v2(take(stmt)); /* FIXME: Updates channel_feerates by discarding and rewriting. */ stmt = db_prepare_v2(w->db, SQL("DELETE FROM channel_feerates " "WHERE channel_id=?")); - db_bind_u64(stmt, 0, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); db_exec_prepared_v2(take(stmt)); for (enum htlc_state i = 0; @@ -2212,16 +2212,16 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) continue; stmt = db_prepare_v2(w->db, SQL("INSERT INTO channel_feerates " " VALUES(?, ?, ?)")); - db_bind_u64(stmt, 0, chan->dbid); - db_bind_int(stmt, 1, htlc_state_in_db(i)); - db_bind_int(stmt, 2, *chan->fee_states->feerate[i]); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); + db_bind_int(stmt, BIND_NEXT, htlc_state_in_db(i)); + db_bind_int(stmt, BIND_NEXT, *chan->fee_states->feerate[i]); db_exec_prepared_v2(take(stmt)); } /* FIXME: Updates channel_blockheights by discarding and rewriting. */ stmt = db_prepare_v2(w->db, SQL("DELETE FROM channel_blockheights " "WHERE channel_id=?")); - db_bind_u64(stmt, 0, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); db_exec_prepared_v2(take(stmt)); for (enum htlc_state i = 0; @@ -2231,9 +2231,9 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) continue; stmt = db_prepare_v2(w->db, SQL("INSERT INTO channel_blockheights " " VALUES(?, ?, ?)")); - db_bind_u64(stmt, 0, chan->dbid); - db_bind_int(stmt, 1, htlc_state_in_db(i)); - db_bind_int(stmt, 2, *chan->blockheight_states->height[i]); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); + db_bind_int(stmt, BIND_NEXT, htlc_state_in_db(i)); + db_bind_int(stmt, BIND_NEXT, *chan->blockheight_states->height[i]); db_exec_prepared_v2(take(stmt)); } @@ -2254,8 +2254,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) list_for_each(&chan->inflights, inflight, list) wallet_inflight_save(w, inflight); - db_bind_talarr(stmt, 0, last_sent_commit); - db_bind_u64(stmt, 1, chan->dbid); + db_bind_talarr(stmt, BIND_NEXT, last_sent_commit); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); db_exec_prepared_v2(take(stmt)); } @@ -2278,12 +2278,12 @@ void wallet_state_change_add(struct wallet *w, ", message" ") VALUES (?, ?, ?, ?, ?, ?);")); - db_bind_u64(stmt, 0, channel_id); - db_bind_timeabs(stmt, 1, *timestamp); - db_bind_int(stmt, 2, old_state); - db_bind_int(stmt, 3, new_state); - db_bind_int(stmt, 4, state_change_in_db(cause)); - db_bind_text(stmt, 5, message); + db_bind_u64(stmt, BIND_NEXT, channel_id); + db_bind_timeabs(stmt, BIND_NEXT, *timestamp); + db_bind_int(stmt, BIND_NEXT, old_state); + db_bind_int(stmt, BIND_NEXT, new_state); + db_bind_int(stmt, BIND_NEXT, state_change_in_db(cause)); + db_bind_text(stmt, BIND_NEXT, message); db_exec_prepared_v2(take(stmt)); } @@ -2306,7 +2306,7 @@ struct state_change_entry *wallet_state_change_get(struct wallet *w, "FROM channel_state_changes " "WHERE channel_id = ? " "ORDER BY timestamp ASC;")); - db_bind_int(stmt, 0, channel_id); + db_bind_int(stmt, BIND_NEXT, channel_id); db_query_prepared(stmt); while (db_step(stmt)) { @@ -2328,7 +2328,7 @@ static void wallet_peer_save(struct wallet *w, struct peer *peer) struct db_stmt *stmt = db_prepare_v2(w->db, SQL("SELECT id FROM peers WHERE node_id = ?")); - db_bind_node_id(stmt, 0, &peer->id); + db_bind_node_id(stmt, BIND_NEXT, &peer->id); db_query_prepared(stmt); if (db_step(stmt)) { @@ -2339,9 +2339,9 @@ static void wallet_peer_save(struct wallet *w, struct peer *peer) /* Since we're at it update the wireaddr, feature bits */ stmt = db_prepare_v2( w->db, SQL("UPDATE peers SET address = ?, feature_bits = ? WHERE id = ?")); - db_bind_text(stmt, 0, addr); - db_bind_talarr(stmt, 1, peer->their_features); - db_bind_u64(stmt, 2, peer->dbid); + db_bind_text(stmt, BIND_NEXT, addr); + db_bind_talarr(stmt, BIND_NEXT, peer->their_features); + db_bind_u64(stmt, BIND_NEXT, peer->dbid); db_exec_prepared_v2(take(stmt)); } else { @@ -2350,9 +2350,9 @@ static void wallet_peer_save(struct wallet *w, struct peer *peer) stmt = db_prepare_v2(w->db, SQL("INSERT INTO peers (node_id, address, feature_bits) VALUES (?, ?, ?);") ); - db_bind_node_id(stmt, 0, &peer->id); - db_bind_text(stmt, 1,addr); - db_bind_talarr(stmt, 2, peer->their_features); + db_bind_node_id(stmt, BIND_NEXT, &peer->id); + db_bind_text(stmt, BIND_NEXT, addr); + db_bind_talarr(stmt, BIND_NEXT, peer->their_features); db_exec_prepared_v2(stmt); peer_set_dbid(peer, db_last_insert_id_v2(take(stmt))); } @@ -2382,17 +2382,17 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan) ", require_confirm_inputs_remote" ", require_confirm_inputs_local" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); - db_bind_u64(stmt, 0, chan->peer->dbid); - db_bind_int(stmt, 1, chan->first_blocknum); - db_bind_int(stmt, 2, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, chan->peer->dbid); + db_bind_int(stmt, BIND_NEXT, chan->first_blocknum); + db_bind_int(stmt, BIND_NEXT, chan->dbid); - db_bind_pubkey(stmt, 3, &chan->local_basepoints.revocation); - db_bind_pubkey(stmt, 4, &chan->local_basepoints.payment); - db_bind_pubkey(stmt, 5, &chan->local_basepoints.htlc); - db_bind_pubkey(stmt, 6, &chan->local_basepoints.delayed_payment); - db_bind_pubkey(stmt, 7, &chan->local_funding_pubkey); - db_bind_int(stmt, 8, chan->req_confirmed_ins[REMOTE]); - db_bind_int(stmt, 9, chan->req_confirmed_ins[LOCAL]); + db_bind_pubkey(stmt, BIND_NEXT, &chan->local_basepoints.revocation); + db_bind_pubkey(stmt, BIND_NEXT, &chan->local_basepoints.payment); + db_bind_pubkey(stmt, BIND_NEXT, &chan->local_basepoints.htlc); + db_bind_pubkey(stmt, BIND_NEXT, &chan->local_basepoints.delayed_payment); + db_bind_pubkey(stmt, BIND_NEXT, &chan->local_funding_pubkey); + db_bind_int(stmt, BIND_NEXT, chan->req_confirmed_ins[REMOTE]); + db_bind_int(stmt, BIND_NEXT, chan->req_confirmed_ins[LOCAL]); db_exec_prepared_v2(take(stmt)); @@ -2417,26 +2417,26 @@ void wallet_channel_close(struct wallet *w, u64 wallet_id) /* Delete entries from `channel_htlcs` */ stmt = db_prepare_v2(w->db, SQL("DELETE FROM channel_htlcs " "WHERE channel_id=?")); - db_bind_u64(stmt, 0, wallet_id); + db_bind_u64(stmt, BIND_NEXT, wallet_id); db_exec_prepared_v2(take(stmt)); /* Delete entries from `htlc_sigs` */ stmt = db_prepare_v2(w->db, SQL("DELETE FROM htlc_sigs " "WHERE channelid=?")); - db_bind_u64(stmt, 0, wallet_id); + db_bind_u64(stmt, BIND_NEXT, wallet_id); db_exec_prepared_v2(take(stmt)); /* Delete entries from `htlc_sigs` */ stmt = db_prepare_v2(w->db, SQL("DELETE FROM channeltxs " "WHERE channel_id=?")); - db_bind_u64(stmt, 0, wallet_id); + db_bind_u64(stmt, BIND_NEXT, wallet_id); db_exec_prepared_v2(take(stmt)); /* Delete any entries from 'inflights' */ stmt = db_prepare_v2(w->db, SQL("DELETE FROM channel_funding_inflights " " WHERE channel_id=?")); - db_bind_u64(stmt, 0, wallet_id); + db_bind_u64(stmt, BIND_NEXT, wallet_id); db_exec_prepared_v2(take(stmt)); /* Delete shachains */ @@ -2446,15 +2446,15 @@ void wallet_channel_close(struct wallet *w, u64 wallet_id) " FROM channels " " WHERE channels.id=?" ")")); - db_bind_u64(stmt, 0, wallet_id); + db_bind_u64(stmt, BIND_NEXT, wallet_id); db_exec_prepared_v2(take(stmt)); /* Set the channel to closed */ stmt = db_prepare_v2(w->db, SQL("UPDATE channels " "SET state=? " "WHERE channels.id=?")); - db_bind_u64(stmt, 0, CLOSED); - db_bind_u64(stmt, 1, wallet_id); + db_bind_u64(stmt, BIND_NEXT, CLOSED); + db_bind_u64(stmt, BIND_NEXT, wallet_id); db_exec_prepared_v2(take(stmt)); } @@ -2464,7 +2464,7 @@ void wallet_delete_peer_if_unused(struct wallet *w, u64 peer_dbid) /* Must not have any channels still using this peer */ stmt = db_prepare_v2(w->db, SQL("SELECT * FROM channels WHERE peer_id = ?;")); - db_bind_u64(stmt, 0, peer_dbid); + db_bind_u64(stmt, BIND_NEXT, peer_dbid); db_query_prepared(stmt); if (db_step(stmt)) { @@ -2475,7 +2475,7 @@ void wallet_delete_peer_if_unused(struct wallet *w, u64 peer_dbid) tal_free(stmt); stmt = db_prepare_v2(w->db, SQL("DELETE FROM peers WHERE id=?")); - db_bind_u64(stmt, 0, peer_dbid); + db_bind_u64(stmt, BIND_NEXT, peer_dbid); db_exec_prepared_v2(take(stmt)); } @@ -2488,8 +2488,8 @@ void wallet_confirm_tx(struct wallet *w, stmt = db_prepare_v2(w->db, SQL("UPDATE outputs " "SET confirmation_height = ? " "WHERE prev_out_tx = ?")); - db_bind_int(stmt, 0, confirmation_height); - db_bind_sha256d(stmt, 1, &txid->shad); + db_bind_int(stmt, BIND_NEXT, confirmation_height); + db_bind_sha256d(stmt, BIND_NEXT, &txid->shad); db_exec_prepared_v2(take(stmt)); } @@ -2610,32 +2610,32 @@ void wallet_htlc_save_in(struct wallet *wallet, " fail_immediate) VALUES " "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); - db_bind_u64(stmt, 0, chan->dbid); - db_bind_u64(stmt, 1, in->key.id); - db_bind_int(stmt, 2, DIRECTION_INCOMING); - db_bind_amount_msat(stmt, 3, &in->msat); - db_bind_int(stmt, 4, in->cltv_expiry); - db_bind_sha256(stmt, 5, &in->payment_hash); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, in->key.id); + db_bind_int(stmt, BIND_NEXT, DIRECTION_INCOMING); + db_bind_amount_msat(stmt, BIND_NEXT, &in->msat); + db_bind_int(stmt, BIND_NEXT, in->cltv_expiry); + db_bind_sha256(stmt, BIND_NEXT, &in->payment_hash); if (in->preimage) - db_bind_preimage(stmt, 6, in->preimage); + db_bind_preimage(stmt, BIND_NEXT, in->preimage); else - db_bind_null(stmt, 6); - db_bind_int(stmt, 7, in->hstate); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, in->hstate); if (!in->shared_secret) - db_bind_null(stmt, 8); + db_bind_null(stmt, BIND_NEXT); else - db_bind_secret(stmt, 8, in->shared_secret); + db_bind_secret(stmt, BIND_NEXT, in->shared_secret); - db_bind_blob(stmt, 9, in->onion_routing_packet, + db_bind_blob(stmt, BIND_NEXT, in->onion_routing_packet, sizeof(in->onion_routing_packet)); - db_bind_timeabs(stmt, 10, in->received_time); - db_bind_u64(stmt, 11, min_unsigned(chan->next_index[LOCAL]-1, + db_bind_timeabs(stmt, BIND_NEXT, in->received_time); + db_bind_u64(stmt, BIND_NEXT, min_unsigned(chan->next_index[LOCAL]-1, chan->next_index[REMOTE]-1)); - db_bind_int(stmt, 12, in->fail_immediate); + db_bind_int(stmt, BIND_NEXT, in->fail_immediate); db_exec_prepared_v2(stmt); in->dbid = db_last_insert_id_v2(take(stmt)); @@ -2671,38 +2671,38 @@ void wallet_htlc_save_out(struct wallet *wallet, " min_commit_num" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?);")); - db_bind_u64(stmt, 0, chan->dbid); - db_bind_u64(stmt, 1, out->key.id); - db_bind_int(stmt, 2, DIRECTION_OUTGOING); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, out->key.id); + db_bind_int(stmt, BIND_NEXT, DIRECTION_OUTGOING); if (out->in) - db_bind_u64(stmt, 3, out->in->dbid); + db_bind_u64(stmt, BIND_NEXT, out->in->dbid); else - db_bind_null(stmt, 3); - db_bind_amount_msat(stmt, 4, &out->msat); - db_bind_int(stmt, 5, out->cltv_expiry); - db_bind_sha256(stmt, 6, &out->payment_hash); + db_bind_null(stmt, BIND_NEXT); + db_bind_amount_msat(stmt, BIND_NEXT, &out->msat); + db_bind_int(stmt, BIND_NEXT, out->cltv_expiry); + db_bind_sha256(stmt, BIND_NEXT, &out->payment_hash); if (out->preimage) - db_bind_preimage(stmt, 7, out->preimage); + db_bind_preimage(stmt, BIND_NEXT, out->preimage); else - db_bind_null(stmt, 7); - db_bind_int(stmt, 8, out->hstate); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, out->hstate); - db_bind_blob(stmt, 9, out->onion_routing_packet, + db_bind_blob(stmt, BIND_NEXT, out->onion_routing_packet, sizeof(out->onion_routing_packet)); /* groupid and partid are only relevant when we are the origin */ if (!out->am_origin) { - db_bind_null(stmt, 10); - db_bind_null(stmt, 11); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); } else { - db_bind_u64(stmt, 10, out->partid); - db_bind_u64(stmt, 11, out->groupid); + db_bind_u64(stmt, BIND_NEXT, out->partid); + db_bind_u64(stmt, BIND_NEXT, out->groupid); } - db_bind_amount_msat(stmt, 12, &out->fees); - db_bind_u64(stmt, 13, min_u64(chan->next_index[LOCAL]-1, - chan->next_index[REMOTE]-1)); + db_bind_amount_msat(stmt, BIND_NEXT, &out->fees); + db_bind_u64(stmt, BIND_NEXT, min_u64(chan->next_index[LOCAL]-1, + chan->next_index[REMOTE]-1)); db_exec_prepared_v2(stmt); out->dbid = db_last_insert_id_v2(stmt); @@ -2735,34 +2735,34 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid, "we_filled=?, max_commit_num=?" " WHERE id=?")); - db_bind_int(stmt, 0, htlc_state_in_db(new_state)); + db_bind_int(stmt, BIND_NEXT, htlc_state_in_db(new_state)); if (payment_key) - db_bind_preimage(stmt, 1, payment_key); + db_bind_preimage(stmt, BIND_NEXT, payment_key); else - db_bind_null(stmt, 1); + db_bind_null(stmt, BIND_NEXT); - db_bind_int(stmt, 2, badonion); + db_bind_int(stmt, BIND_NEXT, badonion); if (failonion) - db_bind_onionreply(stmt, 3, failonion); + db_bind_onionreply(stmt, BIND_NEXT, failonion); else - db_bind_null(stmt, 3); + db_bind_null(stmt, BIND_NEXT); - db_bind_talarr(stmt, 4, failmsg); + db_bind_talarr(stmt, BIND_NEXT, failmsg); if (we_filled) - db_bind_int(stmt, 5, *we_filled); + db_bind_int(stmt, BIND_NEXT, *we_filled); else - db_bind_null(stmt, 5); + db_bind_null(stmt, BIND_NEXT); /* Set max_commit_num iff we're in final state. */ if (terminal) - db_bind_u64(stmt, 6, max_commit_num); + db_bind_u64(stmt, BIND_NEXT, max_commit_num); else - db_bind_null(stmt, 6); + db_bind_null(stmt, BIND_NEXT); + db_bind_u64(stmt, BIND_NEXT, htlc_dbid); - db_bind_u64(stmt, 7, htlc_dbid); db_exec_prepared_v2(take(stmt)); if (terminal) { @@ -2771,7 +2771,7 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid, wallet->db, SQL("UPDATE channel_htlcs SET payment_key=NULL, routing_onion=NULL, failuremsg=NULL, shared_secret=NULL, localfailmsg=NULL " " WHERE id=?")); - db_bind_u64(stmt, 0, htlc_dbid); + db_bind_u64(stmt, BIND_NEXT, htlc_dbid); db_exec_prepared_v2(take(stmt)); } } @@ -2964,15 +2964,15 @@ bool wallet_htlcs_load_in_for_channel(struct wallet *wallet, " WHERE direction= ?" " AND channel_id= ?" " AND hstate NOT IN (?, ?)")); - db_bind_int(stmt, 0, DIRECTION_INCOMING); - db_bind_u64(stmt, 1, chan->dbid); + db_bind_int(stmt, BIND_NEXT, DIRECTION_INCOMING); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); /* We need to generate `hstate NOT IN (9, 19)` in order to match * the `WHERE` clause of the database index; incoming HTLCs will * never actually get the state `RCVD_REMOVE_ACK_REVOCATION`. * See https://sqlite.org/partialindex.html#queries_using_partial_indexes */ - db_bind_int(stmt, 2, RCVD_REMOVE_ACK_REVOCATION); /* Not gonna happen. */ - db_bind_int(stmt, 3, SENT_REMOVE_ACK_REVOCATION); + db_bind_int(stmt, BIND_NEXT, RCVD_REMOVE_ACK_REVOCATION); /* Not gonna happen. */ + db_bind_int(stmt, BIND_NEXT, SENT_REMOVE_ACK_REVOCATION); db_query_prepared(stmt); while (db_step(stmt)) { @@ -3017,15 +3017,15 @@ bool wallet_htlcs_load_out_for_channel(struct wallet *wallet, " WHERE direction = ?" " AND channel_id = ?" " AND hstate NOT IN (?, ?)")); - db_bind_int(stmt, 0, DIRECTION_OUTGOING); - db_bind_u64(stmt, 1, chan->dbid); + db_bind_int(stmt, BIND_NEXT, DIRECTION_OUTGOING); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); /* We need to generate `hstate NOT IN (9, 19)` in order to match * the `WHERE` clause of the database index; outgoing HTLCs will * never actually get the state `SENT_REMOVE_ACK_REVOCATION`. * See https://sqlite.org/partialindex.html#queries_using_partial_indexes */ - db_bind_int(stmt, 2, RCVD_REMOVE_ACK_REVOCATION); - db_bind_int(stmt, 3, SENT_REMOVE_ACK_REVOCATION); /* Not gonna happen. */ + db_bind_int(stmt, BIND_NEXT, RCVD_REMOVE_ACK_REVOCATION); + db_bind_int(stmt, BIND_NEXT, SENT_REMOVE_ACK_REVOCATION); /* Not gonna happen. */ db_query_prepared(stmt); while (db_step(stmt)) { @@ -3056,9 +3056,9 @@ struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet, "channel_htlc_id, payment_hash " "FROM channel_htlcs WHERE channel_id = ? AND min_commit_num <= ? AND ((max_commit_num IS NULL) OR max_commit_num >= ?);")); - db_bind_u64(stmt, 0, chan->dbid); - db_bind_u64(stmt, 1, commit_num); - db_bind_u64(stmt, 2, commit_num); + db_bind_u64(stmt, BIND_NEXT, chan->dbid); + db_bind_u64(stmt, BIND_NEXT, commit_num); + db_bind_u64(stmt, BIND_NEXT, commit_num); db_query_prepared(stmt); stubs = tal_arr(ctx, struct htlc_stub, 0); @@ -3093,10 +3093,10 @@ void wallet_local_htlc_out_delete(struct wallet *wallet, " AND origin_htlc = ?" " AND payment_hash = ?" " AND partid = ?;")); - db_bind_int(stmt, 0, DIRECTION_OUTGOING); - db_bind_int(stmt, 1, 0); - db_bind_sha256(stmt, 2, payment_hash); - db_bind_u64(stmt, 3, partid); + db_bind_int(stmt, BIND_NEXT, DIRECTION_OUTGOING); + db_bind_int(stmt, BIND_NEXT, 0); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, partid); db_exec_prepared_v2(take(stmt)); } @@ -3144,9 +3144,9 @@ void wallet_payment_store(struct wallet *wallet, db_prepare_v2(wallet->db, SQL("SELECT status FROM payments" " WHERE payment_hash=?" " AND partid = ? AND groupid = ?;")); - db_bind_sha256(stmt, 0, &payment->payment_hash); - db_bind_u64(stmt, 1, payment->partid); - db_bind_u64(stmt, 2, payment->groupid); + db_bind_sha256(stmt, BIND_NEXT, &payment->payment_hash); + db_bind_u64(stmt, BIND_NEXT, payment->partid); + db_bind_u64(stmt, BIND_NEXT, payment->groupid); db_query_prepared(stmt); res = db_step(stmt); assert(res); @@ -3180,57 +3180,57 @@ void wallet_payment_store(struct wallet *wallet, " paydescription" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); - db_bind_int(stmt, 0, payment->status); - db_bind_sha256(stmt, 1, &payment->payment_hash); + db_bind_int(stmt, BIND_NEXT, payment->status); + db_bind_sha256(stmt, BIND_NEXT, &payment->payment_hash); if (payment->destination != NULL) - db_bind_node_id(stmt, 2, payment->destination); + db_bind_node_id(stmt, BIND_NEXT, payment->destination); else - db_bind_null(stmt, 2); + db_bind_null(stmt, BIND_NEXT); - db_bind_amount_msat(stmt, 3, &payment->msatoshi); - db_bind_int(stmt, 4, payment->timestamp); + db_bind_amount_msat(stmt, BIND_NEXT, &payment->msatoshi); + db_bind_int(stmt, BIND_NEXT, payment->timestamp); if (payment->path_secrets != NULL) - db_bind_secret_arr(stmt, 5, payment->path_secrets); + db_bind_secret_arr(stmt, BIND_NEXT, payment->path_secrets); else - db_bind_null(stmt, 5); + db_bind_null(stmt, BIND_NEXT); assert((payment->route_channels == NULL) == (payment->route_nodes == NULL)); if (payment->route_nodes) { - db_bind_node_id_arr(stmt, 6, payment->route_nodes); - db_bind_short_channel_id_arr(stmt, 7, payment->route_channels); + db_bind_node_id_arr(stmt, BIND_NEXT, payment->route_nodes); + db_bind_short_channel_id_arr(stmt, BIND_NEXT, payment->route_channels); } else { - db_bind_null(stmt, 6); - db_bind_null(stmt, 7); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); } - db_bind_amount_msat(stmt, 8, &payment->msatoshi_sent); + db_bind_amount_msat(stmt, BIND_NEXT, &payment->msatoshi_sent); if (payment->label != NULL) - db_bind_text(stmt, 9, payment->label); + db_bind_text(stmt, BIND_NEXT, payment->label); else - db_bind_null(stmt, 9); + db_bind_null(stmt, BIND_NEXT); if (payment->invstring != NULL) - db_bind_text(stmt, 10, payment->invstring); + db_bind_text(stmt, BIND_NEXT, payment->invstring); else - db_bind_null(stmt, 10); + db_bind_null(stmt, BIND_NEXT); - db_bind_amount_msat(stmt, 11, &payment->total_msat); - db_bind_u64(stmt, 12, payment->partid); + db_bind_amount_msat(stmt, BIND_NEXT, &payment->total_msat); + db_bind_u64(stmt, BIND_NEXT, payment->partid); if (payment->local_invreq_id != NULL) - db_bind_sha256(stmt, 13, payment->local_invreq_id); + db_bind_sha256(stmt, BIND_NEXT, payment->local_invreq_id); else - db_bind_null(stmt, 13); + db_bind_null(stmt, BIND_NEXT); - db_bind_u64(stmt, 14, payment->groupid); + db_bind_u64(stmt, BIND_NEXT, payment->groupid); if (payment->description != NULL) - db_bind_text(stmt, 15, payment->description); + db_bind_text(stmt, BIND_NEXT, payment->description); else - db_bind_null(stmt, 15); + db_bind_null(stmt, BIND_NEXT); db_exec_prepared_v2(stmt); payment->id = db_last_insert_id_v2(stmt); @@ -3253,7 +3253,7 @@ u64 wallet_payment_get_groupid(struct wallet *wallet, stmt = db_prepare_v2( wallet->db, SQL("SELECT MAX(groupid) FROM payments WHERE payment_hash = ?")); - db_bind_sha256(stmt, 0, payment_hash); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); db_query_prepared(stmt); if (db_step(stmt) && !db_col_is_null(stmt, "MAX(groupid)")) { groupid = db_col_u64(stmt, "MAX(groupid)"); @@ -3278,18 +3278,18 @@ void wallet_payment_delete(struct wallet *wallet, " AND groupid = ?" " AND partid = ?" " AND status = ?")); - db_bind_sha256(stmt, 0, payment_hash); - db_bind_u64(stmt, 1, *groupid); - db_bind_u64(stmt, 2, *partid); - db_bind_u64(stmt, 3, *status); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, *groupid); + db_bind_u64(stmt, BIND_NEXT, *partid); + db_bind_u64(stmt, BIND_NEXT, *status); } else { assert(!partid); stmt = db_prepare_v2(wallet->db, SQL("DELETE FROM payments" " WHERE payment_hash = ?" " AND status = ?")); - db_bind_sha256(stmt, 0, payment_hash); - db_bind_u64(stmt, 1, *status); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, *status); } db_exec_prepared_v2(take(stmt)); } @@ -3416,9 +3416,9 @@ wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet, " WHERE payment_hash = ?" " AND partid = ? AND groupid=?")); - db_bind_sha256(stmt, 0, payment_hash); - db_bind_u64(stmt, 1, partid); - db_bind_u64(stmt, 2, groupid); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, partid); + db_bind_u64(stmt, BIND_NEXT, groupid); db_query_prepared(stmt); if (db_step(stmt)) { payment = wallet_stmt2payment(ctx, stmt); @@ -3452,15 +3452,15 @@ void wallet_payment_set_status(struct wallet *wallet, SQL("UPDATE payments SET status=?, completed_at=? " "WHERE payment_hash=? AND partid=? AND groupid=?")); - db_bind_int(stmt, 0, payment_status_in_db(newstatus)); + db_bind_int(stmt, BIND_NEXT, payment_status_in_db(newstatus)); if (completed_at != 0) { - db_bind_u64(stmt, 1, completed_at); + db_bind_u64(stmt, BIND_NEXT, completed_at); } else { - db_bind_null(stmt, 1); + db_bind_null(stmt, BIND_NEXT); } - db_bind_sha256(stmt, 2, payment_hash); - db_bind_u64(stmt, 3, partid); - db_bind_u64(stmt, 4, groupid); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, partid); + db_bind_u64(stmt, BIND_NEXT, groupid); db_exec_prepared_v2(take(stmt)); if (preimage) { @@ -3468,10 +3468,10 @@ void wallet_payment_set_status(struct wallet *wallet, SQL("UPDATE payments SET payment_preimage=? " "WHERE payment_hash=? AND partid=? AND groupid=?")); - db_bind_preimage(stmt, 0, preimage); - db_bind_sha256(stmt, 1, payment_hash); - db_bind_u64(stmt, 2, partid); - db_bind_u64(stmt, 3, groupid); + db_bind_preimage(stmt, BIND_NEXT, preimage); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, partid); + db_bind_u64(stmt, BIND_NEXT, groupid); db_exec_prepared_v2(take(stmt)); } if (newstatus != PAYMENT_PENDING) { @@ -3482,9 +3482,9 @@ void wallet_payment_set_status(struct wallet *wallet, " , route_channels = NULL" " WHERE payment_hash = ?" " AND partid = ? AND groupid=?;")); - db_bind_sha256(stmt, 0, payment_hash); - db_bind_u64(stmt, 1, partid); - db_bind_u64(stmt, 2, groupid); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, partid); + db_bind_u64(stmt, BIND_NEXT, groupid); db_exec_prepared_v2(take(stmt)); } } @@ -3515,9 +3515,9 @@ void wallet_payment_get_failinfo(const tal_t *ctx, ", failupdate, faildetail, faildirection" " FROM payments" " WHERE payment_hash=? AND partid=? AND groupid=?;")); - db_bind_sha256(stmt, 0, payment_hash); - db_bind_u64(stmt, 1, partid); - db_bind_u64(stmt, 2, groupid); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, partid); + db_bind_u64(stmt, BIND_NEXT, groupid); db_query_prepared(stmt); resb = db_step(stmt); assert(resb); @@ -3579,35 +3579,35 @@ void wallet_payment_set_failinfo(struct wallet *wallet, " WHERE payment_hash=?" " AND partid=?;")); if (failonionreply) - db_bind_talarr(stmt, 0, failonionreply->contents); + db_bind_talarr(stmt, BIND_NEXT, failonionreply->contents); else - db_bind_null(stmt, 0); - db_bind_int(stmt, 1, faildestperm ? 1 : 0); - db_bind_int(stmt, 2, failindex); - db_bind_int(stmt, 3, (int) failcode); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, faildestperm ? 1 : 0); + db_bind_int(stmt, BIND_NEXT, failindex); + db_bind_int(stmt, BIND_NEXT, (int) failcode); if (failnode) - db_bind_node_id(stmt, 4, failnode); + db_bind_node_id(stmt, BIND_NEXT, failnode); else - db_bind_null(stmt, 4); + db_bind_null(stmt, BIND_NEXT); if (failchannel) { - db_bind_short_channel_id(stmt, 5, failchannel); - db_bind_int(stmt, 6, faildirection); + db_bind_short_channel_id(stmt, BIND_NEXT, failchannel); + db_bind_int(stmt, BIND_NEXT, faildirection); } else { - db_bind_null(stmt, 5); - db_bind_null(stmt, 6); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); } - db_bind_talarr(stmt, 7, failupdate); + db_bind_talarr(stmt, BIND_NEXT, failupdate); if (faildetail != NULL) - db_bind_text(stmt, 8, faildetail); + db_bind_text(stmt, BIND_NEXT, faildetail); else - db_bind_null(stmt, 8); + db_bind_null(stmt, BIND_NEXT); - db_bind_sha256(stmt, 9, payment_hash); - db_bind_u64(stmt, 10, partid); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); + db_bind_u64(stmt, BIND_NEXT, partid); db_exec_prepared_v2(take(stmt)); } @@ -3650,7 +3650,7 @@ wallet_payment_list(const tal_t *ctx, " WHERE" " payment_hash = ?" " ORDER BY id;")); - db_bind_sha256(stmt, 0, payment_hash); + db_bind_sha256(stmt, BIND_NEXT, payment_hash); } else { stmt = db_prepare_v2(wallet->db, SQL("SELECT" " id" @@ -3729,7 +3729,7 @@ wallet_payments_by_invoice_request(const tal_t *ctx, ", completed_at" " FROM payments" " WHERE local_invreq_id = ?;")); - db_bind_sha256(stmt, 0, local_invreq_id); + db_bind_sha256(stmt, BIND_NEXT, local_invreq_id); db_query_prepared(stmt); for (i = 0; db_step(stmt); i++) { @@ -3755,7 +3755,7 @@ void wallet_htlc_sigs_save(struct wallet *w, u64 channel_id, /* Clear any existing HTLC sigs for this channel */ struct db_stmt *stmt = db_prepare_v2( w->db, SQL("DELETE FROM htlc_sigs WHERE channelid = ?")); - db_bind_u64(stmt, 0, channel_id); + db_bind_u64(stmt, BIND_NEXT, channel_id); db_exec_prepared_v2(take(stmt)); /* Now insert the new ones */ @@ -3763,8 +3763,8 @@ void wallet_htlc_sigs_save(struct wallet *w, u64 channel_id, stmt = db_prepare_v2(w->db, SQL("INSERT INTO htlc_sigs (channelid, " "signature) VALUES (?, ?)")); - db_bind_u64(stmt, 0, channel_id); - db_bind_signature(stmt, 1, &htlc_sigs[i].s); + db_bind_u64(stmt, BIND_NEXT, channel_id); + db_bind_signature(stmt, BIND_NEXT, &htlc_sigs[i].s); db_exec_prepared_v2(take(stmt)); } } @@ -3799,7 +3799,7 @@ bool wallet_sanity_check(struct wallet *w) * that we are running */ stmt = db_prepare_v2(w->db, SQL("INSERT INTO vars (name, blobval) " "VALUES ('genesis_hash', ?);")); - db_bind_sha256d(stmt, 0, &chainparams->genesis_blockhash.shad); + db_bind_sha256d(stmt, BIND_NEXT, &chainparams->genesis_blockhash.shad); db_exec_prepared_v2(take(stmt)); } @@ -3827,7 +3827,7 @@ bool wallet_sanity_check(struct wallet *w) /* Still a pristine wallet, claim it for the node_id we are now */ stmt = db_prepare_v2(w->db, SQL("INSERT INTO vars (name, blobval) " "VALUES ('node_id', ?);")); - db_bind_node_id(stmt, 0, &w->ld->id); + db_bind_node_id(stmt, BIND_NEXT, &w->ld->id); db_exec_prepared_v2(take(stmt)); } return true; @@ -3843,7 +3843,7 @@ static void wallet_utxoset_prune(struct wallet *w, const u32 blockheight) stmt = db_prepare_v2( w->db, SQL("SELECT txid, outnum FROM utxoset WHERE spendheight < ?")); - db_bind_int(stmt, 0, blockheight - UTXO_PRUNE_DEPTH); + db_bind_int(stmt, BIND_NEXT, blockheight - UTXO_PRUNE_DEPTH); db_query_prepared(stmt); while (db_step(stmt)) { @@ -3856,7 +3856,7 @@ static void wallet_utxoset_prune(struct wallet *w, const u32 blockheight) stmt = db_prepare_v2(w->db, SQL("DELETE FROM utxoset WHERE spendheight < ?")); - db_bind_int(stmt, 0, blockheight - UTXO_PRUNE_DEPTH); + db_bind_int(stmt, BIND_NEXT, blockheight - UTXO_PRUNE_DEPTH); db_exec_prepared_v2(take(stmt)); } @@ -3866,12 +3866,12 @@ void wallet_block_add(struct wallet *w, struct block *b) db_prepare_v2(w->db, SQL("INSERT INTO blocks " "(height, hash, prev_hash) " "VALUES (?, ?, ?);")); - db_bind_int(stmt, 0, b->height); - db_bind_sha256d(stmt, 1, &b->blkid.shad); + db_bind_int(stmt, BIND_NEXT, b->height); + db_bind_sha256d(stmt, BIND_NEXT, &b->blkid.shad); if (b->prev) { - db_bind_sha256d(stmt, 2, &b->prev->blkid.shad); - }else { - db_bind_null(stmt, 2); + db_bind_sha256d(stmt, BIND_NEXT, &b->prev->blkid.shad); + } else { + db_bind_null(stmt, BIND_NEXT); } db_exec_prepared_v2(take(stmt)); @@ -3883,13 +3883,13 @@ void wallet_block_remove(struct wallet *w, struct block *b) { struct db_stmt *stmt = db_prepare_v2(w->db, SQL("DELETE FROM blocks WHERE hash = ?")); - db_bind_sha256d(stmt, 0, &b->blkid.shad); + db_bind_sha256d(stmt, BIND_NEXT, &b->blkid.shad); db_exec_prepared_v2(take(stmt)); /* Make sure that all descendants of the block are also deleted */ stmt = db_prepare_v2(w->db, SQL("SELECT * FROM blocks WHERE height >= ?;")); - db_bind_int(stmt, 0, b->height); + db_bind_int(stmt, BIND_NEXT, b->height); db_query_prepared(stmt); assert(!db_step(stmt)); tal_free(stmt); @@ -3899,7 +3899,7 @@ void wallet_blocks_rollback(struct wallet *w, u32 height) { struct db_stmt *stmt = db_prepare_v2(w->db, SQL("DELETE FROM blocks " "WHERE height > ?")); - db_bind_int(stmt, 0, height); + db_bind_int(stmt, BIND_NEXT, height); db_exec_prepared_v2(take(stmt)); } @@ -3915,10 +3915,10 @@ bool wallet_outpoint_spend(struct wallet *w, const tal_t *ctx, const u32 blockhe "WHERE prev_out_tx = ?" " AND prev_out_index = ?")); - db_bind_int(stmt, 0, blockheight); - db_bind_int(stmt, 1, output_status_in_db(OUTPUT_STATE_SPENT)); - db_bind_txid(stmt, 2, &outpoint->txid); - db_bind_int(stmt, 3, outpoint->n); + db_bind_int(stmt, BIND_NEXT, blockheight); + db_bind_int(stmt, BIND_NEXT, output_status_in_db(OUTPUT_STATE_SPENT)); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); db_exec_prepared_v2(take(stmt)); @@ -3932,9 +3932,9 @@ bool wallet_outpoint_spend(struct wallet *w, const tal_t *ctx, const u32 blockhe "WHERE txid = ?" " AND outnum = ?")); - db_bind_int(stmt, 0, blockheight); - db_bind_txid(stmt, 1, &outpoint->txid); - db_bind_int(stmt, 2, outpoint->n); + db_bind_int(stmt, BIND_NEXT, blockheight); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); db_exec_prepared_v2(stmt); tal_free(stmt); } @@ -3958,13 +3958,13 @@ void wallet_utxoset_add(struct wallet *w, " scriptpubkey," " satoshis" ") VALUES(?, ?, ?, ?, ?, ?, ?);")); - db_bind_txid(stmt, 0, &outpoint->txid); - db_bind_int(stmt, 1, outpoint->n); - db_bind_int(stmt, 2, blockheight); - db_bind_null(stmt, 3); - db_bind_int(stmt, 4, txindex); - db_bind_talarr(stmt, 5, scriptpubkey); - db_bind_amount_sat(stmt, 6, &sat); + db_bind_txid(stmt, BIND_NEXT, &outpoint->txid); + db_bind_int(stmt, BIND_NEXT, outpoint->n); + db_bind_int(stmt, BIND_NEXT, blockheight); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, txindex); + db_bind_talarr(stmt, BIND_NEXT, scriptpubkey); + db_bind_amount_sat(stmt, BIND_NEXT, &sat); db_exec_prepared_v2(take(stmt)); outpointfilter_add(w->utxoset_outpoints, outpoint); @@ -3979,9 +3979,9 @@ void wallet_filteredblock_add(struct wallet *w, const struct filteredblock *fb) stmt = db_prepare_v2(w->db, SQL("INSERT INTO blocks " "(height, hash, prev_hash) " "VALUES (?, ?, ?);")); - db_bind_int(stmt, 0, fb->height); - db_bind_sha256d(stmt, 1, &fb->id.shad); - db_bind_sha256d(stmt, 2, &fb->prev_hash.shad); + db_bind_int(stmt, BIND_NEXT, fb->height); + db_bind_sha256d(stmt, BIND_NEXT, &fb->id.shad); + db_bind_sha256d(stmt, BIND_NEXT, &fb->prev_hash.shad); db_exec_prepared_v2(take(stmt)); for (size_t i = 0; i < tal_count(fb->outpoints); i++) { @@ -3996,13 +3996,13 @@ void wallet_filteredblock_add(struct wallet *w, const struct filteredblock *fb) " scriptpubkey," " satoshis" ") VALUES(?, ?, ?, ?, ?, ?, ?);")); - db_bind_txid(stmt, 0, &o->outpoint.txid); - db_bind_int(stmt, 1, o->outpoint.n); - db_bind_int(stmt, 2, fb->height); - db_bind_null(stmt, 3); - db_bind_int(stmt, 4, o->txindex); - db_bind_talarr(stmt, 5, o->scriptPubKey); - db_bind_amount_sat(stmt, 6, &o->amount); + db_bind_txid(stmt, BIND_NEXT, &o->outpoint.txid); + db_bind_int(stmt, BIND_NEXT, o->outpoint.n); + db_bind_int(stmt, BIND_NEXT, fb->height); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, o->txindex); + db_bind_talarr(stmt, BIND_NEXT, o->scriptPubKey); + db_bind_amount_sat(stmt, BIND_NEXT, &o->amount); db_exec_prepared_v2(take(stmt)); outpointfilter_add(w->utxoset_outpoints, &o->outpoint); @@ -4014,7 +4014,7 @@ bool wallet_have_block(struct wallet *w, u32 blockheight) bool result; struct db_stmt *stmt = db_prepare_v2( w->db, SQL("SELECT height FROM blocks WHERE height = ?")); - db_bind_int(stmt, 0, blockheight); + db_bind_int(stmt, BIND_NEXT, blockheight); db_query_prepared(stmt); result = db_step(stmt); if (result) @@ -4038,9 +4038,9 @@ struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx, " AND txindex = ?" " AND outnum = ?" " AND spendheight IS NULL")); - db_bind_int(stmt, 0, short_channel_id_blocknum(scid)); - db_bind_int(stmt, 1, short_channel_id_txnum(scid)); - db_bind_int(stmt, 2, short_channel_id_outnum(scid)); + db_bind_int(stmt, BIND_NEXT, short_channel_id_blocknum(scid)); + db_bind_int(stmt, BIND_NEXT, short_channel_id_txnum(scid)); + db_bind_int(stmt, BIND_NEXT, short_channel_id_outnum(scid)); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -4097,7 +4097,7 @@ wallet_utxoset_get_spent(const tal_t *ctx, struct wallet *w, " outnum " "FROM utxoset " "WHERE spendheight = ?")); - db_bind_int(stmt, 0, blockheight); + db_bind_int(stmt, BIND_NEXT, blockheight); db_query_prepared(stmt); return db_scids(ctx, stmt); @@ -4114,7 +4114,7 @@ wallet_utxoset_get_created(const tal_t *ctx, struct wallet *w, " outnum " "FROM utxoset " "WHERE blockheight = ?")); - db_bind_int(stmt, 0, blockheight); + db_bind_int(stmt, BIND_NEXT, blockheight); db_query_prepared(stmt); return db_scids(ctx, stmt); @@ -4128,7 +4128,7 @@ void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx, w->db, SQL("SELECT blockheight FROM transactions WHERE id=?")); wally_txid(tx, &txid); - db_bind_txid(stmt, 0, &txid); + db_bind_txid(stmt, BIND_NEXT, &txid); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -4140,15 +4140,15 @@ void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx, ", blockheight" ", txindex" ", rawtx) VALUES (?, ?, ?, ?);")); - db_bind_txid(stmt, 0, &txid); + db_bind_txid(stmt, BIND_NEXT, &txid); if (blockheight) { - db_bind_int(stmt, 1, blockheight); - db_bind_int(stmt, 2, txindex); + db_bind_int(stmt, BIND_NEXT, blockheight); + db_bind_int(stmt, BIND_NEXT, txindex); } else { - db_bind_null(stmt, 1); - db_bind_null(stmt, 2); + db_bind_null(stmt, BIND_NEXT); + db_bind_null(stmt, BIND_NEXT); } - db_bind_tx(stmt, 3, tx); + db_bind_tx(stmt, BIND_NEXT, tx); db_exec_prepared_v2(take(stmt)); } else { db_col_ignore(stmt, "blockheight"); @@ -4160,9 +4160,9 @@ void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx, SQL("UPDATE transactions " "SET blockheight = ?, txindex = ? " "WHERE id = ?")); - db_bind_int(stmt, 0, blockheight); - db_bind_int(stmt, 1, txindex); - db_bind_txid(stmt, 2, &txid); + db_bind_int(stmt, BIND_NEXT, blockheight); + db_bind_int(stmt, BIND_NEXT, txindex); + db_bind_txid(stmt, BIND_NEXT, &txid); db_exec_prepared_v2(take(stmt)); } } @@ -4178,14 +4178,14 @@ static void wallet_annotation_add(struct wallet *w, const struct bitcoin_txid *t "(txid, idx, location, type, channel) " "VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;")); - db_bind_txid(stmt, 0, txid); - db_bind_int(stmt, 1, num); - db_bind_int(stmt, 2, annotation_type); - db_bind_int(stmt, 3, type); + db_bind_txid(stmt, BIND_NEXT, txid); + db_bind_int(stmt, BIND_NEXT, num); + db_bind_int(stmt, BIND_NEXT, annotation_type); + db_bind_int(stmt, BIND_NEXT, type); if (channel != 0) - db_bind_u64(stmt, 4, channel); + db_bind_u64(stmt, BIND_NEXT, channel); else - db_bind_null(stmt, 4); + db_bind_null(stmt, BIND_NEXT); db_exec_prepared_v2(take(stmt)); } @@ -4209,7 +4209,7 @@ struct bitcoin_tx *wallet_transaction_get(const tal_t *ctx, struct wallet *w, struct bitcoin_tx *tx; struct db_stmt *stmt = db_prepare_v2( w->db, SQL("SELECT rawtx FROM transactions WHERE id=?")); - db_bind_txid(stmt, 0, txid); + db_bind_txid(stmt, BIND_NEXT, txid); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -4231,7 +4231,7 @@ u32 wallet_transaction_height(struct wallet *w, const struct bitcoin_txid *txid) u32 blockheight; struct db_stmt *stmt = db_prepare_v2( w->db, SQL("SELECT blockheight FROM transactions WHERE id=?")); - db_bind_txid(stmt, 0, txid); + db_bind_txid(stmt, BIND_NEXT, txid); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -4255,7 +4255,7 @@ struct txlocator *wallet_transaction_locate(const tal_t *ctx, struct wallet *w, stmt = db_prepare_v2( w->db, SQL("SELECT blockheight, txindex FROM transactions WHERE id=?")); - db_bind_txid(stmt, 0, txid); + db_bind_txid(stmt, BIND_NEXT, txid); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -4284,7 +4284,7 @@ struct bitcoin_txid *wallet_transactions_by_height(const tal_t *ctx, int count = 0; stmt = db_prepare_v2( w->db, SQL("SELECT id FROM transactions WHERE blockheight=?")); - db_bind_int(stmt, 0, blockheight); + db_bind_int(stmt, BIND_NEXT, blockheight); db_query_prepared(stmt); while (db_step(stmt)) { @@ -4309,11 +4309,11 @@ void wallet_channeltxs_add(struct wallet *w, struct channel *chan, ", input_num" ", blockheight" ") VALUES (?, ?, ?, ?, ?);")); - db_bind_int(stmt, 0, chan->dbid); - db_bind_int(stmt, 1, type); - db_bind_sha256(stmt, 2, &txid->shad.sha); - db_bind_int(stmt, 3, input_num); - db_bind_int(stmt, 4, blockheight); + db_bind_int(stmt, BIND_NEXT, chan->dbid); + db_bind_int(stmt, BIND_NEXT, type); + db_bind_sha256(stmt, BIND_NEXT, &txid->shad.sha); + db_bind_int(stmt, BIND_NEXT, input_num); + db_bind_int(stmt, BIND_NEXT, blockheight); db_exec_prepared_v2(take(stmt)); } @@ -4327,7 +4327,7 @@ u32 *wallet_onchaind_channels(struct wallet *w, stmt = db_prepare_v2( w->db, SQL("SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;")); - db_bind_int(stmt, 0, WIRE_ONCHAIND_INIT); + db_bind_int(stmt, BIND_NEXT, WIRE_ONCHAIND_INIT); db_query_prepared(stmt); while (db_step(stmt)) { @@ -4358,7 +4358,7 @@ struct channeltx *wallet_channeltxs_get(struct wallet *w, const tal_t *ctx, "JOIN transactions t ON t.id = c.transaction_id " "WHERE c.channel_id = ? " "ORDER BY c.id ASC;")); - db_bind_int(stmt, 0, channel_id); + db_bind_int(stmt, BIND_NEXT, channel_id); db_query_prepared(stmt); while (db_step(stmt)) { @@ -4401,36 +4401,36 @@ static bool wallet_forwarded_payment_update(struct wallet *w, ", failcode=?" ", forward_style=?" " WHERE in_htlc_id=? AND in_channel_scid=?")); - db_bind_amount_msat(stmt, 0, &in->msat); + db_bind_amount_msat(stmt, BIND_NEXT, &in->msat); if (out) { - db_bind_amount_msat(stmt, 1, &out->msat); + db_bind_amount_msat(stmt, BIND_NEXT, &out->msat); } else { - db_bind_null(stmt, 1); + db_bind_null(stmt, BIND_NEXT); } - db_bind_int(stmt, 2, wallet_forward_status_in_db(state)); + db_bind_int(stmt, BIND_NEXT, wallet_forward_status_in_db(state)); if (resolved_time != NULL) { - db_bind_timeabs(stmt, 3, *resolved_time); + db_bind_timeabs(stmt, BIND_NEXT, *resolved_time); } else { - db_bind_null(stmt, 3); + db_bind_null(stmt, BIND_NEXT); } if (failcode != 0) { assert(state == FORWARD_FAILED || state == FORWARD_LOCAL_FAILED); - db_bind_int(stmt, 4, (int)failcode); + db_bind_int(stmt, BIND_NEXT, (int)failcode); } else { - db_bind_null(stmt, 4); + db_bind_null(stmt, BIND_NEXT); } /* This can happen for malformed onions, reload from db. */ if (forward_style == FORWARD_STYLE_UNKNOWN) - db_bind_null(stmt, 5); + db_bind_null(stmt, BIND_NEXT); else - db_bind_int(stmt, 5, forward_style_in_db(forward_style)); - db_bind_u64(stmt, 6, in->key.id); - db_bind_short_channel_id(stmt, 7, channel_scid_or_local_alias(in->key.channel)); + db_bind_int(stmt, BIND_NEXT, forward_style_in_db(forward_style)); + db_bind_u64(stmt, BIND_NEXT, in->key.id); + db_bind_short_channel_id(stmt, BIND_NEXT, channel_scid_or_local_alias(in->key.channel)); db_exec_prepared_v2(stmt); changed = db_count_changes(stmt) != 0; tal_free(stmt); @@ -4472,7 +4472,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, ", failcode" ", forward_style" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); - db_bind_u64(stmt, 0, in->key.id); + db_bind_u64(stmt, BIND_NEXT, in->key.id); /* FORWARD_LOCAL_FAILED may occur before we get htlc_out */ if (!out || !scid_out) { @@ -4481,46 +4481,46 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, } if (out) - db_bind_u64(stmt, 1, out->key.id); + db_bind_u64(stmt, BIND_NEXT, out->key.id); else - db_bind_null(stmt, 1); + db_bind_null(stmt, BIND_NEXT); /* We use the LOCAL alias, since that's under our control, and * we keep it stable, whereas the REMOTE alias is likely what * the sender used to specify the channel, but that's under * control of the remote end. */ assert(in->key.channel->scid != NULL || in->key.channel->alias[LOCAL]); - db_bind_short_channel_id(stmt, 2, channel_scid_or_local_alias(in->key.channel)); + db_bind_short_channel_id(stmt, BIND_NEXT, channel_scid_or_local_alias(in->key.channel)); if (scid_out) - db_bind_short_channel_id(stmt, 3, scid_out); + db_bind_short_channel_id(stmt, BIND_NEXT, scid_out); else - db_bind_null(stmt, 3); - db_bind_amount_msat(stmt, 4, &in->msat); + db_bind_null(stmt, BIND_NEXT); + db_bind_amount_msat(stmt, BIND_NEXT, &in->msat); if (out) - db_bind_amount_msat(stmt, 5, &out->msat); + db_bind_amount_msat(stmt, BIND_NEXT, &out->msat); else - db_bind_null(stmt, 5); + db_bind_null(stmt, BIND_NEXT); - db_bind_int(stmt, 6, wallet_forward_status_in_db(state)); - db_bind_timeabs(stmt, 7, in->received_time); + db_bind_int(stmt, BIND_NEXT, wallet_forward_status_in_db(state)); + db_bind_timeabs(stmt, BIND_NEXT, in->received_time); if (resolved_time != NULL) - db_bind_timeabs(stmt, 8, *resolved_time); + db_bind_timeabs(stmt, BIND_NEXT, *resolved_time); else - db_bind_null(stmt, 8); + db_bind_null(stmt, BIND_NEXT); if (failcode != 0) { assert(state == FORWARD_FAILED || state == FORWARD_LOCAL_FAILED); - db_bind_int(stmt, 9, (int)failcode); + db_bind_int(stmt, BIND_NEXT, (int)failcode); } else { - db_bind_null(stmt, 9); + db_bind_null(stmt, BIND_NEXT); } /* This can happen for malformed onions, reload from db! */ if (forward_style == FORWARD_STYLE_UNKNOWN) - db_bind_null(stmt, 10); + db_bind_null(stmt, BIND_NEXT); else - db_bind_int(stmt, 10, forward_style_in_db(forward_style)); + db_bind_int(stmt, BIND_NEXT, forward_style_in_db(forward_style)); db_exec_prepared_v2(take(stmt)); @@ -4539,7 +4539,7 @@ struct amount_msat wallet_total_forward_fees(struct wallet *w) " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)" " FROM forwards " "WHERE state = ?;")); - db_bind_int(stmt, 0, wallet_forward_status_in_db(FORWARD_SETTLED)); + db_bind_int(stmt, BIND_NEXT, wallet_forward_status_in_db(FORWARD_SETTLED)); db_query_prepared(stmt); res = db_step(stmt); @@ -4611,32 +4611,32 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, if (status == FORWARD_ANY) { // any status - db_bind_int(stmt, 0, 1); - db_bind_int(stmt, 1, any); + db_bind_int(stmt, BIND_NEXT, 1); + db_bind_int(stmt, BIND_NEXT, any); } else { // specific forward status - db_bind_int(stmt, 0, 0); - db_bind_int(stmt, 1, status); + db_bind_int(stmt, BIND_NEXT, 0); + db_bind_int(stmt, BIND_NEXT, status); } if (chan_in) { // specific in_channel - db_bind_int(stmt, 2, 0); - db_bind_short_channel_id(stmt, 3, chan_in); + db_bind_int(stmt, BIND_NEXT, 0); + db_bind_short_channel_id(stmt, BIND_NEXT, chan_in); } else { // any in_channel - db_bind_int(stmt, 2, 1); - db_bind_int(stmt, 3, any); + db_bind_int(stmt, BIND_NEXT, 1); + db_bind_int(stmt, BIND_NEXT, any); } if (chan_out) { // specific out_channel - db_bind_int(stmt, 4, 0); - db_bind_short_channel_id(stmt, 5, chan_out); + db_bind_int(stmt, BIND_NEXT, 0); + db_bind_short_channel_id(stmt, BIND_NEXT, chan_out); } else { // any out_channel - db_bind_int(stmt, 4, 1); - db_bind_int(stmt, 5, any); + db_bind_int(stmt, BIND_NEXT, 1); + db_bind_int(stmt, BIND_NEXT, any); } db_query_prepared(stmt); @@ -4736,9 +4736,9 @@ bool wallet_forward_delete(struct wallet *w, " WHERE in_channel_scid = ?" " AND in_htlc_id = ?" " AND state = ?;")); - db_bind_short_channel_id(stmt, 0, chan_in); - db_bind_u64(stmt, 1, *htlc_id); - db_bind_int(stmt, 2, wallet_forward_status_in_db(FORWARD_SETTLED)); + db_bind_short_channel_id(stmt, BIND_NEXT, chan_in); + db_bind_u64(stmt, BIND_NEXT, *htlc_id); + db_bind_int(stmt, BIND_NEXT, wallet_forward_status_in_db(FORWARD_SETTLED)); } else { stmt = db_prepare_v2(w->db, SQL("SELECT" " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)" @@ -4746,8 +4746,8 @@ bool wallet_forward_delete(struct wallet *w, " WHERE in_channel_scid = ?" " AND in_htlc_id IS NULL" " AND state = ?;")); - db_bind_short_channel_id(stmt, 0, chan_in); - db_bind_int(stmt, 1, wallet_forward_status_in_db(FORWARD_SETTLED)); + db_bind_short_channel_id(stmt, BIND_NEXT, chan_in); + db_bind_int(stmt, BIND_NEXT, wallet_forward_status_in_db(FORWARD_SETTLED)); } db_query_prepared(stmt); @@ -4769,17 +4769,17 @@ bool wallet_forward_delete(struct wallet *w, " WHERE in_channel_scid = ?" " AND in_htlc_id = ?" " AND state = ?")); - db_bind_short_channel_id(stmt, 0, chan_in); - db_bind_u64(stmt, 1, *htlc_id); - db_bind_int(stmt, 2, wallet_forward_status_in_db(state)); + db_bind_short_channel_id(stmt, BIND_NEXT, chan_in); + db_bind_u64(stmt, BIND_NEXT, *htlc_id); + db_bind_int(stmt, BIND_NEXT, wallet_forward_status_in_db(state)); } else { stmt = db_prepare_v2(w->db, SQL("DELETE FROM forwards" " WHERE in_channel_scid = ?" " AND in_htlc_id IS NULL" " AND state = ?")); - db_bind_short_channel_id(stmt, 0, chan_in); - db_bind_int(stmt, 1, wallet_forward_status_in_db(state)); + db_bind_short_channel_id(stmt, BIND_NEXT, chan_in); + db_bind_int(stmt, BIND_NEXT, wallet_forward_status_in_db(state)); } db_exec_prepared_v2(stmt); changed = db_count_changes(stmt) != 0; @@ -4844,11 +4844,11 @@ void wallet_penalty_base_add(struct wallet *w, u64 chan_id, ", amount" ") VALUES (?, ?, ?, ?, ?);")); - db_bind_u64(stmt, 0, chan_id); - db_bind_u64(stmt, 1, pb->commitment_num); - db_bind_txid(stmt, 2, &pb->txid); - db_bind_int(stmt, 3, pb->outnum); - db_bind_amount_sat(stmt, 4, &pb->amount); + db_bind_u64(stmt, BIND_NEXT, chan_id); + db_bind_u64(stmt, BIND_NEXT, pb->commitment_num); + db_bind_txid(stmt, BIND_NEXT, &pb->txid); + db_bind_int(stmt, BIND_NEXT, pb->outnum); + db_bind_amount_sat(stmt, BIND_NEXT, &pb->amount); db_exec_prepared_v2(take(stmt)); } @@ -4865,7 +4865,7 @@ struct penalty_base *wallet_penalty_base_load_for_channel(const tal_t *ctx, "FROM penalty_bases " "WHERE channel_id = ?")); - db_bind_u64(stmt, 0, chan_id); + db_bind_u64(stmt, BIND_NEXT, chan_id); db_query_prepared(stmt); while (db_step(stmt)) { @@ -4887,8 +4887,8 @@ void wallet_penalty_base_delete(struct wallet *w, u64 chan_id, u64 commitnum) w->db, SQL("DELETE FROM penalty_bases " "WHERE channel_id = ? AND commitnum = ?")); - db_bind_u64(stmt, 0, chan_id); - db_bind_u64(stmt, 1, commitnum); + db_bind_u64(stmt, BIND_NEXT, chan_id); + db_bind_u64(stmt, BIND_NEXT, commitnum); db_exec_prepared_v2(take(stmt)); } @@ -4906,7 +4906,7 @@ bool wallet_offer_create(struct wallet *w, stmt = db_prepare_v2(w->db, SQL("SELECT 1" " FROM offers" " WHERE offer_id = ?;")); - db_bind_sha256(stmt, 0, offer_id); + db_bind_sha256(stmt, BIND_NEXT, offer_id); db_query_prepared(stmt); if (db_step(stmt)) { @@ -4924,13 +4924,13 @@ bool wallet_offer_create(struct wallet *w, ", status" ") VALUES (?, ?, ?, ?);")); - db_bind_sha256(stmt, 0, offer_id); - db_bind_text(stmt, 1, bolt12); + db_bind_sha256(stmt, BIND_NEXT, offer_id); + db_bind_text(stmt, BIND_NEXT, bolt12); if (label) - db_bind_json_escape(stmt, 2, label); + db_bind_json_escape(stmt, BIND_NEXT, label); else - db_bind_null(stmt, 2); - db_bind_int(stmt, 3, offer_status_in_db(status)); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, offer_status_in_db(status)); db_exec_prepared_v2(take(stmt)); return true; } @@ -4947,7 +4947,7 @@ char *wallet_offer_find(const tal_t *ctx, stmt = db_prepare_v2(w->db, SQL("SELECT bolt12, label, status" " FROM offers" " WHERE offer_id = ?;")); - db_bind_sha256(stmt, 0, offer_id); + db_bind_sha256(stmt, BIND_NEXT, offer_id); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -5006,8 +5006,8 @@ static void offer_status_update(struct db *db, stmt = db_prepare_v2(db, SQL("UPDATE offers" " SET status=?" " WHERE offer_id = ?;")); - db_bind_int(stmt, 0, offer_status_in_db(newstatus)); - db_bind_sha256(stmt, 1, offer_id); + db_bind_int(stmt, BIND_NEXT, offer_status_in_db(newstatus)); + db_bind_sha256(stmt, BIND_NEXT, offer_id); db_exec_prepared_v2(take(stmt)); if (!offer_status_active(oldstatus) @@ -5017,9 +5017,9 @@ static void offer_status_update(struct db *db, stmt = db_prepare_v2(db, SQL("UPDATE invoices" " SET state=?" " WHERE state=? AND local_offer_id = ?;")); - db_bind_int(stmt, 0, invoice_status_in_db(EXPIRED)); - db_bind_int(stmt, 1, invoice_status_in_db(UNPAID)); - db_bind_sha256(stmt, 2, offer_id); + db_bind_int(stmt, BIND_NEXT, invoice_status_in_db(EXPIRED)); + db_bind_int(stmt, BIND_NEXT, invoice_status_in_db(UNPAID)); + db_bind_sha256(stmt, BIND_NEXT, offer_id); db_exec_prepared_v2(take(stmt)); } @@ -5045,7 +5045,7 @@ void wallet_offer_mark_used(struct db *db, const struct sha256 *offer_id) stmt = db_prepare_v2(db, SQL("SELECT status" " FROM offers" " WHERE offer_id = ?;")); - db_bind_sha256(stmt, 0, offer_id); + db_bind_sha256(stmt, BIND_NEXT, offer_id); db_query_prepared(stmt); if (!db_step(stmt)) fatal("%s: unknown offer_id %s", @@ -5086,7 +5086,7 @@ bool wallet_invoice_request_create(struct wallet *w, stmt = db_prepare_v2(w->db, SQL("SELECT 1" " FROM invoicerequests" " WHERE invreq_id = ?;")); - db_bind_sha256(stmt, 0, invreq_id); + db_bind_sha256(stmt, BIND_NEXT, invreq_id); db_query_prepared(stmt); if (db_step(stmt)) { @@ -5104,13 +5104,13 @@ bool wallet_invoice_request_create(struct wallet *w, ", status" ") VALUES (?, ?, ?, ?);")); - db_bind_sha256(stmt, 0, invreq_id); - db_bind_text(stmt, 1, bolt12); + db_bind_sha256(stmt, BIND_NEXT, invreq_id); + db_bind_text(stmt, BIND_NEXT, bolt12); if (label) - db_bind_json_escape(stmt, 2, label); + db_bind_json_escape(stmt, BIND_NEXT, label); else - db_bind_null(stmt, 2); - db_bind_int(stmt, 3, offer_status_in_db(status)); + db_bind_null(stmt, BIND_NEXT); + db_bind_int(stmt, BIND_NEXT, offer_status_in_db(status)); db_exec_prepared_v2(take(stmt)); return true; } @@ -5127,7 +5127,7 @@ char *wallet_invoice_request_find(const tal_t *ctx, stmt = db_prepare_v2(w->db, SQL("SELECT bolt12, label, status" " FROM invoicerequests" " WHERE invreq_id = ?;")); - db_bind_sha256(stmt, 0, invreq_id); + db_bind_sha256(stmt, BIND_NEXT, invreq_id); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -5185,8 +5185,8 @@ static void invoice_request_status_update(struct db *db, stmt = db_prepare_v2(db, SQL("UPDATE invoicerequests" " SET status=?" " WHERE invreq_id = ?;")); - db_bind_int(stmt, 0, offer_status_in_db(newstatus)); - db_bind_sha256(stmt, 1, invreq_id); + db_bind_int(stmt, BIND_NEXT, offer_status_in_db(newstatus)); + db_bind_sha256(stmt, BIND_NEXT, invreq_id); db_exec_prepared_v2(take(stmt)); } @@ -5212,7 +5212,7 @@ void wallet_invoice_request_mark_used(struct db *db, const struct sha256 *invreq stmt = db_prepare_v2(db, SQL("SELECT status" " FROM invoicerequests" " WHERE invreq_id = ?;")); - db_bind_sha256(stmt, 0, invreq_id); + db_bind_sha256(stmt, BIND_NEXT, invreq_id); db_query_prepared(stmt); if (!db_step(stmt)) fatal("%s: unknown invreq_id %s", @@ -5294,8 +5294,8 @@ void wallet_datastore_update(struct wallet *w, const char **key, const u8 *data) stmt = db_prepare_v2(w->db, SQL("UPDATE datastore SET data=?, generation=generation+1 WHERE key=?;")); - db_bind_talarr(stmt, 0, data); - db_bind_datastore_key(stmt, 1, key); + db_bind_talarr(stmt, BIND_NEXT, data); + db_bind_datastore_key(stmt, BIND_NEXT, key); db_exec_prepared_v2(take(stmt)); } @@ -5306,8 +5306,8 @@ void wallet_datastore_create(struct wallet *w, const char **key, const u8 *data) stmt = db_prepare_v2(w->db, SQL("INSERT INTO datastore VALUES (?, ?, 0);")); - db_bind_datastore_key(stmt, 0, key); - db_bind_talarr(stmt, 1, data); + db_bind_datastore_key(stmt, BIND_NEXT, key); + db_bind_talarr(stmt, BIND_NEXT, data); db_exec_prepared_v2(take(stmt)); } @@ -5317,7 +5317,7 @@ void wallet_datastore_remove(struct wallet *w, const char **key) stmt = db_prepare_v2(w->db, SQL("DELETE FROM datastore" " WHERE key = ?")); - db_bind_datastore_key(stmt, 0, key); + db_bind_datastore_key(stmt, BIND_NEXT, key); db_exec_prepared_v2(take(stmt)); } @@ -5336,7 +5336,7 @@ struct db_stmt *wallet_datastore_first(const tal_t *ctx, " FROM datastore" " WHERE key >= ?" " ORDER BY key;")); - db_bind_datastore_key(stmt, 0, startkey); + db_bind_datastore_key(stmt, BIND_NEXT, startkey); } else { stmt = db_prepare_v2(w->db, SQL("SELECT key, data, generation" @@ -5407,7 +5407,7 @@ struct wallet_htlc_iter *wallet_htlcs_first(const tal_t *ctx, " FROM channel_htlcs h" " WHERE channel_id = ?" " ORDER BY id ASC")); - db_bind_u64(i->stmt, 0, chan->dbid); + db_bind_u64(i->stmt, BIND_NEXT, chan->dbid); } else { i->scid.u64 = 0; i->stmt = db_prepare_v2(w->db,