@ -1,34 +1,23 @@
use crate ::{
use crate ::database ::Database ;
bitcoin ,
use crate ::execution_params ::ExecutionParams ;
database ::Database ,
use crate ::network ::{ peer_tracker , spot_price } ;
execution_params ::ExecutionParams ,
use crate ::protocol ::alice ::TransferProof ;
monero ,
use crate ::{ bitcoin , monero } ;
network ::{
peer_tracker ::{ self , PeerTracker } ,
spot_price ,
spot_price ::{ SpotPriceRequest , SpotPriceResponse } ,
} ,
protocol ::{ alice ::TransferProof , bob } ,
} ;
use anyhow ::{ anyhow , Error , Result } ;
use anyhow ::{ anyhow , Error , Result } ;
pub use execution_setup ::{ Message0 , Message2 , Message4 } ;
use libp2p ::core ::Multiaddr ;
use libp2p ::{
use libp2p ::request_response ::{ RequestResponseMessage , ResponseChannel } ;
core ::Multiaddr ,
use libp2p ::{ NetworkBehaviour , PeerId } ;
request_response ::{ RequestResponseMessage , ResponseChannel } ,
NetworkBehaviour , PeerId ,
} ;
use std ::sync ::Arc ;
use std ::sync ::Arc ;
use tracing ::debug ;
use tracing ::debug ;
use uuid ::Uuid ;
use uuid ::Uuid ;
pub use self ::{
pub use self ::cancel ::cancel ;
cancel ::cancel ,
pub use self ::encrypted_signature ::EncryptedSignature ;
encrypted_signature ::EncryptedSignature ,
pub use self ::event_loop ::{ EventLoop , EventLoopHandle } ;
event_loop ::{ EventLoop , EventLoopHandle } ,
pub use self ::execution_setup ::{ Message0 , Message2 , Message4 } ;
refund ::refund ,
pub use self ::refund ::refund ;
state ::* ,
pub use self ::state ::* ;
swap ::{ run , run_until } ,
pub use self ::swap ::{ run , run_until } ;
} ;
pub mod cancel ;
pub mod cancel ;
mod encrypted_signature ;
mod encrypted_signature ;
@ -41,7 +30,7 @@ mod transfer_proof;
pub struct Swap {
pub struct Swap {
pub state : BobState ,
pub state : BobState ,
pub event_loop_handle : bob:: EventLoopHandle,
pub event_loop_handle : EventLoopHandle,
pub db : Database ,
pub db : Database ,
pub bitcoin_wallet : Arc < bitcoin ::Wallet > ,
pub bitcoin_wallet : Arc < bitcoin ::Wallet > ,
pub monero_wallet : Arc < monero ::Wallet > ,
pub monero_wallet : Arc < monero ::Wallet > ,
@ -60,7 +49,7 @@ pub struct Builder {
init_params : InitParams ,
init_params : InitParams ,
execution_params : ExecutionParams ,
execution_params : ExecutionParams ,
event_loop_handle : bob:: EventLoopHandle,
event_loop_handle : EventLoopHandle,
receive_monero_address : ::monero ::Address ,
receive_monero_address : ::monero ::Address ,
}
}
@ -78,7 +67,7 @@ impl Builder {
bitcoin_wallet : Arc < bitcoin ::Wallet > ,
bitcoin_wallet : Arc < bitcoin ::Wallet > ,
monero_wallet : Arc < monero ::Wallet > ,
monero_wallet : Arc < monero ::Wallet > ,
execution_params : ExecutionParams ,
execution_params : ExecutionParams ,
event_loop_handle : bob:: EventLoopHandle,
event_loop_handle : EventLoopHandle,
receive_monero_address : ::monero ::Address ,
receive_monero_address : ::monero ::Address ,
) -> Self {
) -> Self {
Self {
Self {
@ -100,7 +89,7 @@ impl Builder {
}
}
}
}
pub fn build ( self ) -> Result < bob:: Swap> {
pub fn build ( self ) -> Result < Swap> {
let state = match self . init_params {
let state = match self . init_params {
InitParams ::New { btc_amount } = > BobState ::Started { btc_amount } ,
InitParams ::New { btc_amount } = > BobState ::Started { btc_amount } ,
InitParams ::None = > self . db . get_state ( self . swap_id ) ? . try_into_bob ( ) ? . into ( ) ,
InitParams ::None = > self . db . get_state ( self . swap_id ) ? . try_into_bob ( ) ? . into ( ) ,
@ -122,7 +111,7 @@ impl Builder {
#[ derive(Debug) ]
#[ derive(Debug) ]
pub enum OutEvent {
pub enum OutEvent {
ConnectionEstablished ( PeerId ) ,
ConnectionEstablished ( PeerId ) ,
SpotPriceReceived ( SpotPrice Response) ,
SpotPriceReceived ( spot_price:: Response) ,
ExecutionSetupDone ( Result < Box < State2 > > ) ,
ExecutionSetupDone ( Result < Box < State2 > > ) ,
TransferProof {
TransferProof {
msg : Box < TransferProof > ,
msg : Box < TransferProof > ,
@ -216,7 +205,7 @@ impl From<encrypted_signature::OutEvent> for OutEvent {
#[ behaviour(out_event = " OutEvent " , event_process = false) ]
#[ behaviour(out_event = " OutEvent " , event_process = false) ]
#[ allow(missing_debug_implementations) ]
#[ allow(missing_debug_implementations) ]
pub struct Behaviour {
pub struct Behaviour {
pt : PeerTracke r,
pt : peer_tracker::Behaviou r,
spot_price : spot_price ::Behaviour ,
spot_price : spot_price ::Behaviour ,
execution_setup : execution_setup ::Behaviour ,
execution_setup : execution_setup ::Behaviour ,
transfer_proof : transfer_proof ::Behaviour ,
transfer_proof : transfer_proof ::Behaviour ,
@ -236,7 +225,7 @@ impl Default for Behaviour {
}
}
impl Behaviour {
impl Behaviour {
pub fn request_spot_price ( & mut self , alice : PeerId , request : SpotPrice Request) {
pub fn request_spot_price ( & mut self , alice : PeerId , request : spot_price:: Request) {
let _ = self . spot_price . send_request ( & alice , request ) ;
let _ = self . spot_price . send_request ( & alice , request ) ;
}
}