Move init event loop in bob::SwapFactory

This commit is contained in:
Franck Royer 2021-01-19 14:22:09 +11:00
parent 96b1b18037
commit 3c68026cfe
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4

View File

@ -107,12 +107,7 @@ impl SwapFactory {
) )
.await?; .await?;
let (event_loop, event_loop_handle) = init_bob_event_loop( let (event_loop, event_loop_handle) = self.init_event_loop()?;
self.identity.clone(),
self.peer_id.clone(),
self.alice_connect_peer_id.clone(),
self.alice_connect_address.clone(),
)?;
let db = Database::open(self.db_path.as_path())?; let db = Database::open(self.db_path.as_path())?;
@ -142,12 +137,7 @@ impl SwapFactory {
) )
}; };
let (event_loop, event_loop_handle) = init_bob_event_loop( let (event_loop, event_loop_handle) = self.init_event_loop()?;
self.identity.clone(),
self.peer_id.clone(),
self.alice_connect_peer_id.clone(),
self.alice_connect_address.clone(),
)?;
Ok(( Ok((
Swap { Swap {
@ -161,6 +151,21 @@ impl SwapFactory {
event_loop, event_loop,
)) ))
} }
fn init_event_loop(
&self,
) -> Result<(bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle)> {
let bob_behaviour = bob::Behaviour::default();
let bob_transport = build(self.identity.clone())?;
bob::event_loop::EventLoop::new(
bob_transport,
bob_behaviour,
self.peer_id.clone(),
self.alice_connect_peer_id.clone(),
self.alice_connect_address.clone(),
)
}
} }
async fn init_bob_state( async fn init_bob_state(
@ -188,24 +193,6 @@ async fn init_bob_state(
Ok(BobState::Started { state0, amounts }) Ok(BobState::Started { state0, amounts })
} }
fn init_bob_event_loop(
identity: Keypair,
peer_id: PeerId,
alice_peer_id: PeerId,
alice_addr: Multiaddr,
) -> Result<(bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle)> {
let bob_behaviour = bob::Behaviour::default();
let bob_transport = build(identity)?;
bob::event_loop::EventLoop::new(
bob_transport,
bob_behaviour,
peer_id,
alice_peer_id,
alice_addr,
)
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum OutEvent { pub enum OutEvent {
ConnectionEstablished(PeerId), ConnectionEstablished(PeerId),