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 2 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
10 changes: 10 additions & 0 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ 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| match parse_keypair_path(&arg.into()) {
KeypairUrl::Usb(_) => true,
_ => false,
})
}

pub fn presigner_from_pubkey_sigs(
pubkey: &Pubkey,
signers: &[(Pubkey, Signature)],
Expand Down
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