@@ -4659,9 +4659,10 @@ struct bitcoin_txid *wallet_transactions_by_height(const tal_t *ctx,
46594659 return txids ;
46604660}
46614661
4662- void wallet_channeltxs_add (struct wallet * w , struct channel * chan ,
4663- const int type , const struct bitcoin_txid * txid ,
4664- const u32 input_num , const u32 blockheight )
4662+ void wallet_insert_funding_spend (struct wallet * w ,
4663+ const struct channel * chan ,
4664+ const struct bitcoin_txid * txid ,
4665+ const u32 input_num , const u32 blockheight )
46654666{
46664667 struct db_stmt * stmt ;
46674668 stmt = db_prepare_v2 (w -> db , SQL ("INSERT INTO channeltxs ("
@@ -4672,72 +4673,15 @@ void wallet_channeltxs_add(struct wallet *w, struct channel *chan,
46724673 ", blockheight"
46734674 ") VALUES (?, ?, ?, ?, ?);" ));
46744675 db_bind_int (stmt , chan -> dbid );
4675- db_bind_int (stmt , type );
4676- db_bind_sha256 (stmt , & txid -> shad .sha );
4676+ /* FIXME: This is WIRE_ONCHAIND_INIT, accidentally leaked into db! */
4677+ db_bind_int (stmt , 5001 );
4678+ db_bind_txid (stmt , txid );
46774679 db_bind_int (stmt , input_num );
46784680 db_bind_int (stmt , blockheight );
46794681
46804682 db_exec_prepared_v2 (take (stmt ));
46814683}
46824684
4683- u32 * wallet_onchaind_channels (const tal_t * ctx , struct wallet * w )
4684- {
4685- struct db_stmt * stmt ;
4686- size_t count = 0 ;
4687- u32 * channel_ids = tal_arr (ctx , u32 , 0 );
4688- stmt = db_prepare_v2 (
4689- w -> db ,
4690- SQL ("SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" ));
4691- db_bind_int (stmt , WIRE_ONCHAIND_INIT );
4692- db_query_prepared (stmt );
4693-
4694- while (db_step (stmt )) {
4695- count ++ ;
4696- tal_resize (& channel_ids , count );
4697- channel_ids [count - 1 ] = db_col_u64 (stmt , "DISTINCT(channel_id)" );
4698- }
4699- tal_free (stmt );
4700-
4701- return channel_ids ;
4702- }
4703-
4704- struct channeltx * wallet_channeltxs_get (const tal_t * ctx , struct wallet * w ,
4705- u32 channel_id )
4706- {
4707- struct db_stmt * stmt ;
4708- size_t count = 0 ;
4709- struct channeltx * res = tal_arr (ctx , struct channeltx , 0 );
4710- stmt = db_prepare_v2 (
4711- w -> db , SQL ("SELECT"
4712- " c.type"
4713- ", c.blockheight"
4714- ", t.rawtx"
4715- ", c.input_num"
4716- ", c.blockheight - t.blockheight + 1 AS depth"
4717- ", t.id as txid "
4718- "FROM channeltxs c "
4719- "JOIN transactions t ON t.id = c.transaction_id "
4720- "WHERE c.channel_id = ? "
4721- "ORDER BY c.id ASC;" ));
4722- db_bind_int (stmt , channel_id );
4723- db_query_prepared (stmt );
4724-
4725- while (db_step (stmt )) {
4726- count ++ ;
4727- tal_resize (& res , count );
4728-
4729- res [count - 1 ].channel_id = channel_id ;
4730- res [count - 1 ].type = db_col_int (stmt , "c.type" );
4731- res [count - 1 ].blockheight = db_col_int (stmt , "c.blockheight" );
4732- res [count - 1 ].tx = db_col_tx (ctx , stmt , "t.rawtx" );
4733- res [count - 1 ].input_num = db_col_int (stmt , "c.input_num" );
4734- res [count - 1 ].depth = db_col_int (stmt , "depth" );
4735- db_col_txid (stmt , "txid" , & res [count - 1 ].txid );
4736- }
4737- tal_free (stmt );
4738- return res ;
4739- }
4740-
47414685struct bitcoin_tx * wallet_get_funding_spend (const tal_t * ctx ,
47424686 struct wallet * w ,
47434687 u64 channel_id ,
0 commit comments