From cb163aef8224141bd51ad4fe1be95ad967f3bb9f Mon Sep 17 00:00:00 2001 From: wthrajat Date: Wed, 4 Sep 2024 22:44:47 +0530 Subject: [PATCH] separate sender and receiver tx info Signed-off-by: wthrajat --- src/taker/routines.rs | 70 +++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/taker/routines.rs b/src/taker/routines.rs index d5aef0e8..64b487d1 100644 --- a/src/taker/routines.rs +++ b/src/taker/routines.rs @@ -92,23 +92,12 @@ pub fn handshake_maker(socket: &mut TcpStream) -> Result<(), TakerError> { } } -/// Request signatures for sender side of the hop. Attempt once. -pub(crate) fn req_sigs_for_sender_once( - socket: &mut TcpStream, - outgoing_swapcoins: &[S], +fn build_contract_tx_info_for_sender( maker_multisig_nonces: &[SecretKey], maker_hashlock_nonces: &[SecretKey], - locktime: u16, -) -> Result { - log::info!("Connecting to {}", socket.peer_addr()?); - handshake_maker(socket)?; - log::info!( - "===> Sending ReqContractSigsForSender to {}", - socket.peer_addr()? - ); - - // TODO: Take this construction out of function body. - let txs_info = maker_multisig_nonces + outgoing_swapcoins: &[S], +) -> Vec { + maker_multisig_nonces .iter() .zip(maker_hashlock_nonces.iter()) .zip(outgoing_swapcoins.iter()) @@ -124,7 +113,30 @@ pub(crate) fn req_sigs_for_sender_once( } }, ) - .collect::>(); + .collect() +} + +/// Request signatures for sender side of the hop. Attempt once. +pub(crate) fn req_sigs_for_sender_once( + socket: &mut TcpStream, + outgoing_swapcoins: &[S], + maker_multisig_nonces: &[SecretKey], + maker_hashlock_nonces: &[SecretKey], + locktime: u16, +) -> Result { + log::info!("Connecting to {}", socket.peer_addr()?); + handshake_maker(socket)?; + log::info!( + "===> Sending ReqContractSigsForSender to {}", + socket.peer_addr()? + ); + + // TODO: Take this construction out of function body. + let txs_info = build_contract_tx_info_for_sender( + maker_multisig_nonces, + maker_hashlock_nonces, + outgoing_swapcoins, + ); send_message( socket, @@ -172,6 +184,20 @@ pub(crate) fn req_sigs_for_sender_once( Ok(contract_sigs_for_sender) } +fn build_contract_tx_info_for_recvr( + incoming_swapcoins: &[S], + receivers_contract_txes: &[Transaction], +) -> Vec { + incoming_swapcoins + .iter() + .zip(receivers_contract_txes.iter()) + .map(|(swapcoin, receivers_contract_tx)| ContractTxInfoForRecvr { + multisig_redeemscript: swapcoin.get_multisig_redeemscript(), + contract_tx: receivers_contract_tx.clone(), + }) + .collect() +} + /// Request signatures for receiver side of the hop. Attempt once. pub(crate) fn req_sigs_for_recvr_once( socket: &mut TcpStream, @@ -181,19 +207,11 @@ pub(crate) fn req_sigs_for_recvr_once( log::info!("Connecting to {}", socket.peer_addr()?); handshake_maker(socket)?; + let txs = build_contract_tx_info_for_recvr(incoming_swapcoins, receivers_contract_txes); // TODO: Take the message construction out of function body. send_message( socket, - &TakerToMakerMessage::ReqContractSigsForRecvr(ReqContractSigsForRecvr { - txs: incoming_swapcoins - .iter() - .zip(receivers_contract_txes.iter()) - .map(|(swapcoin, receivers_contract_tx)| ContractTxInfoForRecvr { - multisig_redeemscript: swapcoin.get_multisig_redeemscript(), - contract_tx: receivers_contract_tx.clone(), - }) - .collect::>(), - }), + &TakerToMakerMessage::ReqContractSigsForRecvr(ReqContractSigsForRecvr { txs }), )?; let msg_bytes = read_message(socket)?;