Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit ec71225

Browse files
committed
add custom signer_from_path and signer_from_path_with_config
1 parent 414650d commit ec71225

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

token/cli/src/config.rs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ use {
44
solana_clap_v3_utils::{
55
input_parsers::{pubkey_of_signer, value_of},
66
input_validators::normalize_to_url_if_moniker,
7-
keypair::{signer_from_path, signer_from_path_with_config, SignerFromPathConfig},
7+
keypair::SignerFromPathConfig,
88
nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG},
9-
offline::{BLOCKHASH_ARG, DUMP_TRANSACTION_MESSAGE, SIGN_ONLY_ARG},
9+
offline::{BLOCKHASH_ARG, DUMP_TRANSACTION_MESSAGE, SIGNER_ARG, SIGN_ONLY_ARG},
1010
},
1111
solana_cli_output::OutputFormat,
1212
solana_client::nonblocking::rpc_client::RpcClient,
1313
solana_remote_wallet::remote_wallet::RemoteWalletManager,
1414
solana_sdk::{
1515
account::Account as RawAccount, commitment_config::CommitmentConfig, hash::Hash,
16-
pubkey::Pubkey, signature::Signer,
16+
pubkey::Pubkey, signature::Signer, signer::null_signer::NullSigner,
1717
},
1818
spl_associated_token_account::*,
1919
spl_token_2022::{
@@ -533,3 +533,43 @@ impl<'a> Config<'a> {
533533
}
534534
}
535535
}
536+
537+
// In clap v2, `value_of` returns `None` if the argument id is not previously specified in
538+
// `Arg`. In contrast, in clap v3, `value_of` panics in this case. Therefore, compared
539+
// to the same function in solana-clap-utils, `signer_from_path` in solana-clap-v3-utils errors
540+
// early when `path` is a valid pubkey, but `SIGNER_ARG.name` is not specified in the args.
541+
// This function behaves exactly as `signer_from_path` from solana-clap-utils by catching
542+
// this special case.
543+
fn signer_from_path(
544+
matches: &ArgMatches,
545+
path: &str,
546+
keypair_name: &str,
547+
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
548+
) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> {
549+
let config = SignerFromPathConfig::default();
550+
signer_from_path_with_config(matches, path, keypair_name, wallet_manager, &config)
551+
}
552+
553+
fn signer_from_path_with_config(
554+
matches: &ArgMatches,
555+
path: &str,
556+
keypair_name: &str,
557+
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
558+
config: &SignerFromPathConfig,
559+
) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> {
560+
if let Ok(pubkey) = Pubkey::from_str(path) {
561+
if matches.try_contains_id(SIGNER_ARG.name).is_err()
562+
&& (config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name)?)
563+
{
564+
return Ok(Box::new(NullSigner::new(&pubkey)));
565+
}
566+
}
567+
568+
solana_clap_v3_utils::keypair::signer_from_path_with_config(
569+
matches,
570+
path,
571+
keypair_name,
572+
wallet_manager,
573+
config,
574+
)
575+
}

0 commit comments

Comments
 (0)