@@ -4722,9 +4722,10 @@ struct bitcoin_txid *wallet_transactions_by_height(const tal_t *ctx,
47224722 return txids ;
47234723}
47244724
4725- void wallet_channeltxs_add (struct wallet * w , struct channel * chan ,
4726- const int type , const struct bitcoin_txid * txid ,
4727- const u32 input_num , const u32 blockheight )
4725+ void wallet_insert_funding_spend (struct wallet * w ,
4726+ const struct channel * chan ,
4727+ const struct bitcoin_txid * txid ,
4728+ const u32 input_num , const u32 blockheight )
47284729{
47294730 struct db_stmt * stmt ;
47304731 stmt = db_prepare_v2 (w -> db , SQL ("INSERT INTO channeltxs ("
@@ -4735,72 +4736,15 @@ void wallet_channeltxs_add(struct wallet *w, struct channel *chan,
47354736 ", blockheight"
47364737 ") VALUES (?, ?, ?, ?, ?);" ));
47374738 db_bind_int (stmt , chan -> dbid );
4738- db_bind_int (stmt , type );
4739- db_bind_sha256 (stmt , & txid -> shad .sha );
4739+ /* FIXME: This is WIRE_ONCHAIND_INIT, accidentally leaked into db! */
4740+ db_bind_int (stmt , 5001 );
4741+ db_bind_txid (stmt , txid );
47404742 db_bind_int (stmt , input_num );
47414743 db_bind_int (stmt , blockheight );
47424744
47434745 db_exec_prepared_v2 (take (stmt ));
47444746}
47454747
4746- u32 * wallet_onchaind_channels (const tal_t * ctx , struct wallet * w )
4747- {
4748- struct db_stmt * stmt ;
4749- size_t count = 0 ;
4750- u32 * channel_ids = tal_arr (ctx , u32 , 0 );
4751- stmt = db_prepare_v2 (
4752- w -> db ,
4753- SQL ("SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" ));
4754- db_bind_int (stmt , WIRE_ONCHAIND_INIT );
4755- db_query_prepared (stmt );
4756-
4757- while (db_step (stmt )) {
4758- count ++ ;
4759- tal_resize (& channel_ids , count );
4760- channel_ids [count - 1 ] = db_col_u64 (stmt , "DISTINCT(channel_id)" );
4761- }
4762- tal_free (stmt );
4763-
4764- return channel_ids ;
4765- }
4766-
4767- struct channeltx * wallet_channeltxs_get (const tal_t * ctx , struct wallet * w ,
4768- u32 channel_id )
4769- {
4770- struct db_stmt * stmt ;
4771- size_t count = 0 ;
4772- struct channeltx * res = tal_arr (ctx , struct channeltx , 0 );
4773- stmt = db_prepare_v2 (
4774- w -> db , SQL ("SELECT"
4775- " c.type"
4776- ", c.blockheight"
4777- ", t.rawtx"
4778- ", c.input_num"
4779- ", c.blockheight - t.blockheight + 1 AS depth"
4780- ", t.id as txid "
4781- "FROM channeltxs c "
4782- "JOIN transactions t ON t.id = c.transaction_id "
4783- "WHERE c.channel_id = ? "
4784- "ORDER BY c.id ASC;" ));
4785- db_bind_int (stmt , channel_id );
4786- db_query_prepared (stmt );
4787-
4788- while (db_step (stmt )) {
4789- count ++ ;
4790- tal_resize (& res , count );
4791-
4792- res [count - 1 ].channel_id = channel_id ;
4793- res [count - 1 ].type = db_col_int (stmt , "c.type" );
4794- res [count - 1 ].blockheight = db_col_int (stmt , "c.blockheight" );
4795- res [count - 1 ].tx = db_col_tx (ctx , stmt , "t.rawtx" );
4796- res [count - 1 ].input_num = db_col_int (stmt , "c.input_num" );
4797- res [count - 1 ].depth = db_col_int (stmt , "depth" );
4798- db_col_txid (stmt , "txid" , & res [count - 1 ].txid );
4799- }
4800- tal_free (stmt );
4801- return res ;
4802- }
4803-
48044748struct bitcoin_tx * wallet_get_funding_spend (const tal_t * ctx ,
48054749 struct wallet * w ,
48064750 u64 channel_id ,
0 commit comments