From a11c9d9c038c3cc3b4a90cc3f483a22f39001b43 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Fri, 25 Jun 2021 18:20:10 +1000 Subject: [PATCH] fixup! Move files from `protocol` to appropriate module --- swap/src/asb.rs | 11 +++++------ swap/src/bin/asb.rs | 6 ++---- swap/src/bin/swap.rs | 18 ++++++++---------- swap/src/cli.rs | 4 ++-- swap/src/cli/behaviour.rs | 16 +++++++--------- swap/src/network/redial.rs | 14 ++++++-------- swap/src/network/swap_setup.rs | 3 +-- swap/src/network/swap_setup/alice.rs | 2 +- swap/src/network/swarm.rs | 2 +- swap/src/protocol/alice.rs | 2 +- swap/src/protocol/alice/swap.rs | 2 +- swap/src/protocol/bob.rs | 6 +++--- swap/src/protocol/bob/swap.rs | 2 +- ...b_refund_using_cancel_and_refund_command.rs | 2 +- ..._and_refund_command_timelock_not_expired.rs | 2 +- ...efund_command_timelock_not_expired_force.rs | 2 +- .../alice_manually_punishes_after_bob_dead.rs | 2 +- ...e_manually_redeems_after_enc_sig_learned.rs | 3 +-- .../alice_punishes_after_restart_bob_dead.rs | 2 +- ...alice_refunds_after_restart_bob_refunded.rs | 2 +- ...oncurrent_bobs_after_xmr_lock_proof_sent.rs | 2 +- ...ncurrent_bobs_before_xmr_lock_proof_sent.rs | 2 +- swap/tests/happy_path.rs | 2 +- ...appy_path_restart_alice_after_xmr_locked.rs | 2 +- .../happy_path_restart_bob_after_xmr_locked.rs | 2 +- ...happy_path_restart_bob_before_xmr_locked.rs | 2 +- swap/tests/harness/mod.rs | 2 +- swap/tests/punish.rs | 2 +- 28 files changed, 54 insertions(+), 65 deletions(-) diff --git a/swap/src/asb.rs b/swap/src/asb.rs index 92c08178..16fc21e6 100644 --- a/swap/src/asb.rs +++ b/swap/src/asb.rs @@ -1,16 +1,15 @@ -pub use rate::Rate; - -pub mod behaviour; +mod behaviour; pub mod command; pub mod config; -pub mod event_loop; +mod event_loop; mod rate; -pub mod recovery; +mod recovery; pub mod tracing; pub mod transport; pub use behaviour::{Behaviour, OutEvent}; -pub use event_loop::{EventLoop, EventLoopHandle}; +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}; diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 1c087122..02237284 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -26,9 +26,7 @@ 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::event_loop::{EventLoop, KrakenRate}; -use swap::asb::recovery::redeem; -use swap::asb::{cancel, punish, redeem, refund, safely_abort}; +use swap::asb::{cancel, punish, redeem, refund, safely_abort, EventLoop, Finality, KrakenRate}; use swap::database::Database; use swap::monero::Amount; use swap::network::swarm; @@ -282,7 +280,7 @@ async fn main() -> Result<()> { 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 5af75145..1d1327ae 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -12,24 +12,19 @@ #![forbid(unsafe_code)] #![allow(non_snake_case)] +use anyhow::{bail, Context, Result}; +use prettytable::{row, Table}; +use qrcode::render::unicode; +use qrcode::QrCode; use std::cmp::min; use std::env; use std::future::Future; use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; - -use anyhow::{bail, Context, Result}; -use prettytable::{row, Table}; -use qrcode::render::unicode; -use qrcode::QrCode; -use tracing::{debug, error, info, warn}; -use url::Url; -use uuid::Uuid; - use swap::bitcoin::TxLock; use swap::cli::command::{parse_args_and_apply_defaults, Arguments, Command, ParseResult}; -use swap::cli::event_loop::EventLoop; +use swap::cli::EventLoop; use swap::database::Database; use swap::env::Config; use swap::network::quote::BidQuote; @@ -38,6 +33,9 @@ use swap::protocol::bob; use swap::protocol::bob::Swap; use swap::seed::Seed; use swap::{bitcoin, cli, monero}; +use tracing::{debug, error, info, warn}; +use url::Url; +use uuid::Uuid; #[macro_use] extern crate prettytable; diff --git a/swap/src/cli.rs b/swap/src/cli.rs index 7c79a796..30a7f7d6 100644 --- a/swap/src/cli.rs +++ b/swap/src/cli.rs @@ -1,7 +1,7 @@ -pub mod behaviour; +mod behaviour; pub mod cancel; pub mod command; -pub mod event_loop; +mod event_loop; pub mod refund; pub mod tracing; pub mod transport; diff --git a/swap/src/cli/behaviour.rs b/swap/src/cli/behaviour.rs index d2e4ed60..cbd39b27 100644 --- a/swap/src/cli/behaviour.rs +++ b/swap/src/cli/behaviour.rs @@ -1,17 +1,15 @@ -use std::sync::Arc; -use std::time::Duration; - -use anyhow::{anyhow, Error, Result}; -use libp2p::core::Multiaddr; -use libp2p::ping::{Ping, PingEvent}; -use libp2p::request_response::{RequestId, ResponseChannel}; -use libp2p::{NetworkBehaviour, PeerId}; - use crate::network::quote::BidQuote; use crate::network::swap_setup::bob; use crate::network::{encrypted_signature, quote, redial, transfer_proof}; use crate::protocol::bob::State2; use crate::{bitcoin, env}; +use anyhow::{anyhow, Error, Result}; +use libp2p::core::Multiaddr; +use libp2p::ping::{Ping, PingEvent}; +use libp2p::request_response::{RequestId, ResponseChannel}; +use libp2p::{NetworkBehaviour, PeerId}; +use std::sync::Arc; +use std::time::Duration; #[derive(Debug)] pub enum OutEvent { diff --git a/swap/src/network/redial.rs b/swap/src/network/redial.rs index d75480f8..23670344 100644 --- a/swap/src/network/redial.rs +++ b/swap/src/network/redial.rs @@ -1,7 +1,4 @@ -use std::pin::Pin; -use std::task::{Context, Poll}; -use std::time::Duration; - +use crate::cli; use backoff::backoff::Backoff; use backoff::ExponentialBackoff; use futures::future::FutureExt; @@ -10,11 +7,12 @@ use libp2p::core::Multiaddr; use libp2p::swarm::protocols_handler::DummyProtocolsHandler; use libp2p::swarm::{DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p::PeerId; +use std::pin::Pin; +use std::task::{Context, Poll}; +use std::time::Duration; use tokio::time::{Instant, Sleep}; use void::Void; -use crate::cli; - pub enum OutEvent { AllAttemptsExhausted { peer: PeerId }, } @@ -121,11 +119,11 @@ impl NetworkBehaviour for Behaviour { } } -impl From for cli::behaviour::OutEvent { +impl From for cli::OutEvent { fn from(event: OutEvent) -> Self { match event { OutEvent::AllAttemptsExhausted { peer } => { - cli::behaviour::OutEvent::AllRedialAttemptsExhausted { peer } + cli::OutEvent::AllRedialAttemptsExhausted { peer } } } } diff --git a/swap/src/network/swap_setup.rs b/swap/src/network/swap_setup.rs index b76d1d00..621f9df3 100644 --- a/swap/src/network/swap_setup.rs +++ b/swap/src/network/swap_setup.rs @@ -1,11 +1,10 @@ +use crate::monero; use anyhow::{Context, Result}; use libp2p::core::upgrade; use libp2p::swarm::NegotiatedSubstream; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; -use crate::monero; - pub mod alice; pub mod bob; diff --git a/swap/src/network/swap_setup/alice.rs b/swap/src/network/swap_setup/alice.rs index 9135ee35..ab4a1a17 100644 --- a/swap/src/network/swap_setup/alice.rs +++ b/swap/src/network/swap_setup/alice.rs @@ -1,4 +1,4 @@ -use crate::asb::event_loop::LatestRate; +use crate::asb::LatestRate; use crate::network::swap_setup; use crate::network::swap_setup::{ protocol, BlockchainNetwork, SpotPriceError, SpotPriceRequest, SpotPriceResponse, diff --git a/swap/src/network/swarm.rs b/swap/src/network/swarm.rs index 2500f1a5..bbcc2353 100644 --- a/swap/src/network/swarm.rs +++ b/swap/src/network/swarm.rs @@ -1,4 +1,4 @@ -use crate::asb::event_loop::LatestRate; +use crate::asb::LatestRate; use crate::seed::Seed; use crate::{asb, bitcoin, cli, env, tor}; use anyhow::Result; diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index 0673b5fe..f8e80ca7 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -14,7 +14,7 @@ pub mod swap; pub struct Swap { pub state: AliceState, - pub event_loop_handle: asb::event_loop::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 2c3f1296..c15892a1 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -1,6 +1,6 @@ //! Run an XMR/BTC swap in the role of Alice. //! Alice holds XMR and wishes receive BTC. -use crate::asb::event_loop::{EventLoopHandle, LatestRate}; +use crate::asb::{EventLoopHandle, LatestRate}; use crate::bitcoin::ExpiredTimelocks; use crate::env::Config; use crate::protocol::alice::{AliceState, Swap}; diff --git a/swap/src/protocol/bob.rs b/swap/src/protocol/bob.rs index ab047388..347f86d8 100644 --- a/swap/src/protocol/bob.rs +++ b/swap/src/protocol/bob.rs @@ -14,7 +14,7 @@ pub mod swap; pub struct Swap { pub state: BobState, - pub event_loop_handle: cli::event_loop::EventLoopHandle, + pub event_loop_handle: cli::EventLoopHandle, pub db: Database, pub bitcoin_wallet: Arc, pub monero_wallet: Arc, @@ -31,7 +31,7 @@ impl Swap { bitcoin_wallet: Arc, monero_wallet: Arc, env_config: env::Config, - event_loop_handle: cli::event_loop::EventLoopHandle, + event_loop_handle: cli::EventLoopHandle, receive_monero_address: monero::Address, btc_amount: bitcoin::Amount, ) -> Self { @@ -53,7 +53,7 @@ impl Swap { bitcoin_wallet: Arc, monero_wallet: Arc, env_config: env::Config, - event_loop_handle: cli::event_loop::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 36ee8764..23ab6388 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -1,5 +1,5 @@ use crate::bitcoin::{ExpiredTimelocks, TxCancel, TxRefund}; -use crate::cli::event_loop::EventLoopHandle; +use crate::cli::EventLoopHandle; use crate::database::Swap; use crate::network::swap_setup::bob::NewSwap; use crate::protocol::bob; 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 12fac996..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,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::FastCancelConfig; -use swap::asb::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_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 81de1231..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,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::SlowCancelConfig; -use swap::asb::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_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 f7174283..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,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::SlowCancelConfig; -use swap::asb::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_manually_punishes_after_bob_dead.rs b/swap/tests/alice_manually_punishes_after_bob_dead.rs index 11bf53ba..2cfa11ae 100644 --- a/swap/tests/alice_manually_punishes_after_bob_dead.rs +++ b/swap/tests/alice_manually_punishes_after_bob_dead.rs @@ -4,7 +4,7 @@ use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::bob_run_until::is_btc_locked; use harness::FastPunishConfig; use swap::asb; -use swap::asb::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_manually_redeems_after_enc_sig_learned.rs b/swap/tests/alice_manually_redeems_after_enc_sig_learned.rs index cf85bb90..0ece1b85 100644 --- a/swap/tests/alice_manually_redeems_after_enc_sig_learned.rs +++ b/swap/tests/alice_manually_redeems_after_enc_sig_learned.rs @@ -3,8 +3,7 @@ pub mod harness; use harness::alice_run_until::is_encsig_learned; use harness::SlowCancelConfig; use swap::asb; -use swap::asb::event_loop::FixedRate; -use swap::asb::Finality; +use swap::asb::{Finality, FixedRate}; use swap::protocol::alice::AliceState; use swap::protocol::{alice, bob}; diff --git a/swap/tests/alice_punishes_after_restart_bob_dead.rs b/swap/tests/alice_punishes_after_restart_bob_dead.rs index aa66ade8..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::asb::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 8038fc0f..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::asb::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 9460173c..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::asb::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 599ff47d..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::asb::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 34e1e902..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::asb::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 d65ea13c..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::asb::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 08b58fe6..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::asb::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 08b58fe6..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::asb::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 a2dd9f84..4f692648 100644 --- a/swap/tests/harness/mod.rs +++ b/swap/tests/harness/mod.rs @@ -14,7 +14,7 @@ use std::fmt; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::Duration; -use swap::asb::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::bitcoin::{CancelTimelock, PunishTimelock, TxCancel, TxPunish, TxRedeem, TxRefund}; use swap::database::Database; use swap::env::{Config, GetConfig}; diff --git a/swap/tests/punish.rs b/swap/tests/punish.rs index 2b693d17..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::asb::event_loop::FixedRate; +use swap::asb::FixedRate; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob};