Skip to content

Commit

Permalink
fix(console_wallet): use cli.non_interactive instead of propmt to sho…
Browse files Browse the repository at this point in the history
…w seed words (#4612)

Description
---

When starting a new console wallet with --password 'xxx' the seed words do not show. 

It's happen because of the property used to decide show or not the seed words its based on prompt instead of --non-interactive arg.

More detailed here: #4568

---

Closes #4568
  • Loading branch information
willyrgf committed Sep 5, 2022
1 parent 86c030d commit 8ad67ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
32 changes: 18 additions & 14 deletions applications/tari_console_wallet/src/init/mod.rs
Expand Up @@ -118,8 +118,9 @@ pub async fn change_password(
config: &ApplicationConfig,
arg_password: Option<SafePassword>,
shutdown_signal: ShutdownSignal,
non_interactive_mode: bool,
) -> Result<(), ExitError> {
let mut wallet = init_wallet(config, arg_password, None, None, shutdown_signal).await?;
let mut wallet = init_wallet(config, arg_password, None, None, shutdown_signal, non_interactive_mode).await?;

let passphrase = prompt_password("New wallet password: ")?;
let confirmed = prompt_password("Confirm new password: ")?;
Expand Down Expand Up @@ -248,6 +249,7 @@ pub async fn init_wallet(
seed_words_file_name: Option<PathBuf>,
recovery_seed: Option<CipherSeed>,
shutdown_signal: ShutdownSignal,
non_interactive_mode: bool,
) -> Result<WalletSqlite, ExitError> {
fs::create_dir_all(
&config
Expand Down Expand Up @@ -359,27 +361,29 @@ pub async fn init_wallet(
debug!(target: LOG_TARGET, "Wallet is not encrypted.");

// create using --password arg if supplied and skip seed words confirmation
let (passphrase, interactive) = if let Some(password) = arg_password {
debug!(target: LOG_TARGET, "Setting password from command line argument.");

(password, false)
} else {
debug!(target: LOG_TARGET, "Prompting for password.");
let password = prompt_password("Create wallet password: ")?;
let confirmed = prompt_password("Confirm wallet password: ")?;
let passphrase = match arg_password {
Some(password) => {
debug!(target: LOG_TARGET, "Setting password from command line argument.");
password
},
None => {
debug!(target: LOG_TARGET, "Prompting for password.");
let password = prompt_password("Create wallet password: ")?;
let confirmed = prompt_password("Confirm wallet password: ")?;

if password != confirmed {
return Err(ExitError::new(ExitCode::InputError, "Passwords don't match!"));
}
if password != confirmed {
return Err(ExitError::new(ExitCode::InputError, "Passwords don't match!"));
}

(password, true)
password
},
};

wallet.apply_encryption(passphrase).await?;

debug!(target: LOG_TARGET, "Wallet encrypted.");

if interactive && recovery_seed.is_none() {
if !non_interactive_mode && recovery_seed.is_none() {
match confirm_seed_words(&mut wallet) {
Ok(()) => {
print!("\x1Bc"); // Clear the screen
Expand Down
25 changes: 17 additions & 8 deletions applications/tari_console_wallet/src/main.rs
Expand Up @@ -47,6 +47,7 @@ use tari_key_manager::cipher_seed::CipherSeed;
#[cfg(all(unix, feature = "libtor"))]
use tari_libtor::tor::Tor;
use tari_shutdown::Shutdown;
use tari_utilities::SafePassword;
use tracing_subscriber::{layer::SubscriberExt, Registry};
use wallet_modes::{command_mode, grpc_mode, recovery_mode, script_mode, tui_mode, WalletMode};

Expand Down Expand Up @@ -92,8 +93,7 @@ fn main() {
fn main_inner() -> Result<(), ExitError> {
let cli = Cli::parse();

let config_path = cli.common.config_path();
let cfg = load_configuration(config_path.as_path(), true, &cli)?;
let cfg = load_configuration(cli.common.config_path().as_path(), true, &cli)?;
initialize_logging(
&cli.common.log_config_path("wallet"),
include_str!("../log4rs_sample.yml"),
Expand All @@ -118,11 +118,7 @@ fn main_inner() -> Result<(), ExitError> {
consts::APP_VERSION
);

let password = cli
.password
.as_ref()
.or(config.wallet.password.as_ref())
.map(|s| s.to_owned());
let password = get_password(&config, &cli);

if password.is_none() {
tari_splash_screen("Console Wallet");
Expand All @@ -141,7 +137,12 @@ fn main_inner() -> Result<(), ExitError> {

if cli.change_password {
info!(target: LOG_TARGET, "Change password requested.");
return runtime.block_on(change_password(&config, password, shutdown_signal));
return runtime.block_on(change_password(
&config,
password,
shutdown_signal,
cli.non_interactive_mode,
));
}

// Run our own Tor instance, if configured
Expand All @@ -164,6 +165,7 @@ fn main_inner() -> Result<(), ExitError> {
seed_words_file_name,
recovery_seed,
shutdown_signal,
cli.non_interactive_mode,
))?;

// Check if there is an in progress recovery in the wallet's database
Expand Down Expand Up @@ -219,6 +221,13 @@ fn main_inner() -> Result<(), ExitError> {
result
}

fn get_password(config: &ApplicationConfig, cli: &Cli) -> Option<SafePassword> {
cli.password
.as_ref()
.or(config.wallet.password.as_ref())
.map(|s| s.to_owned())
}

fn get_recovery_seed(boot_mode: WalletBoot, cli: &Cli) -> Result<Option<CipherSeed>, ExitError> {
if matches!(boot_mode, WalletBoot::Recovery) {
let seed = if cli.seed_words.is_some() {
Expand Down

0 comments on commit 8ad67ab

Please sign in to comment.