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]
pub trait CreateWalletForOutputThenLoadDefaultWallet {
async fn create_and_load_wallet_for_output_then_load_default_wallet(
pub trait CreateWalletForOutputThenReloadWallet {
async fn create_and_load_wallet_for_output_then_reload_wallet(
&self,
private_spend_key: PrivateKey,
private_view_key: PrivateViewKey,

View File

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

View File

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