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

Tame overeager wallet manager #9262

Merged
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
23 changes: 23 additions & 0 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ pub fn parse_keypair_path(path: &str) -> KeypairUrl {
}
}

pub fn check_for_usb<S>(mut items: impl Iterator<Item = S>) -> bool
where
S: Into<String>,
{
items.any(|arg| matches!(parse_keypair_path(&arg.into()), KeypairUrl::Usb(_)))
}

pub fn presigner_from_pubkey_sigs(
pubkey: &Pubkey,
signers: &[(Pubkey, Signature)],
Expand Down Expand Up @@ -256,4 +263,20 @@ mod tests {
sanitize_seed_phrase(seed_phrase)
);
}

#[test]
fn test_check_for_usb() {
let args: Vec<&str> = vec![];
assert_eq!(check_for_usb(args.into_iter()), false);
let args = vec!["usb://"];
assert_eq!(check_for_usb(args.into_iter()), true);
let args = vec!["other"];
assert_eq!(check_for_usb(args.into_iter()), false);
let args = vec!["other", "usb://", "another"];
assert_eq!(check_for_usb(args.into_iter()), true);
let args = vec!["other", "another"];
assert_eq!(check_for_usb(args.into_iter()), false);
let args = vec!["usb://", "usb://"];
assert_eq!(check_for_usb(args.into_iter()), true);
}
}
18 changes: 14 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use clap::{crate_description, crate_name, AppSettings, Arg, ArgGroup, ArgMatches
use console::style;

use solana_clap_utils::{
input_validators::is_url, keypair::SKIP_SEED_PHRASE_VALIDATION_ARG, offline::SIGN_ONLY_ARG,
input_validators::is_url,
keypair::{check_for_usb, SKIP_SEED_PHRASE_VALIDATION_ARG},
offline::SIGN_ONLY_ARG,
DisplayError,
};
use solana_cli::{
Expand Down Expand Up @@ -233,12 +235,20 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.get_matches();

do_main(&matches).map_err(|err| DisplayError::new_as_boxed(err).into())
do_main(&matches, check_for_usb(std::env::args()))
.map_err(|err| DisplayError::new_as_boxed(err).into())
}

fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
fn do_main(
matches: &ArgMatches<'_>,
need_wallet_manager: bool,
) -> Result<(), Box<dyn error::Error>> {
if parse_settings(&matches)? {
let wallet_manager = maybe_wallet_manager()?;
let wallet_manager = if need_wallet_manager {
maybe_wallet_manager()?
} else {
None
};

let (mut config, signers) = parse_args(&matches, wallet_manager)?;
config.signers = signers.iter().map(|s| s.as_ref()).collect();
Expand Down
8 changes: 6 additions & 2 deletions keygen/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use num_cpus;
use solana_clap_utils::{
input_validators::is_derivation,
keypair::{
keypair_from_seed_phrase, prompt_passphrase, signer_from_path,
check_for_usb, keypair_from_seed_phrase, prompt_passphrase, signer_from_path,
SKIP_SEED_PHRASE_VALIDATION_ARG,
},
DisplayError,
Expand Down Expand Up @@ -407,7 +407,11 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
Config::default()
};

let wallet_manager = maybe_wallet_manager()?;
let wallet_manager = if check_for_usb(std::env::args()) {
maybe_wallet_manager()?
} else {
None
};

match matches.subcommand() {
("pubkey", Some(matches)) => {
Expand Down