Harmonize names to make more sense

The wallet is an instance of a wallet that has a name.
When we use `CreateWalletForOutputThenReloadWallet` we actually unload the wallet.
It would be cleaner to create a new instance that does that swap, but I did not go that far.
This commit is contained in:
Daniel Karzel 2021-03-02 19:42:23 +11:00
parent 70494fcb4f
commit 9f53dab3c6
3 changed files with 15 additions and 21 deletions

View File

@ -229,8 +229,8 @@ pub trait CreateWalletForOutput {
} }
#[async_trait] #[async_trait]
pub trait CreateWalletForOutputThenLoadDefaultWallet { pub trait CreateWalletForOutputThenReloadWallet {
async fn create_and_load_wallet_for_output_then_load_default_wallet( async fn create_and_load_wallet_for_output_then_reload_wallet(
&self, &self,
private_spend_key: PrivateKey, private_spend_key: PrivateKey,
private_view_key: PrivateViewKey, private_view_key: PrivateViewKey,

View File

@ -1,5 +1,5 @@
use crate::monero::{ use crate::monero::{
Amount, CreateWallet, CreateWalletForOutput, CreateWalletForOutputThenLoadDefaultWallet, Amount, CreateWallet, CreateWalletForOutput, CreateWalletForOutputThenReloadWallet,
InsufficientFunds, OpenWallet, PrivateViewKey, PublicViewKey, Transfer, TransferProof, TxHash, InsufficientFunds, OpenWallet, PrivateViewKey, PublicViewKey, Transfer, TransferProof, TxHash,
WatchForTransfer, WatchForTransfer,
}; };
@ -21,27 +21,23 @@ use url::Url;
pub struct Wallet { pub struct Wallet {
inner: Mutex<wallet::Client>, inner: Mutex<wallet::Client>,
network: Network, network: Network,
default_wallet_name: String, name: String,
} }
impl Wallet { impl Wallet {
pub fn new(url: Url, network: Network, default_wallet_name: String) -> Self { pub fn new(url: Url, network: Network, name: String) -> Self {
Self { Self {
inner: Mutex::new(wallet::Client::new(url)), inner: Mutex::new(wallet::Client::new(url)),
network, network,
default_wallet_name, name,
} }
} }
pub fn new_with_client( pub fn new_with_client(client: wallet::Client, network: Network, name: String) -> Self {
client: wallet::Client,
network: Network,
default_wallet_name: String,
) -> Self {
Self { Self {
inner: Mutex::new(client), inner: Mutex::new(client),
network, network,
default_wallet_name, name,
} }
} }
@ -133,8 +129,8 @@ impl CreateWalletForOutput for Wallet {
} }
#[async_trait] #[async_trait]
impl CreateWalletForOutputThenLoadDefaultWallet for Wallet { impl CreateWalletForOutputThenReloadWallet for Wallet {
async fn create_and_load_wallet_for_output_then_load_default_wallet( async fn create_and_load_wallet_for_output_then_reload_wallet(
&self, &self,
private_spend_key: PrivateKey, private_spend_key: PrivateKey,
private_view_key: PrivateViewKey, private_view_key: PrivateViewKey,
@ -156,9 +152,7 @@ impl CreateWalletForOutputThenLoadDefaultWallet for Wallet {
) )
.await?; .await?;
let _ = wallet let _ = wallet.open_wallet(self.name.as_str()).await?;
.open_wallet(self.default_wallet_name.as_str())
.await?;
Ok(()) Ok(())
} }
@ -170,7 +164,7 @@ impl OpenWallet for Wallet {
self.inner self.inner
.lock() .lock()
.await .await
.open_wallet(self.default_wallet_name.as_str()) .open_wallet(self.name.as_str())
.await?; .await?;
Ok(()) Ok(())
} }
@ -182,7 +176,7 @@ impl CreateWallet for Wallet {
self.inner self.inner
.lock() .lock()
.await .await
.create_wallet(self.default_wallet_name.as_str()) .create_wallet(self.name.as_str())
.await?; .await?;
Ok(()) Ok(())
} }

View File

@ -7,7 +7,7 @@ use crate::{
database::Database, database::Database,
execution_params::ExecutionParams, execution_params::ExecutionParams,
monero, monero,
monero::CreateWalletForOutputThenLoadDefaultWallet, monero::CreateWalletForOutputThenReloadWallet,
monero_ext::ScalarExt, monero_ext::ScalarExt,
protocol::{ protocol::{
alice, alice,
@ -392,7 +392,7 @@ async fn run_until_internal(
let view_key = state3.v; let view_key = state3.v;
monero_wallet monero_wallet
.create_and_load_wallet_for_output_then_load_default_wallet( .create_and_load_wallet_for_output_then_reload_wallet(
spend_key, spend_key,
view_key, view_key,
monero_wallet_restore_blockheight, monero_wallet_restore_blockheight,