From 82974412b2a3e5bff807b04caaad19e294012dfb Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Tue, 19 Jan 2021 09:43:50 +1100 Subject: [PATCH] Remove roles from SwapFactory name as implied by module and cleanup --- swap/src/main.rs | 10 +++++----- swap/src/protocol/alice.rs | 18 +++++++++--------- swap/src/protocol/bob.rs | 23 +++++++++++------------ swap/tests/testutils/mod.rs | 15 +++++---------- 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/swap/src/main.rs b/swap/src/main.rs index 891c7954..5c66b952 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -23,7 +23,7 @@ use swap::{ config::Config, database::Database, monero, - protocol::{alice, bob, bob::BobSwapFactory}, + protocol::{alice, bob, bob::SwapFactory}, trace::init_tracing, StartingBalances, SwapAmounts, }; @@ -82,7 +82,7 @@ async fn main() -> Result<()> { send_monero, receive_bitcoin, swap_id ); - let alice_factory = alice::AliceSwapFactory::new( + let alice_factory = alice::SwapFactory::new( seed, config, swap_id, @@ -127,7 +127,7 @@ async fn main() -> Result<()> { send_bitcoin, receive_monero, swap_id ); - let bob_factory = BobSwapFactory::new( + let bob_factory = SwapFactory::new( seed, db_path, swap_id, @@ -172,7 +172,7 @@ async fn main() -> Result<()> { ) .await?; - let alice_factory = alice::AliceSwapFactory::new( + let alice_factory = alice::SwapFactory::new( seed, config, swap_id, @@ -204,7 +204,7 @@ async fn main() -> Result<()> { ) .await?; - let bob_factory = BobSwapFactory::new( + let bob_factory = SwapFactory::new( seed, db_path, swap_id, diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index 04ff737b..7d801ef1 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -50,21 +50,21 @@ pub struct Swap { pub db: Database, } -pub struct AliceSwapFactory { - listen_address: Multiaddr, +pub struct SwapFactory { + swap_id: Uuid, identity: Keypair, peer_id: PeerId, - db_path: PathBuf, - swap_id: Uuid, + config: Config, + + listen_address: Multiaddr, pub bitcoin_wallet: Arc, pub monero_wallet: Arc, - config: Config, pub starting_balances: StartingBalances, } -impl AliceSwapFactory { +impl SwapFactory { #[allow(clippy::too_many_arguments)] pub async fn new( seed: Seed, @@ -81,14 +81,14 @@ impl AliceSwapFactory { let peer_id = PeerId::from(identity.public()); Self { - listen_address, + swap_id, identity, peer_id, db_path, - swap_id, + config, + listen_address, bitcoin_wallet, monero_wallet, - config, starting_balances, } } diff --git a/swap/src/protocol/bob.rs b/swap/src/protocol/bob.rs index 25b35f79..906eb80f 100644 --- a/swap/src/protocol/bob.rs +++ b/swap/src/protocol/bob.rs @@ -47,23 +47,22 @@ pub struct Swap { pub swap_id: Uuid, } -pub struct BobSwapFactory { +pub struct SwapFactory { + swap_id: Uuid, identity: Keypair, peer_id: PeerId, - db_path: PathBuf, - swap_id: Uuid, - - pub bitcoin_wallet: Arc, - pub monero_wallet: Arc, config: Config, - pub starting_balances: StartingBalances, alice_connect_address: Multiaddr, alice_connect_peer_id: PeerId, + + pub bitcoin_wallet: Arc, + pub monero_wallet: Arc, + pub starting_balances: StartingBalances, } -impl BobSwapFactory { +impl SwapFactory { #[allow(clippy::too_many_arguments)] pub fn new( seed: Seed, @@ -80,16 +79,16 @@ impl BobSwapFactory { let peer_id = identity.public().into_peer_id(); Self { + swap_id, identity, peer_id, db_path, - swap_id, - bitcoin_wallet, - monero_wallet, config, - starting_balances, alice_connect_address, alice_connect_peer_id, + bitcoin_wallet, + monero_wallet, + starting_balances, } } diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index b0938705..24cb9eb5 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -9,12 +9,7 @@ use swap::{ bitcoin, config::Config, monero, - protocol::{ - alice, - alice::{AliceState, AliceSwapFactory}, - bob, - bob::{BobState, BobSwapFactory}, - }, + protocol::{alice, alice::AliceState, bob, bob::BobState}, seed::Seed, StartingBalances, SwapAmounts, }; @@ -27,8 +22,8 @@ use uuid::Uuid; pub struct Test { swap_amounts: SwapAmounts, - alice_swap_factory: AliceSwapFactory, - bob_swap_factory: BobSwapFactory, + alice_swap_factory: alice::SwapFactory, + bob_swap_factory: bob::SwapFactory, } impl Test { @@ -344,7 +339,7 @@ where ) .await; - let alice_swap_factory = AliceSwapFactory::new( + let alice_swap_factory = alice::SwapFactory::new( Seed::random().unwrap(), config, Uuid::new_v4(), @@ -370,7 +365,7 @@ where ) .await; - let bob_swap_factory = BobSwapFactory::new( + let bob_swap_factory = bob::SwapFactory::new( Seed::random().unwrap(), tempdir().unwrap().path().to_path_buf(), Uuid::new_v4(),