Skip to content

Commit

Permalink
Aggregator returns move_txid
Browse files Browse the repository at this point in the history
  • Loading branch information
ekrembal committed Sep 4, 2024
1 parent 7bc56e0 commit fc04c31
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 7 additions & 5 deletions core/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use crate::{
EVMAddress, UTXO,
};
use async_trait::async_trait;
use bitcoin::hashes::Hash;
use bitcoin::{address::NetworkUnchecked, Address, OutPoint, Transaction};
use bitcoin::{hashes::Hash, Txid};
use bitcoin::{address::NetworkUnchecked, Address, OutPoint};
use bitcoincore_rpc::RawTx;
use secp256k1::schnorr;

/// Aggregator struct.
Expand Down Expand Up @@ -287,7 +288,7 @@ impl Aggregator {
evm_address: EVMAddress,
agg_nonce: MuSigAggNonce,
partial_sigs: Vec<MuSigPartialSignature>,
) -> Result<Transaction, BridgeError> {
) -> Result<(String, Txid), BridgeError> {
let agg_move_tx_final_sig = self.aggregate_move_partial_sigs(
deposit_outpoint,
&evm_address,
Expand All @@ -310,7 +311,8 @@ impl Aggregator {
let move_tx_witness_elements = vec![move_tx_sig.serialize().to_vec()];
handle_taproot_witness_new(&mut move_tx_handler, &move_tx_witness_elements, 0, Some(0))?;

Ok(move_tx_handler.tx)
let txid = move_tx_handler.tx.compute_txid();
Ok((move_tx_handler.tx.raw_hex(), txid))
}
}

Expand Down Expand Up @@ -352,7 +354,7 @@ impl AggregatorServer for Aggregator {
evm_address: EVMAddress,
agg_nonce: MuSigAggNonce,
partial_sigs: Vec<MuSigPartialSignature>,
) -> Result<Transaction, BridgeError> {
) -> Result<(String, Txid), BridgeError> {
self.aggregate_move_tx_sigs(
deposit_outpoint,
recovery_taproot_address,
Expand Down
4 changes: 2 additions & 2 deletions core/src/traits/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::musig2::{MuSigAggNonce, MuSigPartialSignature, MuSigPubNonce};
use crate::UTXO;
use crate::{errors::BridgeError, EVMAddress};
use bitcoin::address::NetworkUnchecked;
use bitcoin::{Address, OutPoint, Transaction, TxOut, Txid};
use bitcoin::{Address, OutPoint, TxOut, Txid};
use jsonrpsee::proc_macros::rpc;
use secp256k1::schnorr;

Expand Down Expand Up @@ -128,5 +128,5 @@ pub trait Aggregator {
evm_address: EVMAddress,
agg_nonce: MuSigAggNonce,
partial_sigs: Vec<MuSigPartialSignature>,
) -> Result<Transaction, BridgeError>;
) -> Result<(String, Txid), BridgeError>;
}
12 changes: 9 additions & 3 deletions core/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// //! # Common utilities for tests

use bitcoin::consensus::encode::deserialize_hex;
use bitcoin::OutPoint;
use bitcoin::Transaction;
use clementine_core::actor::Actor;
use clementine_core::config::BridgeConfig;
use clementine_core::database::common::Database;
Expand Down Expand Up @@ -159,7 +161,7 @@ pub async fn run_single_deposit(

// aggreagte move_tx_partial_sigs

let move_tx = aggregator
let (move_tx, _) = aggregator
.0
.aggregate_move_tx_sigs_rpc(
deposit_outpoint,
Expand All @@ -170,6 +172,7 @@ pub async fn run_single_deposit(
)
.await
.unwrap();
let move_tx: Transaction = deserialize_hex(&move_tx).unwrap();
// tracing::debug!("Move tx: {:#?}", move_tx);
// tracing::debug!("Move tx_hex: {:?}", move_tx_handler.tx.raw_hex());
tracing::debug!("Move tx weight: {:?}", move_tx.weight());
Expand All @@ -180,6 +183,8 @@ pub async fn run_single_deposit(

#[cfg(test)]
mod tests {
use bitcoin::consensus::encode::deserialize_hex;
use bitcoin::Transaction;
use clementine_core::actor::Actor;
use clementine_core::database::common::Database;
use clementine_core::extended_rpc::ExtendedRpc;
Expand Down Expand Up @@ -432,7 +437,7 @@ mod tests {

// aggreagte move_tx_partial_sigs

let _move_tx = aggregator
let (_move_tx, _) = aggregator
.0
.aggregate_move_tx_sigs_rpc(
deposit_outpoint,
Expand All @@ -444,7 +449,7 @@ mod tests {
.await
.unwrap();

let move_tx_retry = aggregator
let (move_tx_retry, _) = aggregator
.0
.aggregate_move_tx_sigs_rpc(
deposit_outpoint,
Expand All @@ -456,6 +461,7 @@ mod tests {
.await
.unwrap();

let move_tx_retry: Transaction = deserialize_hex(&move_tx_retry).unwrap();
// tracing::debug!("Move tx: {:#?}", move_tx);
// tracing::debug!("Move tx_hex: {:?}", move_tx_handler.tx.raw_hex());
tracing::debug!("Move tx retry weight: {:?}", move_tx_retry.weight());
Expand Down

0 comments on commit fc04c31

Please sign in to comment.