|
|
|
@ -1,10 +1,7 @@
|
|
|
|
|
use crate::database::Database;
|
|
|
|
|
use crate::execution_params::ExecutionParams;
|
|
|
|
|
use crate::network::peer_tracker::{self, PeerTracker};
|
|
|
|
|
use crate::network::spot_price;
|
|
|
|
|
use crate::network::spot_price::{SpotPriceRequest, SpotPriceResponse};
|
|
|
|
|
use crate::network::{peer_tracker, spot_price};
|
|
|
|
|
use crate::protocol::alice::TransferProof;
|
|
|
|
|
use crate::protocol::bob;
|
|
|
|
|
use crate::{bitcoin, monero};
|
|
|
|
|
use anyhow::{anyhow, Error, Result};
|
|
|
|
|
use libp2p::core::Multiaddr;
|
|
|
|
@ -33,7 +30,7 @@ mod transfer_proof;
|
|
|
|
|
|
|
|
|
|
pub struct Swap {
|
|
|
|
|
pub state: BobState,
|
|
|
|
|
pub event_loop_handle: bob::EventLoopHandle,
|
|
|
|
|
pub event_loop_handle: EventLoopHandle,
|
|
|
|
|
pub db: Database,
|
|
|
|
|
pub bitcoin_wallet: Arc<bitcoin::Wallet>,
|
|
|
|
|
pub monero_wallet: Arc<monero::Wallet>,
|
|
|
|
@ -52,7 +49,7 @@ pub struct Builder {
|
|
|
|
|
init_params: InitParams,
|
|
|
|
|
execution_params: ExecutionParams,
|
|
|
|
|
|
|
|
|
|
event_loop_handle: bob::EventLoopHandle,
|
|
|
|
|
event_loop_handle: EventLoopHandle,
|
|
|
|
|
|
|
|
|
|
receive_monero_address: ::monero::Address,
|
|
|
|
|
}
|
|
|
|
@ -70,7 +67,7 @@ impl Builder {
|
|
|
|
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
|
|
|
|
monero_wallet: Arc<monero::Wallet>,
|
|
|
|
|
execution_params: ExecutionParams,
|
|
|
|
|
event_loop_handle: bob::EventLoopHandle,
|
|
|
|
|
event_loop_handle: EventLoopHandle,
|
|
|
|
|
receive_monero_address: ::monero::Address,
|
|
|
|
|
) -> Self {
|
|
|
|
|
Self {
|
|
|
|
@ -92,7 +89,7 @@ impl Builder {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn build(self) -> Result<bob::Swap> {
|
|
|
|
|
pub fn build(self) -> Result<Swap> {
|
|
|
|
|
let state = match self.init_params {
|
|
|
|
|
InitParams::New { btc_amount } => BobState::Started { btc_amount },
|
|
|
|
|
InitParams::None => self.db.get_state(self.swap_id)?.try_into_bob()?.into(),
|
|
|
|
@ -114,7 +111,7 @@ impl Builder {
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum OutEvent {
|
|
|
|
|
ConnectionEstablished(PeerId),
|
|
|
|
|
SpotPriceReceived(SpotPriceResponse),
|
|
|
|
|
SpotPriceReceived(spot_price::Response),
|
|
|
|
|
ExecutionSetupDone(Result<Box<State2>>),
|
|
|
|
|
TransferProof {
|
|
|
|
|
msg: Box<TransferProof>,
|
|
|
|
@ -208,7 +205,7 @@ impl From<encrypted_signature::OutEvent> for OutEvent {
|
|
|
|
|
#[behaviour(out_event = "OutEvent", event_process = false)]
|
|
|
|
|
#[allow(missing_debug_implementations)]
|
|
|
|
|
pub struct Behaviour {
|
|
|
|
|
pt: PeerTracker,
|
|
|
|
|
pt: peer_tracker::Behaviour,
|
|
|
|
|
spot_price: spot_price::Behaviour,
|
|
|
|
|
execution_setup: execution_setup::Behaviour,
|
|
|
|
|
transfer_proof: transfer_proof::Behaviour,
|
|
|
|
@ -228,7 +225,7 @@ impl Default for Behaviour {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Behaviour {
|
|
|
|
|
pub fn request_spot_price(&mut self, alice: PeerId, request: SpotPriceRequest) {
|
|
|
|
|
pub fn request_spot_price(&mut self, alice: PeerId, request: spot_price::Request) {
|
|
|
|
|
let _ = self.spot_price.send_request(&alice, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|