Skip to content

Commit

Permalink
fix: wallet seed_words command is broken (see issue #4363) (#4370)
Browse files Browse the repository at this point in the history
Description
---
#4363

Motivation and Context
---
Seed word command is broken on GRPC

` thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs:1210:50`

How Has This Been Tested?
---
  • Loading branch information
agubarev authored Aug 2, 2022
1 parent 1c5ec0d commit 1cabd70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
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();
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?;
Ok(())
}

Expand Down

0 comments on commit 1cabd70

Please sign in to comment.