diff --git a/core/src/builder/sighash.rs b/core/src/builder/sighash.rs index 7fe9767a..0bcdf8e6 100644 --- a/core/src/builder/sighash.rs +++ b/core/src/builder/sighash.rs @@ -20,6 +20,7 @@ pub fn create_nofn_sighash_stream( // Collect kickoff transactions. let kickoff_txs = collect_kickoff_txs(db, config.clone(), nofn_xonly_pk, evm_address).await?; + let mut wcp_txs = Vec::new(); for tx in kickoff_txs { let kickoff_utxo = UTXO { outpoint: OutPoint { @@ -28,7 +29,7 @@ pub fn create_nofn_sighash_stream( }, txout: tx.output[0].clone() }; - let mut tx_handler = builder::transaction::create_watchtower_challenge_page_txhandler( + let mut watchtower_challenge_page_tx_handler = builder::transaction::create_watchtower_challenge_page_txhandler( &kickoff_utxo, nofn_xonly_pk, config.bridge_amount_sats, @@ -36,7 +37,23 @@ pub fn create_nofn_sighash_stream( config.network, ); - yield Actor::convert_tx_to_sighash_script_spend(&mut tx_handler, 0, 0)?; + yield Actor::convert_tx_to_sighash_script_spend(&mut watchtower_challenge_page_tx_handler, 0, 0)?; + wcp_txs.push(watchtower_challenge_page_tx_handler); + } + + for watchtower in 0..config.num_watchtowers { + let utxo = UTXO { outpoint: OutPoint { + txid: wcp_txs[watchtower].tx.compute_txid(), + vout: watchtower as u32 + }, txout: wcp_txs[watchtower].tx.output[watchtower].clone() + }; + let mut watchtower_challenge_page_tx_2_handler = builder::transaction::create_watchtower_challenge_page_2_txhandler( + utxo, + nofn_xonly_pk, + config.network, + ); + + yield Actor::convert_tx_to_sighash_script_spend(&mut watchtower_challenge_page_tx_2_handler, 0, 0)?; } // First iterate over operators @@ -69,6 +86,7 @@ async fn collect_kickoff_txs( time_tx_outpoint, nofn_xonly_pk, user_evm_address, + config.network, ); kickoff_txs.push(kickoff_tx); diff --git a/core/src/builder/transaction.rs b/core/src/builder/transaction.rs index cc0c9e3d..45302663 100644 --- a/core/src/builder/transaction.rs +++ b/core/src/builder/transaction.rs @@ -4,6 +4,7 @@ //! transactions. use super::address::create_taproot_address; +use super::script; use crate::builder; use crate::utils::SECP; use crate::{utils, EVMAddress, UTXO}; @@ -379,6 +380,34 @@ pub fn create_watchtower_challenge_page_txhandler( } } +pub fn create_watchtower_challenge_page_2_txhandler( + wcp_utxo: UTXO, + nofn_xonly_pk: XOnlyPublicKey, + network: bitcoin::Network, +) -> TxHandler { + let tx_ins = create_tx_ins(vec![wcp_utxo.outpoint]); + + let nofn_1week = builder::script::generate_relative_timelock_script(nofn_xonly_pk, 7 * 24 * 6); + let (nofn_or_nofn_1week, _) = + builder::address::create_taproot_address(&[nofn_1week], Some(nofn_xonly_pk), network); + // TODO: This also needs to include nofn + operator preimage hash + let script_pubkey = nofn_or_nofn_1week.script_pubkey(); + + let tx_outs = vec![TxOut { + value: wcp_utxo.txout.value - MOVE_TX_MIN_RELAY_FEE, + script_pubkey, + }]; + + let wcptx2 = create_btc_tx(tx_ins, tx_outs); + + TxHandler { + tx: wcptx2, + prevouts: vec![wcp_utxo.txout.clone()], + scripts: vec![vec![]], + taproot_spend_infos: vec![], + } +} + pub fn create_slash_or_take_tx( deposit_outpoint: OutPoint, kickoff_utxo: UTXO,