Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge removed code duplication into ekrem/new-architecture #228

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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