Skip to content

Commit

Permalink
Remove code duplication (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaymak authored Aug 21, 2024
1 parent f843942 commit 70fa7c3
Showing 1 changed file with 27 additions and 53 deletions.
80 changes: 27 additions & 53 deletions core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::errors::BridgeError;
use crate::extended_rpc::ExtendedRpc;
use crate::musig2::{self, MuSigAggNonce, MuSigPartialSignature, MuSigPubNonce};
use crate::traits::rpc::VerifierRpcServer;
use crate::transaction_builder::TransactionBuilder;
use crate::transaction_builder::{TransactionBuilder, TxHandler};
use crate::{utils, EVMAddress, UTXO};
use ::musig2::secp::Point;
use bitcoin::address::NetworkUnchecked;
Expand Down Expand Up @@ -165,14 +165,10 @@ where
Ok(vec![])
}

/// verify burn txs are signed by verifiers
/// sign operator_takes_txs
async fn burn_txs_signed_rpc(
async fn create_deposit_details(
&self,
deposit_outpoint: OutPoint,
_burn_sigs: Vec<schnorr::Signature>,
) -> Result<Vec<MuSigPartialSignature>, BridgeError> {
// TODO: Verify burn txs are signed by verifiers
) -> Result<(Vec<UTXO>, TxHandler, TxHandler, OutPoint), BridgeError> {
let kickoff_utxos = self
.db
.get_kickoff_utxos(deposit_outpoint)
Expand Down Expand Up @@ -218,6 +214,24 @@ where
txid: move_reveal_tx_handler.tx.compute_txid(),
vout: 0,
};
Ok((
kickoff_utxos,
move_commit_tx_handler,
move_reveal_tx_handler,
bridge_fund_outpoint,
))
}

/// verify burn txs are signed by verifiers
/// sign operator_takes_txs
async fn burn_txs_signed_rpc(
&self,
deposit_outpoint: OutPoint,
_burn_sigs: Vec<schnorr::Signature>,
) -> Result<Vec<MuSigPartialSignature>, BridgeError> {
// TODO: Verify burn txs are signed by verifiers
let (kickoff_utxos, _, _, bridge_fund_outpoint) =
self.create_deposit_details(deposit_outpoint).await?;

let operator_takes_sighashes = kickoff_utxos
.iter()
Expand Down Expand Up @@ -284,52 +298,12 @@ where
deposit_outpoint: OutPoint,
operator_take_sigs: Vec<schnorr::Signature>,
) -> Result<(MuSigPartialSignature, MuSigPartialSignature), BridgeError> {
// TODO: remove code duplication
let kickoff_utxos = self
.db
.get_kickoff_utxos(deposit_outpoint)
.await?
.ok_or(BridgeError::KickoffOutpointsNotFound)?;

let kickoff_outpoints = kickoff_utxos
.iter()
.map(|utxo| utxo.outpoint)
.collect::<Vec<_>>();

let (recovery_taproot_address, evm_address) = self
.db
.get_deposit_info(deposit_outpoint)
.await?
.ok_or(BridgeError::DepositInfoNotFound)?;

let mut move_commit_tx_handler = TransactionBuilder::create_move_commit_tx(
deposit_outpoint,
&evm_address,
&recovery_taproot_address,
200, // TODO: Fix this
&self.nofn_xonly_pk,
&kickoff_outpoints,
201, // TODO: Fix this
self.config.network,
);

let mut move_reveal_tx_handler = TransactionBuilder::create_move_reveal_tx(
OutPoint {
txid: move_commit_tx_handler.tx.compute_txid(),
vout: 0,
},
&evm_address,
&recovery_taproot_address,
&self.nofn_xonly_pk,
&kickoff_outpoints,
201, // TODO: Fix this
self.config.network,
);

let bridge_fund_outpoint = OutPoint {
txid: move_reveal_tx_handler.tx.compute_txid(),
vout: 0,
};
let (
kickoff_utxos,
mut move_commit_tx_handler,
mut move_reveal_tx_handler,
bridge_fund_outpoint,
) = self.create_deposit_details(deposit_outpoint).await?;

let _ = kickoff_utxos
.iter()
Expand Down

0 comments on commit 70fa7c3

Please sign in to comment.