From c0070f8fa7c0e94692b07d27f7dc95024a0a13b2 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Fri, 25 Jun 2021 13:40:33 +1000 Subject: [PATCH] Move files from `protocol` to appropriate module Some network and application specific code does not belong in the protocol module and was moved. Eventloop, recovery and the outside behaviour were moved to the respective application module because they are application specific. The `swap_setup` was moved into the network module because upon change both sides will have to be changed and should thus stay close together. --- swap/src/asb.rs | 11 +++++++++ swap/src/{protocol/alice => asb}/behaviour.rs | 13 ++++++----- .../src/{protocol/alice => asb}/event_loop.rs | 5 ++-- swap/src/{protocol/alice => asb}/recovery.rs | 0 .../alice => asb}/recovery/cancel.rs | 0 .../alice => asb}/recovery/punish.rs | 0 .../alice => asb}/recovery/redeem.rs | 0 .../alice => asb}/recovery/refund.rs | 0 .../alice => asb}/recovery/safely_abort.rs | 0 swap/src/bin/asb.rs | 17 +++++++------- swap/src/bin/swap.rs | 18 +++++++++------ swap/src/cli.rs | 9 ++++++++ swap/src/{protocol/bob => cli}/behaviour.rs | 7 +++--- swap/src/{protocol/bob => cli}/cancel.rs | 0 swap/src/{protocol/bob => cli}/event_loop.rs | 5 ++-- swap/src/{protocol/bob => cli}/refund.rs | 0 swap/src/network.rs | 2 ++ swap/src/network/alice.rs | 1 + swap/src/network/bob.rs | 1 + swap/src/network/encrypted_signature.rs | 10 ++++---- swap/src/network/quote.rs | 11 ++++----- swap/src/network/redial.rs | 6 ++--- swap/src/network/swap_setup.rs | 3 +++ .../swap_setup/alice.rs} | 18 +++++++-------- .../swap_setup/bob.rs} | 14 +++++------ swap/src/network/swarm.rs | 11 ++++----- swap/src/network/transfer_proof.rs | 11 ++++----- swap/src/protocol/alice.rs | 16 ++----------- swap/src/protocol/alice/swap.rs | 2 +- swap/src/protocol/bob.rs | 23 +++++++------------ swap/src/protocol/bob/swap.rs | 4 ++-- ..._refund_using_cancel_and_refund_command.rs | 11 +++++---- ...and_refund_command_timelock_not_expired.rs | 19 +++++++-------- ...fund_command_timelock_not_expired_force.rs | 13 ++++++----- .../alice_manually_punishes_after_bob_dead.rs | 7 +++--- ..._manually_redeems_after_enc_sig_learned.rs | 6 ++--- .../alice_punishes_after_restart_bob_dead.rs | 2 +- ...lice_refunds_after_restart_bob_refunded.rs | 2 +- ...ncurrent_bobs_after_xmr_lock_proof_sent.rs | 2 +- ...current_bobs_before_xmr_lock_proof_sent.rs | 2 +- swap/tests/happy_path.rs | 2 +- ...ppy_path_restart_alice_after_xmr_locked.rs | 2 +- ...happy_path_restart_bob_after_xmr_locked.rs | 2 +- ...appy_path_restart_bob_before_xmr_locked.rs | 2 +- swap/tests/harness/mod.rs | 14 +++++------ swap/tests/punish.rs | 2 +- 46 files changed, 161 insertions(+), 145 deletions(-) rename swap/src/{protocol/alice => asb}/behaviour.rs (90%) rename swap/src/{protocol/alice => asb}/event_loop.rs (99%) rename swap/src/{protocol/alice => asb}/recovery.rs (100%) rename swap/src/{protocol/alice => asb}/recovery/cancel.rs (100%) rename swap/src/{protocol/alice => asb}/recovery/punish.rs (100%) rename swap/src/{protocol/alice => asb}/recovery/redeem.rs (100%) rename swap/src/{protocol/alice => asb}/recovery/refund.rs (100%) rename swap/src/{protocol/alice => asb}/recovery/safely_abort.rs (100%) rename swap/src/{protocol/bob => cli}/behaviour.rs (94%) rename swap/src/{protocol/bob => cli}/cancel.rs (100%) rename swap/src/{protocol/bob => cli}/event_loop.rs (98%) rename swap/src/{protocol/bob => cli}/refund.rs (100%) create mode 100644 swap/src/network/alice.rs create mode 100644 swap/src/network/bob.rs rename swap/src/{protocol/alice/swap_setup.rs => network/swap_setup/alice.rs} (96%) rename swap/src/{protocol/bob/swap_setup.rs => network/swap_setup/bob.rs} (96%) diff --git a/swap/src/asb.rs b/swap/src/asb.rs index 47ceb072..16fc21e6 100644 --- a/swap/src/asb.rs +++ b/swap/src/asb.rs @@ -1,7 +1,18 @@ +mod behaviour; pub mod command; pub mod config; +mod event_loop; mod rate; +mod recovery; pub mod tracing; pub mod transport; +pub use behaviour::{Behaviour, OutEvent}; +pub use event_loop::{EventLoop, EventLoopHandle, FixedRate, KrakenRate, LatestRate}; pub use rate::Rate; +pub use recovery::cancel::cancel; +pub use recovery::punish::punish; +pub use recovery::redeem::{redeem, Finality}; +pub use recovery::refund::refund; +pub use recovery::safely_abort::safely_abort; +pub use recovery::{cancel, refund}; diff --git a/swap/src/protocol/alice/behaviour.rs b/swap/src/asb/behaviour.rs similarity index 90% rename from swap/src/protocol/alice/behaviour.rs rename to swap/src/asb/behaviour.rs index 97c1b4b6..8f9ef6b8 100644 --- a/swap/src/protocol/alice/behaviour.rs +++ b/swap/src/asb/behaviour.rs @@ -1,9 +1,10 @@ +use crate::asb::event_loop::LatestRate; use crate::env; use crate::network::quote::BidQuote; +use crate::network::swap_setup::alice; +use crate::network::swap_setup::alice::WalletSnapshot; use crate::network::{encrypted_signature, quote, transfer_proof}; -use crate::protocol::alice::event_loop::LatestRate; -use crate::protocol::alice::swap_setup::WalletSnapshot; -use crate::protocol::alice::{swap_setup, State3}; +use crate::protocol::alice::State3; use anyhow::{anyhow, Error}; use libp2p::ping::{Ping, PingEvent}; use libp2p::request_response::{RequestId, ResponseChannel}; @@ -22,7 +23,7 @@ pub enum OutEvent { }, SwapDeclined { peer: PeerId, - error: swap_setup::Error, + error: alice::Error, }, QuoteRequested { channel: ResponseChannel, @@ -71,7 +72,7 @@ where LR: LatestRate + Send + 'static, { pub quote: quote::Behaviour, - pub swap_setup: swap_setup::Behaviour, + pub swap_setup: alice::Behaviour, pub transfer_proof: transfer_proof::Behaviour, pub encrypted_signature: encrypted_signature::Behaviour, @@ -94,7 +95,7 @@ where ) -> Self { Self { quote: quote::alice(), - swap_setup: swap_setup::Behaviour::new( + swap_setup: alice::Behaviour::new( min_buy, max_buy, env_config, diff --git a/swap/src/protocol/alice/event_loop.rs b/swap/src/asb/event_loop.rs similarity index 99% rename from swap/src/protocol/alice/event_loop.rs rename to swap/src/asb/event_loop.rs index 6456e152..e18d595e 100644 --- a/swap/src/protocol/alice/event_loop.rs +++ b/swap/src/asb/event_loop.rs @@ -1,10 +1,11 @@ +use crate::asb::behaviour::{Behaviour, OutEvent}; use crate::asb::Rate; use crate::database::Database; use crate::env::Config; use crate::network::quote::BidQuote; +use crate::network::swap_setup::alice::WalletSnapshot; use crate::network::transfer_proof; -use crate::protocol::alice::swap_setup::WalletSnapshot; -use crate::protocol::alice::{AliceState, Behaviour, OutEvent, State3, Swap}; +use crate::protocol::alice::{AliceState, State3, Swap}; use crate::{bitcoin, kraken, monero}; use anyhow::{Context, Result}; use futures::future; diff --git a/swap/src/protocol/alice/recovery.rs b/swap/src/asb/recovery.rs similarity index 100% rename from swap/src/protocol/alice/recovery.rs rename to swap/src/asb/recovery.rs diff --git a/swap/src/protocol/alice/recovery/cancel.rs b/swap/src/asb/recovery/cancel.rs similarity index 100% rename from swap/src/protocol/alice/recovery/cancel.rs rename to swap/src/asb/recovery/cancel.rs diff --git a/swap/src/protocol/alice/recovery/punish.rs b/swap/src/asb/recovery/punish.rs similarity index 100% rename from swap/src/protocol/alice/recovery/punish.rs rename to swap/src/asb/recovery/punish.rs diff --git a/swap/src/protocol/alice/recovery/redeem.rs b/swap/src/asb/recovery/redeem.rs similarity index 100% rename from swap/src/protocol/alice/recovery/redeem.rs rename to swap/src/asb/recovery/redeem.rs diff --git a/swap/src/protocol/alice/recovery/refund.rs b/swap/src/asb/recovery/refund.rs similarity index 100% rename from swap/src/protocol/alice/recovery/refund.rs rename to swap/src/asb/recovery/refund.rs diff --git a/swap/src/protocol/alice/recovery/safely_abort.rs b/swap/src/asb/recovery/safely_abort.rs similarity index 100% rename from swap/src/protocol/alice/recovery/safely_abort.rs rename to swap/src/asb/recovery/safely_abort.rs diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 63b4c459..02237284 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -26,12 +26,11 @@ use swap::asb::command::{parse_args, Arguments, Command}; use swap::asb::config::{ initial_setup, query_user_for_initial_config, read_config, Config, ConfigNotInitialized, }; +use swap::asb::{cancel, punish, redeem, refund, safely_abort, EventLoop, Finality, KrakenRate}; use swap::database::Database; use swap::monero::Amount; use swap::network::swarm; -use swap::protocol::alice; -use swap::protocol::alice::event_loop::KrakenRate; -use swap::protocol::alice::{redeem, run, EventLoop}; +use swap::protocol::alice::run; use swap::seed::Seed; use swap::tor::AuthenticatedClient; use swap::{asb, bitcoin, kraken, monero, tor}; @@ -237,7 +236,7 @@ async fn main() -> Result<()> { let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; let (txid, _) = - alice::cancel(swap_id, Arc::new(bitcoin_wallet), Arc::new(db), force).await??; + cancel(swap_id, Arc::new(bitcoin_wallet), Arc::new(db), force).await??; tracing::info!("Cancel transaction successfully published with id {}", txid); } @@ -245,7 +244,7 @@ async fn main() -> Result<()> { let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; let monero_wallet = init_monero_wallet(&config, env_config).await?; - alice::refund( + refund( swap_id, Arc::new(bitcoin_wallet), Arc::new(monero_wallet), @@ -260,12 +259,12 @@ async fn main() -> Result<()> { let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; let (txid, _) = - alice::punish(swap_id, Arc::new(bitcoin_wallet), Arc::new(db), force).await??; + punish(swap_id, Arc::new(bitcoin_wallet), Arc::new(db), force).await??; tracing::info!("Punish transaction successfully published with id {}", txid); } Command::SafelyAbort { swap_id } => { - alice::safely_abort(swap_id, Arc::new(db)).await?; + safely_abort(swap_id, Arc::new(db)).await?; tracing::info!("Swap safely aborted"); } @@ -276,12 +275,12 @@ async fn main() -> Result<()> { } => { let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; - let (txid, _) = alice::redeem( + let (txid, _) = redeem( swap_id, Arc::new(bitcoin_wallet), Arc::new(db), force, - redeem::Finality::from_bool(do_not_await_finality), + Finality::from_bool(do_not_await_finality), ) .await?; diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 71fff4f3..1d1327ae 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -24,12 +24,13 @@ use std::sync::Arc; use std::time::Duration; use swap::bitcoin::TxLock; use swap::cli::command::{parse_args_and_apply_defaults, Arguments, Command, ParseResult}; +use swap::cli::EventLoop; use swap::database::Database; use swap::env::Config; use swap::network::quote::BidQuote; use swap::network::swarm; use swap::protocol::bob; -use swap::protocol::bob::{EventLoop, Swap}; +use swap::protocol::bob::Swap; use swap::seed::Seed; use swap::{bitcoin, cli, monero}; use tracing::{debug, error, info, warn}; @@ -245,13 +246,13 @@ async fn main() -> Result<()> { ) .await?; - let cancel = bob::cancel(swap_id, Arc::new(bitcoin_wallet), db, force).await?; + let cancel = cli::cancel(swap_id, Arc::new(bitcoin_wallet), db, force).await?; match cancel { Ok((txid, _)) => { debug!("Cancel transaction successfully published with id {}", txid) } - Err(bob::cancel::Error::CancelTimelockNotExpiredYet) => error!( + Err(cli::cancel::Error::CancelTimelockNotExpiredYet) => error!( "The Cancel Transaction cannot be published yet, because the timelock has not expired. Please try again later" ), } @@ -277,7 +278,7 @@ async fn main() -> Result<()> { ) .await?; - bob::refund(swap_id, Arc::new(bitcoin_wallet), db, force).await??; + cli::refund(swap_id, Arc::new(bitcoin_wallet), db, force).await??; } }; Ok(()) @@ -428,12 +429,15 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::determine_btc_to_swap; - use ::bitcoin::Amount; use std::sync::Mutex; + + use ::bitcoin::Amount; use tracing::subscriber; + use crate::determine_btc_to_swap; + + use super::*; + struct MaxGiveable { amounts: Vec, call_counter: usize, diff --git a/swap/src/cli.rs b/swap/src/cli.rs index 7962efd8..30a7f7d6 100644 --- a/swap/src/cli.rs +++ b/swap/src/cli.rs @@ -1,3 +1,12 @@ +mod behaviour; +pub mod cancel; pub mod command; +mod event_loop; +pub mod refund; pub mod tracing; pub mod transport; + +pub use behaviour::{Behaviour, OutEvent}; +pub use cancel::cancel; +pub use event_loop::{EventLoop, EventLoopHandle}; +pub use refund::refund; diff --git a/swap/src/protocol/bob/behaviour.rs b/swap/src/cli/behaviour.rs similarity index 94% rename from swap/src/protocol/bob/behaviour.rs rename to swap/src/cli/behaviour.rs index 951c84f6..be6596e3 100644 --- a/swap/src/protocol/bob/behaviour.rs +++ b/swap/src/cli/behaviour.rs @@ -1,6 +1,7 @@ use crate::network::quote::BidQuote; +use crate::network::swap_setup::bob; use crate::network::{encrypted_signature, quote, redial, transfer_proof}; -use crate::protocol::bob::{swap_setup, State2}; +use crate::protocol::bob::State2; use crate::{bitcoin, env}; use anyhow::{anyhow, Error, Result}; use libp2p::core::Multiaddr; @@ -59,7 +60,7 @@ impl OutEvent { #[allow(missing_debug_implementations)] pub struct Behaviour { pub quote: quote::Behaviour, - pub swap_setup: swap_setup::Behaviour, + pub swap_setup: bob::Behaviour, pub transfer_proof: transfer_proof::Behaviour, pub encrypted_signature: encrypted_signature::Behaviour, pub redial: redial::Behaviour, @@ -78,7 +79,7 @@ impl Behaviour { ) -> Self { Self { quote: quote::bob(), - swap_setup: swap_setup::Behaviour::new(env_config, bitcoin_wallet), + swap_setup: bob::Behaviour::new(env_config, bitcoin_wallet), transfer_proof: transfer_proof::bob(), encrypted_signature: encrypted_signature::bob(), redial: redial::Behaviour::new(alice, Duration::from_secs(2)), diff --git a/swap/src/protocol/bob/cancel.rs b/swap/src/cli/cancel.rs similarity index 100% rename from swap/src/protocol/bob/cancel.rs rename to swap/src/cli/cancel.rs diff --git a/swap/src/protocol/bob/event_loop.rs b/swap/src/cli/event_loop.rs similarity index 98% rename from swap/src/protocol/bob/event_loop.rs rename to swap/src/cli/event_loop.rs index 742129a0..9d55a81a 100644 --- a/swap/src/protocol/bob/event_loop.rs +++ b/swap/src/cli/event_loop.rs @@ -1,8 +1,9 @@ use crate::bitcoin::EncryptedSignature; +use crate::cli::behaviour::{Behaviour, OutEvent}; use crate::network::encrypted_signature; use crate::network::quote::BidQuote; -use crate::protocol::bob::swap_setup::NewSwap; -use crate::protocol::bob::{Behaviour, OutEvent, State2}; +use crate::network::swap_setup::bob::NewSwap; +use crate::protocol::bob::State2; use crate::{env, monero}; use anyhow::{Context, Result}; use futures::future::{BoxFuture, OptionFuture}; diff --git a/swap/src/protocol/bob/refund.rs b/swap/src/cli/refund.rs similarity index 100% rename from swap/src/protocol/bob/refund.rs rename to swap/src/cli/refund.rs diff --git a/swap/src/network.rs b/swap/src/network.rs index 1eea35e4..d02cddbd 100644 --- a/swap/src/network.rs +++ b/swap/src/network.rs @@ -1,5 +1,7 @@ mod impl_from_rr_event; +pub mod alice; +pub mod bob; pub mod cbor_request_response; pub mod encrypted_signature; pub mod json_pull_codec; diff --git a/swap/src/network/alice.rs b/swap/src/network/alice.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/swap/src/network/alice.rs @@ -0,0 +1 @@ + diff --git a/swap/src/network/bob.rs b/swap/src/network/bob.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/swap/src/network/bob.rs @@ -0,0 +1 @@ + diff --git a/swap/src/network/encrypted_signature.rs b/swap/src/network/encrypted_signature.rs index 041220e7..15323794 100644 --- a/swap/src/network/encrypted_signature.rs +++ b/swap/src/network/encrypted_signature.rs @@ -1,5 +1,5 @@ use crate::network::cbor_request_response::CborCodec; -use crate::protocol::{alice, bob}; +use crate::{asb, cli}; use libp2p::core::ProtocolName; use libp2p::request_response::{ ProtocolSupport, RequestResponse, RequestResponseConfig, RequestResponseEvent, @@ -46,7 +46,7 @@ pub fn bob() -> Behaviour { ) } -impl From<(PeerId, Message)> for alice::OutEvent { +impl From<(PeerId, Message)> for asb::OutEvent { fn from((peer, message): (PeerId, Message)) -> Self { match message { Message::Request { @@ -60,9 +60,9 @@ impl From<(PeerId, Message)> for alice::OutEvent { } } } -crate::impl_from_rr_event!(OutEvent, alice::OutEvent, PROTOCOL); +crate::impl_from_rr_event!(OutEvent, asb::OutEvent, PROTOCOL); -impl From<(PeerId, Message)> for bob::OutEvent { +impl From<(PeerId, Message)> for cli::OutEvent { fn from((peer, message): (PeerId, Message)) -> Self { match message { Message::Request { .. } => Self::unexpected_request(peer), @@ -72,4 +72,4 @@ impl From<(PeerId, Message)> for bob::OutEvent { } } } -crate::impl_from_rr_event!(OutEvent, bob::OutEvent, PROTOCOL); +crate::impl_from_rr_event!(OutEvent, cli::OutEvent, PROTOCOL); diff --git a/swap/src/network/quote.rs b/swap/src/network/quote.rs index 7fb999ff..1c78adbe 100644 --- a/swap/src/network/quote.rs +++ b/swap/src/network/quote.rs @@ -1,6 +1,5 @@ -use crate::bitcoin; use crate::network::json_pull_codec::JsonPullCodec; -use crate::protocol::{alice, bob}; +use crate::{asb, bitcoin, cli}; use libp2p::core::ProtocolName; use libp2p::request_response::{ ProtocolSupport, RequestResponse, RequestResponseConfig, RequestResponseEvent, @@ -60,7 +59,7 @@ pub fn bob() -> Behaviour { ) } -impl From<(PeerId, Message)> for alice::OutEvent { +impl From<(PeerId, Message)> for asb::OutEvent { fn from((peer, message): (PeerId, Message)) -> Self { match message { Message::Request { channel, .. } => Self::QuoteRequested { channel, peer }, @@ -68,9 +67,9 @@ impl From<(PeerId, Message)> for alice::OutEvent { } } } -crate::impl_from_rr_event!(OutEvent, alice::OutEvent, PROTOCOL); +crate::impl_from_rr_event!(OutEvent, asb::OutEvent, PROTOCOL); -impl From<(PeerId, Message)> for bob::OutEvent { +impl From<(PeerId, Message)> for cli::OutEvent { fn from((peer, message): (PeerId, Message)) -> Self { match message { Message::Request { .. } => Self::unexpected_request(peer), @@ -84,4 +83,4 @@ impl From<(PeerId, Message)> for bob::OutEvent { } } } -crate::impl_from_rr_event!(OutEvent, bob::OutEvent, PROTOCOL); +crate::impl_from_rr_event!(OutEvent, cli::OutEvent, PROTOCOL); diff --git a/swap/src/network/redial.rs b/swap/src/network/redial.rs index a6c00706..23670344 100644 --- a/swap/src/network/redial.rs +++ b/swap/src/network/redial.rs @@ -1,4 +1,4 @@ -use crate::protocol::bob; +use crate::cli; use backoff::backoff::Backoff; use backoff::ExponentialBackoff; use futures::future::FutureExt; @@ -119,11 +119,11 @@ impl NetworkBehaviour for Behaviour { } } -impl From for bob::OutEvent { +impl From for cli::OutEvent { fn from(event: OutEvent) -> Self { match event { OutEvent::AllAttemptsExhausted { peer } => { - bob::OutEvent::AllRedialAttemptsExhausted { peer } + cli::OutEvent::AllRedialAttemptsExhausted { peer } } } } diff --git a/swap/src/network/swap_setup.rs b/swap/src/network/swap_setup.rs index fb5a5657..621f9df3 100644 --- a/swap/src/network/swap_setup.rs +++ b/swap/src/network/swap_setup.rs @@ -5,6 +5,9 @@ use libp2p::swarm::NegotiatedSubstream; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; +pub mod alice; +pub mod bob; + pub const BUF_SIZE: usize = 1024 * 1024; pub mod protocol { diff --git a/swap/src/protocol/alice/swap_setup.rs b/swap/src/network/swap_setup/alice.rs similarity index 96% rename from swap/src/protocol/alice/swap_setup.rs rename to swap/src/network/swap_setup/alice.rs index 333a4769..ab4a1a17 100644 --- a/swap/src/protocol/alice/swap_setup.rs +++ b/swap/src/network/swap_setup/alice.rs @@ -1,11 +1,11 @@ +use crate::asb::LatestRate; use crate::network::swap_setup; use crate::network::swap_setup::{ protocol, BlockchainNetwork, SpotPriceError, SpotPriceRequest, SpotPriceResponse, }; -use crate::protocol::alice::event_loop::LatestRate; use crate::protocol::alice::{State0, State3}; -use crate::protocol::{alice, Message0, Message2, Message4}; -use crate::{bitcoin, env, monero}; +use crate::protocol::{Message0, Message2, Message4}; +use crate::{asb, bitcoin, env, monero}; use anyhow::{anyhow, Context, Result}; use futures::future::{BoxFuture, OptionFuture}; use futures::FutureExt; @@ -81,24 +81,24 @@ impl WalletSnapshot { } } -impl From for alice::OutEvent { +impl From for asb::OutEvent { fn from(event: OutEvent) -> Self { match event { OutEvent::Initiated { send_wallet_snapshot, - } => alice::OutEvent::SwapSetupInitiated { + } => asb::OutEvent::SwapSetupInitiated { send_wallet_snapshot, }, OutEvent::Completed { peer_id: bob_peer_id, swap_id, state3, - } => alice::OutEvent::SwapSetupCompleted { + } => asb::OutEvent::SwapSetupCompleted { peer_id: bob_peer_id, swap_id, state3: Box::new(state3), }, - OutEvent::Error { peer_id, error } => alice::OutEvent::Failure { + OutEvent::Error { peer_id, error } => asb::OutEvent::Failure { peer: peer_id, error: anyhow!(error), }, @@ -194,7 +194,7 @@ where } } -type InboundStream = BoxFuture<'static, Result<(Uuid, alice::State3)>>; +type InboundStream = BoxFuture<'static, Result<(Uuid, State3)>>; pub struct Handler { inbound_stream: OptionFuture, @@ -236,7 +236,7 @@ impl Handler { #[allow(clippy::large_enum_variant)] pub enum HandlerOutEvent { Initiated(bmrng::RequestReceiver), - Completed(Result<(Uuid, alice::State3)>), + Completed(Result<(Uuid, State3)>), } impl ProtocolsHandler for Handler diff --git a/swap/src/protocol/bob/swap_setup.rs b/swap/src/network/swap_setup/bob.rs similarity index 96% rename from swap/src/protocol/bob/swap_setup.rs rename to swap/src/network/swap_setup/bob.rs index 9c8b07f4..7f8110a1 100644 --- a/swap/src/protocol/bob/swap_setup.rs +++ b/swap/src/network/swap_setup/bob.rs @@ -2,9 +2,9 @@ use crate::network::swap_setup::{ protocol, read_cbor_message, write_cbor_message, BlockchainNetwork, SpotPriceError, SpotPriceRequest, SpotPriceResponse, }; -use crate::protocol::bob::State0; -use crate::protocol::{bob, Message1, Message3}; -use crate::{bitcoin, env, monero}; +use crate::protocol::bob::{State0, State2}; +use crate::protocol::{Message1, Message3}; +use crate::{bitcoin, cli, env, monero}; use anyhow::Result; use futures::future::{BoxFuture, OptionFuture}; use futures::FutureExt; @@ -46,9 +46,9 @@ impl Behaviour { } } -impl From for bob::OutEvent { +impl From for cli::OutEvent { fn from(completed: Completed) -> Self { - bob::OutEvent::SwapSetupCompleted(Box::new(completed.0)) + cli::OutEvent::SwapSetupCompleted(Box::new(completed.0)) } } @@ -93,7 +93,7 @@ impl NetworkBehaviour for Behaviour { } } -type OutboundStream = BoxFuture<'static, Result>; +type OutboundStream = BoxFuture<'static, Result>; pub struct Handler { outbound_stream: OptionFuture, @@ -126,7 +126,7 @@ pub struct NewSwap { pub bitcoin_refund_address: bitcoin::Address, } -pub struct Completed(Result); +pub struct Completed(Result); impl ProtocolsHandler for Handler { type InEvent = NewSwap; diff --git a/swap/src/network/swarm.rs b/swap/src/network/swarm.rs index 43d635d7..bbcc2353 100644 --- a/swap/src/network/swarm.rs +++ b/swap/src/network/swarm.rs @@ -1,5 +1,4 @@ -use crate::protocol::alice::event_loop::LatestRate; -use crate::protocol::{alice, bob}; +use crate::asb::LatestRate; use crate::seed::Seed; use crate::{asb, bitcoin, cli, env, tor}; use anyhow::Result; @@ -16,11 +15,11 @@ pub fn asb( latest_rate: LR, resume_only: bool, env_config: env::Config, -) -> Result>> +) -> Result>> where LR: LatestRate + Send + 'static + Debug + Clone, { - let behaviour = alice::Behaviour::new(min_buy, max_buy, latest_rate, resume_only, env_config); + let behaviour = asb::Behaviour::new(min_buy, max_buy, latest_rate, resume_only, env_config); let identity = seed.derive_libp2p_identity(); let transport = asb::transport::new(&identity)?; @@ -41,13 +40,13 @@ pub async fn cli( tor_socks5_port: u16, env_config: env::Config, bitcoin_wallet: Arc, -) -> Result> { +) -> Result> { let maybe_tor_socks5_port = match tor::Client::new(tor_socks5_port).assert_tor_running().await { Ok(()) => Some(tor_socks5_port), Err(_) => None, }; - let behaviour = bob::Behaviour::new(alice, env_config, bitcoin_wallet); + let behaviour = cli::Behaviour::new(alice, env_config, bitcoin_wallet); let identity = seed.derive_libp2p_identity(); let transport = cli::transport::new(&identity, maybe_tor_socks5_port)?; diff --git a/swap/src/network/transfer_proof.rs b/swap/src/network/transfer_proof.rs index def98bb9..98ab88ac 100644 --- a/swap/src/network/transfer_proof.rs +++ b/swap/src/network/transfer_proof.rs @@ -1,6 +1,5 @@ -use crate::monero; use crate::network::cbor_request_response::CborCodec; -use crate::protocol::{alice, bob}; +use crate::{asb, cli, monero}; use libp2p::core::ProtocolName; use libp2p::request_response::{ ProtocolSupport, RequestResponse, RequestResponseConfig, RequestResponseEvent, @@ -47,7 +46,7 @@ pub fn bob() -> Behaviour { ) } -impl From<(PeerId, Message)> for alice::OutEvent { +impl From<(PeerId, Message)> for asb::OutEvent { fn from((peer, message): (PeerId, Message)) -> Self { match message { Message::Request { .. } => Self::unexpected_request(peer), @@ -58,9 +57,9 @@ impl From<(PeerId, Message)> for alice::OutEvent { } } } -crate::impl_from_rr_event!(OutEvent, alice::OutEvent, PROTOCOL); +crate::impl_from_rr_event!(OutEvent, asb::OutEvent, PROTOCOL); -impl From<(PeerId, Message)> for bob::OutEvent { +impl From<(PeerId, Message)> for cli::OutEvent { fn from((peer, message): (PeerId, Message)) -> Self { match message { Message::Request { @@ -74,4 +73,4 @@ impl From<(PeerId, Message)> for bob::OutEvent { } } } -crate::impl_from_rr_event!(OutEvent, bob::OutEvent, PROTOCOL); +crate::impl_from_rr_event!(OutEvent, cli::OutEvent, PROTOCOL); diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index fa8a4317..f8e80ca7 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -2,31 +2,19 @@ //! Alice holds XMR and wishes receive BTC. use crate::database::Database; use crate::env::Config; -use crate::{bitcoin, monero}; +use crate::{asb, bitcoin, monero}; use std::sync::Arc; use uuid::Uuid; -pub use self::behaviour::{Behaviour, OutEvent}; -pub use self::event_loop::{EventLoop, EventLoopHandle}; -pub use self::recovery::cancel::cancel; -pub use self::recovery::punish::punish; -pub use self::recovery::redeem::redeem; -pub use self::recovery::refund::refund; -pub use self::recovery::safely_abort::safely_abort; -pub use self::recovery::{cancel, punish, redeem, refund, safely_abort}; pub use self::state::*; pub use self::swap::{run, run_until}; -mod behaviour; -pub mod event_loop; -mod recovery; pub mod state; pub mod swap; -pub mod swap_setup; pub struct Swap { pub state: AliceState, - pub event_loop_handle: EventLoopHandle, + pub event_loop_handle: asb::EventLoopHandle, pub bitcoin_wallet: Arc, pub monero_wallet: Arc, pub env_config: Config, diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 4070a04b..c15892a1 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -1,8 +1,8 @@ //! Run an XMR/BTC swap in the role of Alice. //! Alice holds XMR and wishes receive BTC. +use crate::asb::{EventLoopHandle, LatestRate}; use crate::bitcoin::ExpiredTimelocks; use crate::env::Config; -use crate::protocol::alice::event_loop::{EventLoopHandle, LatestRate}; use crate::protocol::alice::{AliceState, Swap}; use crate::{bitcoin, database, monero}; use anyhow::{bail, Context, Result}; diff --git a/swap/src/protocol/bob.rs b/swap/src/protocol/bob.rs index 4c93b73b..347f86d8 100644 --- a/swap/src/protocol/bob.rs +++ b/swap/src/protocol/bob.rs @@ -1,27 +1,20 @@ -use crate::database::Database; -use crate::{bitcoin, env, monero}; -use anyhow::Result; use std::sync::Arc; + +use anyhow::Result; use uuid::Uuid; -pub use self::behaviour::{Behaviour, OutEvent}; -pub use self::cancel::cancel; -pub use self::event_loop::{EventLoop, EventLoopHandle}; -pub use self::refund::refund; +use crate::database::Database; +use crate::{bitcoin, cli, env, monero}; + pub use self::state::*; pub use self::swap::{run, run_until}; -mod behaviour; -pub mod cancel; -pub mod event_loop; -pub mod refund; pub mod state; pub mod swap; -mod swap_setup; pub struct Swap { pub state: BobState, - pub event_loop_handle: EventLoopHandle, + pub event_loop_handle: cli::EventLoopHandle, pub db: Database, pub bitcoin_wallet: Arc, pub monero_wallet: Arc, @@ -38,7 +31,7 @@ impl Swap { bitcoin_wallet: Arc, monero_wallet: Arc, env_config: env::Config, - event_loop_handle: EventLoopHandle, + event_loop_handle: cli::EventLoopHandle, receive_monero_address: monero::Address, btc_amount: bitcoin::Amount, ) -> Self { @@ -60,7 +53,7 @@ impl Swap { bitcoin_wallet: Arc, monero_wallet: Arc, env_config: env::Config, - event_loop_handle: EventLoopHandle, + event_loop_handle: cli::EventLoopHandle, receive_monero_address: monero::Address, ) -> Result { let state = db.get_state(id)?.try_into_bob()?.into(); diff --git a/swap/src/protocol/bob/swap.rs b/swap/src/protocol/bob/swap.rs index 0d8eefee..23ab6388 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -1,9 +1,9 @@ use crate::bitcoin::{ExpiredTimelocks, TxCancel, TxRefund}; +use crate::cli::EventLoopHandle; use crate::database::Swap; +use crate::network::swap_setup::bob::NewSwap; use crate::protocol::bob; -use crate::protocol::bob::event_loop::EventLoopHandle; use crate::protocol::bob::state::*; -use crate::protocol::bob::swap_setup::NewSwap; use crate::{bitcoin, monero}; use anyhow::{bail, Context, Result}; use tokio::select; diff --git a/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command.rs b/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command.rs index 557768a3..94e12506 100644 --- a/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command.rs +++ b/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command.rs @@ -3,10 +3,11 @@ pub mod harness; use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::bob_run_until::is_btc_locked; use harness::FastCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; +use swap::{asb, cli}; #[tokio::test] async fn given_alice_and_bob_manually_refund_after_funds_locked_both_refund() { @@ -50,7 +51,7 @@ async fn given_alice_and_bob_manually_refund_after_funds_locked_both_refund() { // Bob manually cancels bob_join_handle.abort(); let (_, state) = - bob::cancel(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false).await??; + cli::cancel(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false).await??; assert!(matches!(state, BobState::BtcCancelled { .. })); let (bob_swap, bob_join_handle) = ctx @@ -61,7 +62,7 @@ async fn given_alice_and_bob_manually_refund_after_funds_locked_both_refund() { // Bob manually refunds bob_join_handle.abort(); let bob_state = - bob::refund(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false).await??; + cli::refund(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false).await??; ctx.assert_bob_refunded(bob_state).await; @@ -74,7 +75,7 @@ async fn given_alice_and_bob_manually_refund_after_funds_locked_both_refund() { AliceState::XmrLockTransactionSent { .. } )); - alice::cancel( + asb::cancel( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db, @@ -86,7 +87,7 @@ async fn given_alice_and_bob_manually_refund_after_funds_locked_both_refund() { ctx.restart_alice().await; let alice_swap = ctx.alice_next_swap().await; assert!(matches!(alice_swap.state, AliceState::BtcCancelled { .. })); - let alice_state = alice::refund( + let alice_state = asb::refund( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.monero_wallet, diff --git a/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired.rs b/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired.rs index 9a20127e..13dd1160 100644 --- a/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired.rs +++ b/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired.rs @@ -3,10 +3,11 @@ pub mod harness; use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::bob_run_until::is_btc_locked; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; +use swap::{asb, cli}; #[tokio::test] async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors() { @@ -37,12 +38,12 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors() )); // Bob tries but fails to manually cancel - let result = bob::cancel(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false) + let result = cli::cancel(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false) .await? .unwrap_err(); assert!(matches!( result, - bob::cancel::Error::CancelTimelockNotExpiredYet + cli::cancel::Error::CancelTimelockNotExpiredYet )); ctx.restart_alice().await; @@ -53,7 +54,7 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors() )); // Alice tries but fails manual cancel - let result = alice::cancel( + let result = asb::cancel( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db, @@ -63,7 +64,7 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors() .unwrap_err(); assert!(matches!( result, - alice::cancel::Error::CancelTimelockNotExpiredYet + asb::cancel::Error::CancelTimelockNotExpiredYet )); let (bob_swap, bob_join_handle) = ctx @@ -72,10 +73,10 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors() assert!(matches!(bob_swap.state, BobState::BtcLocked { .. })); // Bob tries but fails to manually refund - let result = bob::refund(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false) + let result = cli::refund(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, false) .await? .unwrap_err(); - assert!(matches!(result, bob::refund::SwapNotCancelledYet(_))); + assert!(matches!(result, cli::refund::SwapNotCancelledYet(_))); let (bob_swap, _) = ctx .stop_and_resume_bob_from_db(bob_join_handle, swap_id) @@ -90,7 +91,7 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors() )); // Alice tries but fails manual cancel - let result = alice::refund( + let result = asb::refund( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.monero_wallet, @@ -99,7 +100,7 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors() ) .await? .unwrap_err(); - assert!(matches!(result, alice::refund::Error::SwapNotCancelled)); + assert!(matches!(result, asb::refund::Error::SwapNotCancelled)); ctx.restart_alice().await; let alice_swap = ctx.alice_next_swap().await; diff --git a/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired_force.rs b/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired_force.rs index 843d6a79..de16ec96 100644 --- a/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired_force.rs +++ b/swap/tests/alice_and_bob_refund_using_cancel_and_refund_command_timelock_not_expired_force.rs @@ -3,10 +3,11 @@ pub mod harness; use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::bob_run_until::is_btc_locked; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; +use swap::{asb, cli}; #[tokio::test] async fn given_alice_and_bob_manually_force_cancel_when_timelock_not_expired_errors() { @@ -37,7 +38,7 @@ async fn given_alice_and_bob_manually_force_cancel_when_timelock_not_expired_err )); // Bob tries but fails to manually cancel - let result = bob::cancel(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, true).await; + let result = cli::cancel(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, true).await; assert!(matches!(result, Err(_))); ctx.restart_alice().await; @@ -48,7 +49,7 @@ async fn given_alice_and_bob_manually_force_cancel_when_timelock_not_expired_err )); // Alice tries but fails manual cancel - let is_outer_err = alice::cancel( + let is_outer_err = asb::cancel( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db, @@ -64,7 +65,7 @@ async fn given_alice_and_bob_manually_force_cancel_when_timelock_not_expired_err assert!(matches!(bob_swap.state, BobState::BtcLocked { .. })); // Bob tries but fails to manually refund - let is_outer_err = bob::refund(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, true) + let is_outer_err = cli::refund(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db, true) .await .is_err(); assert!(is_outer_err); @@ -82,7 +83,7 @@ async fn given_alice_and_bob_manually_force_cancel_when_timelock_not_expired_err )); // Alice tries but fails manual cancel - let refund_tx_not_published_yet = alice::refund( + let refund_tx_not_published_yet = asb::refund( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.monero_wallet, @@ -93,7 +94,7 @@ async fn given_alice_and_bob_manually_force_cancel_when_timelock_not_expired_err .unwrap_err(); assert!(matches!( refund_tx_not_published_yet, - alice::refund::Error::RefundTransactionNotPublishedYet(..) + asb::refund::Error::RefundTransactionNotPublishedYet(..) )); ctx.restart_alice().await; diff --git a/swap/tests/alice_manually_punishes_after_bob_dead.rs b/swap/tests/alice_manually_punishes_after_bob_dead.rs index 2da13969..2cfa11ae 100644 --- a/swap/tests/alice_manually_punishes_after_bob_dead.rs +++ b/swap/tests/alice_manually_punishes_after_bob_dead.rs @@ -3,7 +3,8 @@ pub mod harness; use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::bob_run_until::is_btc_locked; use harness::FastPunishConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; @@ -47,7 +48,7 @@ async fn alice_manually_punishes_after_bob_dead() { ctx.restart_alice().await; let alice_swap = ctx.alice_next_swap().await; - let (_, alice_state) = alice::cancel( + let (_, alice_state) = asb::cancel( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db, @@ -70,7 +71,7 @@ async fn alice_manually_punishes_after_bob_dead() { ctx.restart_alice().await; let alice_swap = ctx.alice_next_swap().await; - let (_, alice_state) = alice::punish( + let (_, alice_state) = asb::punish( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db, diff --git a/swap/tests/alice_manually_redeems_after_enc_sig_learned.rs b/swap/tests/alice_manually_redeems_after_enc_sig_learned.rs index 720dad19..0ece1b85 100644 --- a/swap/tests/alice_manually_redeems_after_enc_sig_learned.rs +++ b/swap/tests/alice_manually_redeems_after_enc_sig_learned.rs @@ -2,8 +2,8 @@ pub mod harness; use harness::alice_run_until::is_encsig_learned; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; -use swap::protocol::alice::redeem::Finality; +use swap::asb; +use swap::asb::{Finality, FixedRate}; use swap::protocol::alice::AliceState; use swap::protocol::{alice, bob}; @@ -28,7 +28,7 @@ async fn alice_manually_redeems_after_enc_sig_learned() { // manual redeem ctx.restart_alice().await; let alice_swap = ctx.alice_next_swap().await; - let (_, alice_state) = alice::redeem( + let (_, alice_state) = asb::redeem( alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db, diff --git a/swap/tests/alice_punishes_after_restart_bob_dead.rs b/swap/tests/alice_punishes_after_restart_bob_dead.rs index a272dbf1..b049d681 100644 --- a/swap/tests/alice_punishes_after_restart_bob_dead.rs +++ b/swap/tests/alice_punishes_after_restart_bob_dead.rs @@ -3,7 +3,7 @@ pub mod harness; use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::bob_run_until::is_btc_locked; use harness::FastPunishConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/alice_refunds_after_restart_bob_refunded.rs b/swap/tests/alice_refunds_after_restart_bob_refunded.rs index 2cf12605..1ec35e34 100644 --- a/swap/tests/alice_refunds_after_restart_bob_refunded.rs +++ b/swap/tests/alice_refunds_after_restart_bob_refunded.rs @@ -2,7 +2,7 @@ pub mod harness; use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::FastCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/concurrent_bobs_after_xmr_lock_proof_sent.rs b/swap/tests/concurrent_bobs_after_xmr_lock_proof_sent.rs index e756fd9e..45e27819 100644 --- a/swap/tests/concurrent_bobs_after_xmr_lock_proof_sent.rs +++ b/swap/tests/concurrent_bobs_after_xmr_lock_proof_sent.rs @@ -2,7 +2,7 @@ pub mod harness; use harness::bob_run_until::is_xmr_locked; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/concurrent_bobs_before_xmr_lock_proof_sent.rs b/swap/tests/concurrent_bobs_before_xmr_lock_proof_sent.rs index 420d3cbe..8c6bc034 100644 --- a/swap/tests/concurrent_bobs_before_xmr_lock_proof_sent.rs +++ b/swap/tests/concurrent_bobs_before_xmr_lock_proof_sent.rs @@ -2,7 +2,7 @@ pub mod harness; use harness::bob_run_until::is_btc_locked; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/happy_path.rs b/swap/tests/happy_path.rs index 51e132fa..3814eb0e 100644 --- a/swap/tests/happy_path.rs +++ b/swap/tests/happy_path.rs @@ -1,7 +1,7 @@ pub mod harness; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::{alice, bob}; use tokio::join; diff --git a/swap/tests/happy_path_restart_alice_after_xmr_locked.rs b/swap/tests/happy_path_restart_alice_after_xmr_locked.rs index 95a68861..22a50757 100644 --- a/swap/tests/happy_path_restart_alice_after_xmr_locked.rs +++ b/swap/tests/happy_path_restart_alice_after_xmr_locked.rs @@ -2,7 +2,7 @@ pub mod harness; use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::alice::AliceState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/happy_path_restart_bob_after_xmr_locked.rs b/swap/tests/happy_path_restart_bob_after_xmr_locked.rs index b3a3b1ed..f38c8953 100644 --- a/swap/tests/happy_path_restart_bob_after_xmr_locked.rs +++ b/swap/tests/happy_path_restart_bob_after_xmr_locked.rs @@ -2,7 +2,7 @@ pub mod harness; use harness::bob_run_until::is_xmr_locked; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/happy_path_restart_bob_before_xmr_locked.rs b/swap/tests/happy_path_restart_bob_before_xmr_locked.rs index b3a3b1ed..f38c8953 100644 --- a/swap/tests/happy_path_restart_bob_before_xmr_locked.rs +++ b/swap/tests/happy_path_restart_bob_before_xmr_locked.rs @@ -2,7 +2,7 @@ pub mod harness; use harness::bob_run_until::is_xmr_locked; use harness::SlowCancelConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/harness/mod.rs b/swap/tests/harness/mod.rs index 052b1d4b..4f692648 100644 --- a/swap/tests/harness/mod.rs +++ b/swap/tests/harness/mod.rs @@ -14,16 +14,16 @@ use std::fmt; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::Duration; +use swap::asb::FixedRate; use swap::bitcoin::{CancelTimelock, PunishTimelock, TxCancel, TxPunish, TxRedeem, TxRefund}; use swap::database::Database; use swap::env::{Config, GetConfig}; use swap::network::swarm; -use swap::protocol::alice::event_loop::FixedRate; use swap::protocol::alice::{AliceState, Swap}; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; use swap::seed::Seed; -use swap::{bitcoin, env, monero}; +use swap::{asb, bitcoin, cli, env, monero}; use tempfile::tempdir; use testcontainers::clients::Cli; use testcontainers::{Container, Docker, RunArgs}; @@ -240,7 +240,7 @@ async fn start_alice( .unwrap(); swarm.listen_on(listen_address).unwrap(); - let (event_loop, swap_handle) = alice::EventLoop::new( + let (event_loop, swap_handle) = asb::EventLoop::new( swarm, env_config, bitcoin_wallet, @@ -399,7 +399,7 @@ struct BobParams { } impl BobParams { - pub async fn new_swap_from_db(&self, swap_id: Uuid) -> Result<(bob::Swap, bob::EventLoop)> { + pub async fn new_swap_from_db(&self, swap_id: Uuid) -> Result<(bob::Swap, cli::EventLoop)> { let (event_loop, handle) = self.new_eventloop(swap_id).await?; let db = Database::open(&self.db_path)?; @@ -419,7 +419,7 @@ impl BobParams { pub async fn new_swap( &self, btc_amount: bitcoin::Amount, - ) -> Result<(bob::Swap, bob::EventLoop)> { + ) -> Result<(bob::Swap, cli::EventLoop)> { let swap_id = Uuid::new_v4(); let (event_loop, handle) = self.new_eventloop(swap_id).await?; @@ -442,7 +442,7 @@ impl BobParams { pub async fn new_eventloop( &self, swap_id: Uuid, - ) -> Result<(bob::EventLoop, bob::EventLoopHandle)> { + ) -> Result<(cli::EventLoop, cli::EventLoopHandle)> { let tor_socks5_port = get_port() .expect("We don't care about Tor in the tests so we get a free port to disable it."); let mut swarm = swarm::cli( @@ -457,7 +457,7 @@ impl BobParams { .behaviour_mut() .add_address(self.alice_peer_id, self.alice_address.clone()); - bob::EventLoop::new(swap_id, swarm, self.alice_peer_id, self.env_config) + cli::EventLoop::new(swap_id, swarm, self.alice_peer_id, self.env_config) } } diff --git a/swap/tests/punish.rs b/swap/tests/punish.rs index 61af1f61..60eadfe3 100644 --- a/swap/tests/punish.rs +++ b/swap/tests/punish.rs @@ -2,7 +2,7 @@ pub mod harness; use harness::bob_run_until::is_btc_locked; use harness::FastPunishConfig; -use swap::protocol::alice::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob};