From 0945cee459aeae17f3e7234ec3aa49cb26293c5d Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 25 Feb 2021 10:34:22 +1100 Subject: [PATCH] Remove traits in favour of public functions --- swap/src/bin/asb.rs | 2 +- swap/src/bin/swap_cli.rs | 2 +- swap/src/monero/wallet.rs | 39 +++++++++++++-------------------- swap/src/protocol/alice/swap.rs | 2 +- swap/src/protocol/bob/swap.rs | 2 +- swap/tests/testutils/mod.rs | 1 - 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index d63246fa..ed985d47 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -31,7 +31,7 @@ use swap::{ execution_params::GetExecutionParams, fs::default_config_path, monero, - monero::{Amount, CreateWallet, GetAddress, OpenWallet}, + monero::{Amount, CreateWallet, OpenWallet}, protocol::alice::EventLoop, seed::Seed, trace::init_tracing, diff --git a/swap/src/bin/swap_cli.rs b/swap/src/bin/swap_cli.rs index 2efffb3f..4b13e6ba 100644 --- a/swap/src/bin/swap_cli.rs +++ b/swap/src/bin/swap_cli.rs @@ -30,7 +30,7 @@ use swap::{ execution_params::GetExecutionParams, fs::default_config_path, monero, - monero::{CreateWallet, OpenWallet, WalletBlockHeight}, + monero::{CreateWallet, OpenWallet}, protocol::{ bob, bob::{cancel::CancelError, Builder}, diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index 72226225..c8e3577d 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -1,7 +1,7 @@ use crate::monero::{ Amount, CreateWallet, CreateWalletForOutput, CreateWalletForOutputThenLoadDefaultWallet, - GetAddress, InsufficientFunds, OpenWallet, PrivateViewKey, PublicViewKey, Refresh, Transfer, - TransferProof, TxHash, WalletBlockHeight, WatchForTransfer, + InsufficientFunds, OpenWallet, PrivateViewKey, PublicViewKey, Transfer, TransferProof, TxHash, + WatchForTransfer, }; use ::monero::{Address, Network, PrivateKey, PublicKey}; use anyhow::Result; @@ -55,6 +55,19 @@ impl Wallet { Ok(Amount::from_piconero(amount)) } + + pub async fn block_height(&self) -> Result { + self.inner.lock().await.block_height().await + } + + pub async fn get_main_address(&self) -> Result
{ + let address = self.inner.lock().await.get_address(0).await?; + Ok(Address::from_str(address.address.as_str())?) + } + + pub async fn refresh(&self) -> Result { + self.inner.lock().await.refresh().await + } } #[async_trait] @@ -233,25 +246,3 @@ impl WatchForTransfer for Wallet { Ok(()) } } - -#[async_trait] -impl WalletBlockHeight for Wallet { - async fn block_height(&self) -> Result { - self.inner.lock().await.block_height().await - } -} - -#[async_trait] -impl GetAddress for Wallet { - async fn get_main_address(&self) -> Result
{ - let address = self.inner.lock().await.get_address(0).await?; - Ok(Address::from_str(address.address.as_str())?) - } -} - -#[async_trait] -impl Refresh for Wallet { - async fn refresh(&self) -> Result { - self.inner.lock().await.refresh().await - } -} diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index e233c1e7..55484983 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -10,7 +10,7 @@ use crate::{ database::Database, execution_params::ExecutionParams, monero, - monero::{CreateWalletForOutputThenLoadDefaultWallet, WalletBlockHeight}, + monero::CreateWalletForOutputThenLoadDefaultWallet, monero_ext::ScalarExt, protocol::{ alice, diff --git a/swap/src/protocol/bob/swap.rs b/swap/src/protocol/bob/swap.rs index 485e8f74..29cac4e8 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -4,7 +4,7 @@ use crate::{ database::{Database, Swap}, execution_params::ExecutionParams, monero, - monero::{InsufficientFunds, WalletBlockHeight}, + monero::InsufficientFunds, protocol::bob::{self, event_loop::EventLoopHandle, state::*, QuoteRequest}, }; use anyhow::{bail, Result}; diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index 8210f566..646a3cc4 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -21,7 +21,6 @@ use swap::{ execution_params, execution_params::{ExecutionParams, GetExecutionParams}, monero, - monero::Refresh, protocol::{alice, alice::AliceState, bob, bob::BobState}, seed::Seed, };