Skip to content

Commit

Permalink
optional secret manager choice
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Jan 16, 2024
1 parent aaa57c8 commit 467d9a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 3 additions & 4 deletions cli/src/command/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{
};

const DEFAULT_LOG_LEVEL: &str = "debug";
const DEFAULT_SECRET_MANAGER: &str = "stronghold";
const DEFAULT_NODE_URL: &str = "https://api.testnet.shimmer.network";
const DEFAULT_STRONGHOLD_SNAPSHOT_PATH: &str = "./stardust-cli-wallet.stronghold";
const DEFAULT_WALLET_DATABASE_PATH: &str = "./stardust-cli-wallet-db";
Expand Down Expand Up @@ -109,8 +108,8 @@ pub enum WalletCommand {
#[derive(Debug, Clone, Args)]
pub struct InitParameters {
/// Set the secret manager to use.
#[arg(short, long, value_name = "SECRET_MANAGER", default_value = DEFAULT_SECRET_MANAGER)]
pub secret_manager: SecretManagerChoice,
#[arg(short, long, value_name = "SECRET_MANAGER")]
pub secret_manager: Option<SecretManagerChoice>,
/// Set the path to the stronghold snapshot file. Ignored if the <SECRET_MANAGER> is not a Stronghold secret
/// manager.
#[arg(short = 't', long, value_name = "PATH", env = "STRONGHOLD_SNAPSHOT_PATH", default_value = DEFAULT_STRONGHOLD_SNAPSHOT_PATH)]
Expand All @@ -130,7 +129,7 @@ pub struct InitParameters {
impl Default for InitParameters {
fn default() -> Self {
Self {
secret_manager: SecretManagerChoice::Stronghold,
secret_manager: Some(SecretManagerChoice::Stronghold),
stronghold_snapshot_path: DEFAULT_STRONGHOLD_SNAPSHOT_PATH.to_string(),
mnemonic_file_path: None,
node_url: DEFAULT_NODE_URL.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub async fn check_file_exists(path: &Path) -> Result<(), Error> {
Ok(())
}

#[derive(Clone, Debug, clap::ValueEnum)]
#[derive(Copy, Clone, Debug, clap::ValueEnum)]
pub enum SecretManagerChoice {
Stronghold,
LedgerNano,
Expand Down
8 changes: 7 additions & 1 deletion cli/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ async fn create_initial_account(wallet: Wallet) -> Result<(Option<Wallet>, Optio
}

async fn create_secret_manager(init_params: &InitParameters) -> Result<SecretManager, Error> {
Ok(match select_secret_manager().await? {
let choice = if let Some(choice) = &init_params.secret_manager {
*choice
} else {
select_secret_manager().await?
};

Ok(match choice {
SecretManagerChoice::Stronghold => {
let snapshot_path = Path::new(&init_params.stronghold_snapshot_path);

Expand Down

0 comments on commit 467d9a6

Please sign in to comment.