diff --git a/core/src/aggregator.rs b/core/src/aggregator.rs index 2ecdb821..280cc847 100644 --- a/core/src/aggregator.rs +++ b/core/src/aggregator.rs @@ -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. @@ -287,7 +288,7 @@ impl Aggregator { evm_address: EVMAddress, agg_nonce: MuSigAggNonce, partial_sigs: Vec, - ) -> Result { + ) -> Result<(String, Txid), BridgeError> { let agg_move_tx_final_sig = self.aggregate_move_partial_sigs( deposit_outpoint, &evm_address, @@ -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)) } } @@ -352,7 +354,7 @@ impl AggregatorServer for Aggregator { evm_address: EVMAddress, agg_nonce: MuSigAggNonce, partial_sigs: Vec, - ) -> Result { + ) -> Result<(String, Txid), BridgeError> { self.aggregate_move_tx_sigs( deposit_outpoint, recovery_taproot_address, diff --git a/core/src/traits/rpc.rs b/core/src/traits/rpc.rs index 0585f892..79fd7db5 100644 --- a/core/src/traits/rpc.rs +++ b/core/src/traits/rpc.rs @@ -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; @@ -128,5 +128,5 @@ pub trait Aggregator { evm_address: EVMAddress, agg_nonce: MuSigAggNonce, partial_sigs: Vec, - ) -> Result; + ) -> Result<(String, Txid), BridgeError>; } diff --git a/core/tests/common.rs b/core/tests/common.rs index 995a8fd7..e8431822 100644 --- a/core/tests/common.rs +++ b/core/tests/common.rs @@ -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; @@ -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, @@ -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()); @@ -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; @@ -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, @@ -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, @@ -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());