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

Commit 6779d26

Browse files
committed
add custom signer_from_path and signer_from_path_with_config
1 parent ea67826 commit 6779d26

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_client::address::get_associated_token_address_with_program_id,
1919
spl_token_2022::{
@@ -560,3 +560,43 @@ impl<'a> Config<'a> {
560560
}
561561
}
562562
}
563+
564+
// In clap v2, `value_of` returns `None` if the argument id is not previously specified in
565+
// `Arg`. In contrast, in clap v3, `value_of` panics in this case. Therefore, compared
566+
// to the same function in solana-clap-utils, `signer_from_path` in solana-clap-v3-utils errors
567+
// early when `path` is a valid pubkey, but `SIGNER_ARG.name` is not specified in the args.
568+
// This function behaves exactly as `signer_from_path` from solana-clap-utils by catching
569+
// this special case.
570+
fn signer_from_path(
571+
matches: &ArgMatches,
572+
path: &str,
573+
keypair_name: &str,
574+
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
575+
) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> {
576+
let config = SignerFromPathConfig::default();
577+
signer_from_path_with_config(matches, path, keypair_name, wallet_manager, &config)
578+
}
579+
580+
fn signer_from_path_with_config(
581+
matches: &ArgMatches,
582+
path: &str,
583+
keypair_name: &str,
584+
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
585+
config: &SignerFromPathConfig,
586+
) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> {
587+
if let Ok(pubkey) = Pubkey::from_str(path) {
588+
if matches.try_contains_id(SIGNER_ARG.name).is_err()
589+
&& (config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name)?)
590+
{
591+
return Ok(Box::new(NullSigner::new(&pubkey)));
592+
}
593+
}
594+
595+
solana_clap_v3_utils::keypair::signer_from_path_with_config(
596+
matches,
597+
path,
598+
keypair_name,
599+
wallet_manager,
600+
config,
601+
)
602+
}

0 commit comments

Comments
 (0)