From 3bc76a91c610d971ad5fb943ae1a287df9fd399e Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 19 Jan 2021 14:39:30 +1100 Subject: [PATCH] Make `init_state` associated to `bob::SwapFactory` --- swap/src/protocol/bob.rs | 54 +++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/swap/src/protocol/bob.rs b/swap/src/protocol/bob.rs index 5780c17c..a9f72a86 100644 --- a/swap/src/protocol/bob.rs +++ b/swap/src/protocol/bob.rs @@ -93,13 +93,9 @@ impl SwapFactory { swap_amounts: SwapAmounts, config: Config, ) -> Result<(bob::Swap, bob::EventLoop)> { - let initial_state = init_bob_state( - swap_amounts.btc, - swap_amounts.xmr, - self.bitcoin_wallet.clone(), - config, - ) - .await?; + let initial_state = self + .make_initial_state(swap_amounts.btc, swap_amounts.xmr, config) + .await?; let (event_loop, event_loop_handle) = self.init_event_loop()?; @@ -160,31 +156,31 @@ impl SwapFactory { self.alice_address.clone(), ) } -} -async fn init_bob_state( - btc_to_swap: bitcoin::Amount, - xmr_to_swap: monero::Amount, - bob_btc_wallet: Arc, - config: Config, -) -> Result { - let amounts = SwapAmounts { - btc: btc_to_swap, - xmr: xmr_to_swap, - }; + async fn make_initial_state( + &self, + btc_to_swap: bitcoin::Amount, + xmr_to_swap: monero::Amount, + config: Config, + ) -> Result { + let amounts = SwapAmounts { + btc: btc_to_swap, + xmr: xmr_to_swap, + }; - let refund_address = bob_btc_wallet.new_address().await?; - let state0 = bob::State0::new( - &mut OsRng, - btc_to_swap, - xmr_to_swap, - config.bitcoin_cancel_timelock, - config.bitcoin_punish_timelock, - refund_address, - config.monero_finality_confirmations, - ); + let refund_address = self.bitcoin_wallet.new_address().await?; + let state0 = bob::State0::new( + &mut OsRng, + btc_to_swap, + xmr_to_swap, + config.bitcoin_cancel_timelock, + config.bitcoin_punish_timelock, + refund_address, + config.monero_finality_confirmations, + ); - Ok(BobState::Started { state0, amounts }) + Ok(BobState::Started { state0, amounts }) + } } #[derive(Debug, Clone)]