Skip to content

Commit

Permalink
Merge pull request #2781 from dusk-network/2682/profile-wallet-flag
Browse files Browse the repository at this point in the history
rusk-wallet: Rename --profile flag to --wallet-dir
  • Loading branch information
HDauven authored Oct 28, 2024
2 parents 6ff3b30 + d5bba7d commit 4f267cf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
2 changes: 2 additions & 0 deletions rusk-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Split `prove_and_propagate` into `prove` and `propagate` [#2708]
- Unify `sndr_idx` and `profile_idx` fields in `Command` enum [#2702]
- Rename `--profile` flag to `--wallet-dir` [#2682]
- Change Rusk wallet name and version information [#2647]
- Update Clap from v3 to workspace v4 [#2489]

Expand All @@ -30,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[#2708]: https://github.com/dusk-network/rusk/issues/2708
[#2702]: https://github.com/dusk-network/rusk/issues/2702
[#2682]: https://github.com/dusk-network/rusk/issues/2682
[#2659]: https://github.com/dusk-network/rusk/issues/2659
[#2647]: https://github.com/dusk-network/rusk/issues/2647
[#2566]: https://github.com/dusk-network/rusk/issues/2566
Expand Down
8 changes: 4 additions & 4 deletions rusk-wallet/src/bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ USAGE:
rusk-wallet [OPTIONS] [SUBCOMMAND]
OPTIONS:
-p, --profile <PROFILE> Directory to store user data [default: `$HOME/.dusk/rusk-wallet`]
-w, --wallet-dir <WALLET_PATH> Directory to store user data [default: `$HOME/.dusk/rusk-wallet`]
-n, --network <NETWORK> Network to connect to
--password <PASSWORD> Set the password for wallet's creation [env:
RUSK_WALLET_PWD=password]
Expand Down Expand Up @@ -71,12 +71,12 @@ The default settings can be seen [here](https://github.com/dusk-network/rusk/blo
It's possible to override those settings by create a `config.toml` file with the same structure, in one of the following
directory:

- The profile folder (provided via the `--profile` argument, defaults to `$HOME/.dusk/rusk-wallet/`)
- The wallet directory (provided via the `--wallet-dir` argument, defaults to `$HOME/.dusk/rusk-wallet/`)
- The global configuration folder (`$HOME/.config/rusk-wallet/`)

Having the `config.toml` in the global configuration folder is useful in case of multiple wallets (each one with its own profile folder) that shares the same settings.
Having the `config.toml` in the global configuration folder is useful in case of multiple wallets (each one with its own wallet directory) that shares the same settings.

If a `config.toml` exists in both locations, the one found in the profile folder will be used.
If a `config.toml` exists in both locations, the one found in the specified wallet directory will be used.

The CLI arguments takes precedence and overrides any configuration present in the configuration file.

Expand Down
10 changes: 8 additions & 2 deletions rusk-wallet/src/bin/interactive/command_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ pub(crate) fn online(
MenuItem::Export => ProfileOp::Run(Box::new(Command::Export {
profile_idx: Some(profile_idx),
name: None,
dir: prompt::request_dir("export keys", settings.profile.clone())?,
dir: prompt::request_dir(
"export keys",
settings.wallet_dir.clone(),
)?,
})),
MenuItem::Back => ProfileOp::Back,
};
Expand Down Expand Up @@ -248,7 +251,10 @@ pub(crate) fn offline(
MenuItem::Export => ProfileOp::Run(Box::new(Command::Export {
profile_idx: Some(profile_idx),
name: None,
dir: prompt::request_dir("export keys", settings.profile.clone())?,
dir: prompt::request_dir(
"export keys",
settings.wallet_dir.clone(),
)?,
})),
MenuItem::Back => ProfileOp::Back,
_ => unreachable!(),
Expand Down
2 changes: 1 addition & 1 deletion rusk-wallet/src/bin/io/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::path::PathBuf;
pub(crate) struct WalletArgs {
/// Directory to store user data [default: `$HOME/.dusk/rusk-wallet`]
#[arg(short, long)]
pub profile: Option<PathBuf>,
pub wallet_dir: Option<PathBuf>,

/// Network to connect to
#[arg(short, long)]
Expand Down
12 changes: 6 additions & 6 deletions rusk-wallet/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where

let msg = match e.kind() {
ErrorKind::InvalidArgument => {
format!("You seem to try access a wallet with a different seed-phrase \n\r\n\r{0: <1} delete the cache? (Alternatively specify the --profile flag to add a new wallet under the given path)", "[ALERT]")
format!("You seem to try access a wallet with a different seed-phrase \n\r\n\r{0: <1} delete the cache? (Alternatively specify the --wallet-dir flag to add a new wallet under the given path)", "[ALERT]")
},
ErrorKind::Corruption => {
format!("The database appears to be corrupted \n\r\n\r{0: <1} delete the cache?", "[ALERT]")
Expand Down Expand Up @@ -139,17 +139,17 @@ async fn exec() -> anyhow::Result<()> {
// Get the initial settings from the args
let settings_builder = Settings::args(args);

// Obtain the profile dir from the settings
let profile_folder = settings_builder.profile().clone();
// Obtain the wallet dir from the settings
let wallet_dir = settings_builder.wallet_dir().clone();

fs::create_dir_all(profile_folder.as_path())?;
fs::create_dir_all(wallet_dir.as_path())?;

// prepare wallet path
let mut wallet_path =
WalletPath::from(profile_folder.as_path().join("wallet.dat"));
WalletPath::from(wallet_dir.as_path().join("wallet.dat"));

// load configuration (or use default)
let cfg = Config::load(&profile_folder)?;
let cfg = Config::load(&wallet_dir)?;

wallet_path.set_network_name(settings_builder.args.network.clone());

Expand Down
19 changes: 10 additions & 9 deletions rusk-wallet/src/bin/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ pub(crate) struct Settings {

pub(crate) logging: Logging,

pub(crate) profile: PathBuf,
pub(crate) wallet_dir: PathBuf,
pub(crate) password: Option<String>,
}

pub(crate) struct SettingsBuilder {
profile: PathBuf,
wallet_dir: PathBuf,
pub(crate) args: WalletArgs,
}

impl SettingsBuilder {
pub fn profile(&self) -> &PathBuf {
&self.profile
pub fn wallet_dir(&self) -> &PathBuf {
&self.wallet_dir
}

pub fn network(self, network: Network) -> Result<Settings, Error> {
Expand Down Expand Up @@ -101,7 +101,8 @@ impl SettingsBuilder {

let explorer = network.explorer;

let profile = args.profile.as_ref().cloned().unwrap_or(self.profile);
let wallet_dir =
args.wallet_dir.as_ref().cloned().unwrap_or(self.wallet_dir);

let password = args.password;

Expand All @@ -115,15 +116,15 @@ impl SettingsBuilder {
prover,
explorer,
logging,
profile,
wallet_dir,
password,
})
}
}

impl Settings {
pub fn args(args: WalletArgs) -> SettingsBuilder {
let profile = if let Some(path) = &args.profile {
let wallet_dir = if let Some(path) = &args.wallet_dir {
path.clone()
} else {
let mut path = dirs::home_dir().expect("OS not supported");
Expand All @@ -132,7 +133,7 @@ impl Settings {
path
};

SettingsBuilder { profile, args }
SettingsBuilder { wallet_dir, args }
}
}

Expand Down Expand Up @@ -190,7 +191,7 @@ impl fmt::Display for Settings {
writeln!(f, "{separator}")?;
writeln!(f, "Settings")?;
writeln!(f, "{separator}")?;
writeln!(f, "Profile: {}", self.profile.display())?;
writeln!(f, "Wallet directory: {}", self.wallet_dir.display())?;
writeln!(
f,
"Password: {}",
Expand Down

0 comments on commit 4f267cf

Please sign in to comment.