Skip to content

Commit

Permalink
sighash: Add create_watchtower_challenge_page_2_txhandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Dec 20, 2024
1 parent 33f6cae commit 903552e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
22 changes: 20 additions & 2 deletions core/src/builder/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,15 +29,31 @@ 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,
config.num_watchtowers as u32,
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
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions core/src/builder/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 903552e

Please sign in to comment.