|
4 | 4 | solana_clap_v3_utils::{
|
5 | 5 | input_parsers::{pubkey_of_signer, value_of},
|
6 | 6 | input_validators::normalize_to_url_if_moniker,
|
7 |
| - keypair::{signer_from_path, signer_from_path_with_config, SignerFromPathConfig}, |
| 7 | + keypair::SignerFromPathConfig, |
8 | 8 | 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}, |
10 | 10 | },
|
11 | 11 | solana_cli_output::OutputFormat,
|
12 | 12 | solana_client::nonblocking::rpc_client::RpcClient,
|
13 | 13 | solana_remote_wallet::remote_wallet::RemoteWalletManager,
|
14 | 14 | solana_sdk::{
|
15 | 15 | account::Account as RawAccount, commitment_config::CommitmentConfig, hash::Hash,
|
16 |
| - pubkey::Pubkey, signature::Signer, |
| 16 | + pubkey::Pubkey, signature::Signer, signer::null_signer::NullSigner, |
17 | 17 | },
|
18 | 18 | spl_associated_token_account::*,
|
19 | 19 | spl_token_2022::{
|
@@ -526,3 +526,43 @@ impl<'a> Config<'a> {
|
526 | 526 | }
|
527 | 527 | }
|
528 | 528 | }
|
| 529 | + |
| 530 | +// In clap v2, `value_of` returns `None` if the argument id is not previously specified in |
| 531 | +// `Arg`. In contrast, in clap v3, `value_of` panics in this case. Therefore, compared |
| 532 | +// to the same function in solana-clap-utils, `signer_from_path` in solana-clap-v3-utils errors |
| 533 | +// early when `path` is a valid pubkey, but `SIGNER_ARG.name` is not specified in the args. |
| 534 | +// This function behaves exactly as `signer_from_path` from solana-clap-utils by catching |
| 535 | +// this special case. |
| 536 | +fn signer_from_path( |
| 537 | + matches: &ArgMatches, |
| 538 | + path: &str, |
| 539 | + keypair_name: &str, |
| 540 | + wallet_manager: &mut Option<Rc<RemoteWalletManager>>, |
| 541 | +) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> { |
| 542 | + let config = SignerFromPathConfig::default(); |
| 543 | + signer_from_path_with_config(matches, path, keypair_name, wallet_manager, &config) |
| 544 | +} |
| 545 | + |
| 546 | +fn signer_from_path_with_config( |
| 547 | + matches: &ArgMatches, |
| 548 | + path: &str, |
| 549 | + keypair_name: &str, |
| 550 | + wallet_manager: &mut Option<Rc<RemoteWalletManager>>, |
| 551 | + config: &SignerFromPathConfig, |
| 552 | +) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> { |
| 553 | + if let Ok(pubkey) = Pubkey::from_str(path) { |
| 554 | + if matches.try_contains_id(SIGNER_ARG.name).is_err() |
| 555 | + && (config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name)?) |
| 556 | + { |
| 557 | + return Ok(Box::new(NullSigner::new(&pubkey))); |
| 558 | + } |
| 559 | + } |
| 560 | + |
| 561 | + solana_clap_v3_utils::keypair::signer_from_path_with_config( |
| 562 | + matches, |
| 563 | + path, |
| 564 | + keypair_name, |
| 565 | + wallet_manager, |
| 566 | + config, |
| 567 | + ) |
| 568 | +} |
0 commit comments