From 578d23d7fc9d2f703e96384a2b3e911aaec176a6 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 25 Feb 2021 10:30:24 +1100 Subject: [PATCH] Proper encapsulation of wallet boundaries through private fields --- swap/src/monero/wallet.rs | 18 +++++++++++++++--- swap/tests/testutils/mod.rs | 16 ++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index 08fbb9c8..72226225 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -23,9 +23,9 @@ use url::Url; #[derive(Debug)] pub struct Wallet { - pub inner: Mutex, - pub network: Network, - pub default_wallet_name: String, + inner: Mutex, + network: Network, + default_wallet_name: String, } impl Wallet { @@ -37,6 +37,18 @@ impl Wallet { } } + pub fn new_with_client( + client: wallet::Client, + network: Network, + default_wallet_name: String, + ) -> Self { + Self { + inner: Mutex::new(client), + network, + default_wallet_name, + } + } + /// Get the balance of the primary account. pub async fn get_balance(&self) -> Result { let amount = self.inner.lock().await.get_balance(0).await?; diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index 8688083a..8210f566 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -27,11 +27,7 @@ use swap::{ }; use tempfile::tempdir; use testcontainers::{clients::Cli, Container, Docker, RunArgs}; -use tokio::{ - sync::{mpsc, Mutex}, - task::JoinHandle, - time::interval, -}; +use tokio::{sync::mpsc, task::JoinHandle, time::interval}; use tracing::dispatcher::DefaultGuard; use tracing_log::LogTracer; use url::Url; @@ -589,11 +585,11 @@ async fn init_test_wallets( .await .unwrap(); - let xmr_wallet = swap::monero::Wallet { - inner: Mutex::new(monero.wallet(name).unwrap().client()), - network: monero::Network::default(), - default_wallet_name: "irrelevant_for_tests".to_string(), - }; + let xmr_wallet = swap::monero::Wallet::new_with_client( + monero.wallet(name).unwrap().client(), + monero::Network::default(), + "irrelevant_for_tests".to_string(), + ); let electrum_rpc_url = { let input = format!("tcp://@localhost:{}", electrum_rpc_port);