Tame wallet manager better (#9567)

automerge
This commit is contained in:
Tyera Eulberg
2020-04-18 12:54:21 -06:00
committed by GitHub
parent a7aa7e172b
commit 679e7863cb
12 changed files with 214 additions and 234 deletions

View File

@@ -8,13 +8,13 @@ use num_cpus;
use solana_clap_utils::{
input_validators::is_derivation,
keypair::{
check_for_usb, keypair_from_seed_phrase, prompt_passphrase, signer_from_path,
keypair_from_seed_phrase, prompt_passphrase, signer_from_path,
SKIP_SEED_PHRASE_VALIDATION_ARG,
},
DisplayError,
};
use solana_cli_config::{Config, CONFIG_FILE};
use solana_remote_wallet::remote_wallet::{maybe_wallet_manager, RemoteWalletManager};
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::{
instruction::{AccountMeta, Instruction},
message::Message,
@@ -53,7 +53,7 @@ fn check_for_overwrite(outfile: &str, matches: &ArgMatches) {
fn get_keypair_from_matches(
matches: &ArgMatches,
config: Config,
wallet_manager: Option<Arc<RemoteWalletManager>>,
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
) -> Result<Box<dyn Signer>, Box<dyn error::Error>> {
let mut path = dirs::home_dir().expect("home directory");
let path = if matches.is_present("keypair") {
@@ -64,7 +64,7 @@ fn get_keypair_from_matches(
path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap()
};
signer_from_path(matches, path, "pubkey recovery", wallet_manager.as_ref())
signer_from_path(matches, path, "pubkey recovery", wallet_manager)
}
fn output_keypair(
@@ -407,16 +407,12 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
Config::default()
};
let wallet_manager =
if check_for_usb(std::env::args()) || check_for_usb([config.keypair_path.clone()].iter()) {
maybe_wallet_manager()?
} else {
None
};
let mut wallet_manager = None;
match matches.subcommand() {
("pubkey", Some(matches)) => {
let pubkey = get_keypair_from_matches(matches, config, wallet_manager)?.try_pubkey()?;
let pubkey =
get_keypair_from_matches(matches, config, &mut wallet_manager)?.try_pubkey()?;
if matches.is_present("outfile") {
let outfile = matches.value_of("outfile").unwrap();
@@ -606,7 +602,7 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
}
}
("verify", Some(matches)) => {
let keypair = get_keypair_from_matches(matches, config, wallet_manager)?;
let keypair = get_keypair_from_matches(matches, config, &mut wallet_manager)?;
let simple_message = Message::new(&[Instruction::new(
Pubkey::default(),
&0,