Make init_state associated to bob::SwapFactory

This commit is contained in:
Franck Royer 2021-01-19 14:39:30 +11:00
parent f0e6e45d56
commit 3bc76a91c6
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4

View File

@ -93,12 +93,8 @@ 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,
)
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,12 +156,11 @@ impl SwapFactory {
self.alice_address.clone(),
)
}
}
async fn init_bob_state(
async fn make_initial_state(
&self,
btc_to_swap: bitcoin::Amount,
xmr_to_swap: monero::Amount,
bob_btc_wallet: Arc<bitcoin::Wallet>,
config: Config,
) -> Result<BobState> {
let amounts = SwapAmounts {
@ -173,7 +168,7 @@ async fn init_bob_state(
xmr: xmr_to_swap,
};
let refund_address = bob_btc_wallet.new_address().await?;
let refund_address = self.bitcoin_wallet.new_address().await?;
let state0 = bob::State0::new(
&mut OsRng,
btc_to_swap,
@ -186,6 +181,7 @@ async fn init_bob_state(
Ok(BobState::Started { state0, amounts })
}
}
#[derive(Debug, Clone)]
pub enum OutEvent {