Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wallet seed_words command is broken (see issue #4363) #4370

Merged
merged 3 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::{
convert::{TryFrom, TryInto},
fs,
path::PathBuf,
};

use clap::Parser;
Expand Down Expand Up @@ -1240,47 +1241,38 @@ impl wallet_server::Wallet for WalletGrpcServer {
}
}

/// Returns the contents of a seed words file, provided via CLI
async fn seed_words(&self, _: Request<tari_rpc::Empty>) -> Result<Response<SeedWordsResponse>, Status> {
let cli = Cli::parse();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Cli::parse should (ideally) not be used in GRPC, rather the ApplicationConfig should be made available to the GRPC server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, a good idea

let file_path = cli.seed_words_file_name.unwrap();

if !file_path.is_file() {
return Err(Status::not_found("file not found"));
}

let file_name = file_path.clone().into_os_string().into_string().unwrap();

if file_name.is_empty() {
return Err(Status::not_found("seed_words_file_name is empty"));
}
let filepath: PathBuf = match cli.seed_words_file_name {
Some(filepath) => filepath,
None => return Err(Status::not_found("file path is empty")),
};

let contents = fs::read_to_string(file_path)?;
let words = contents
let words = fs::read_to_string(filepath)?
.split(' ')
.collect::<Vec<&str>>()
.iter()
.map(|&x| x.into())
.collect::<Vec<String>>();

Ok(Response::new(SeedWordsResponse { words }))
}

/// Deletes the seed words file, provided via CLI
async fn delete_seed_words_file(
&self,
_: Request<tari_rpc::Empty>,
) -> Result<Response<FileDeletedResponse>, Status> {
let cli = Cli::parse();
let file_path = cli.seed_words_file_name.unwrap();

if !file_path.is_file() {
return Err(Status::not_found("file not found"));
}

let file_name = file_path.clone().into_os_string().into_string().unwrap();
// WARNING: the filepath used is supplied as an argument
fs::remove_file(match cli.seed_words_file_name {
Some(filepath) => filepath,
None => return Err(Status::not_found("file path is empty")),
})?;

if file_name.is_empty() {
return Err(Status::not_found("seed_words_file_name is empty"));
}
fs::remove_file(file_path)?;
Ok(Response::new(FileDeletedResponse {}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,10 @@ where
/// Remove encryption from all the Wallet db backends. If any backends do not have encryption applied then this will
/// fail
pub async fn remove_encryption(&mut self) -> Result<(), WalletError> {
self.db.remove_encryption().await?;
self.output_manager_service.remove_encryption().await?;
self.transaction_service.remove_encryption().await?;
self.key_manager_service.remove_encryption().await?;
self.db.remove_encryption().await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rather not sneak this in :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been waiting for another PR for days, you got me :)

Ok(())
}

Expand Down