|
1 | 1 | use { |
2 | | - crate::clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG}, |
| 2 | + crate::{ |
| 3 | + clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG}, |
| 4 | + print_error_and_exit, |
| 5 | + }, |
3 | 6 | clap::ArgMatches, |
4 | 7 | solana_clap_v3_utils::{ |
5 | | - input_parsers::{pubkey_of_signer, signer::SignerSource}, |
| 8 | + input_parsers::{ |
| 9 | + pubkey_of_signer, |
| 10 | + signer::{SignerSource, SignerSourceKind}, |
| 11 | + }, |
6 | 12 | input_validators::normalize_to_url_if_moniker, |
7 | 13 | keypair::SignerFromPathConfig, |
8 | 14 | nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG}, |
@@ -181,23 +187,23 @@ impl<'a> Config<'a> { |
181 | 187 | }; |
182 | 188 |
|
183 | 189 | let default_keypair = cli_config.keypair_path.clone(); |
184 | | - |
| 190 | + let default_keypair_source = |
| 191 | + SignerSource::parse(&default_keypair).unwrap_or_else(print_error_and_exit); |
185 | 192 | let default_signer: Option<Arc<dyn Signer>> = { |
186 | | - if let Some(owner_path) = matches.try_get_one::<String>("owner").ok().flatten() { |
187 | | - signer_from_path_with_config(matches, owner_path, "owner", wallet_manager, &config) |
| 193 | + if let Some(source) = matches.try_get_one::<SignerSource>("owner").ok().flatten() { |
| 194 | + signer_from_source_with_config(matches, source, "owner", wallet_manager, &config) |
188 | 195 | .ok() |
189 | 196 | } else { |
190 | | - signer_from_path_with_config( |
| 197 | + signer_from_source_with_config( |
191 | 198 | matches, |
192 | | - &default_keypair, |
| 199 | + &default_keypair_source, |
193 | 200 | "default", |
194 | 201 | wallet_manager, |
195 | 202 | &config, |
196 | 203 | ) |
197 | 204 | .map_err(|e| { |
198 | 205 | if std::fs::metadata(&default_keypair).is_ok() { |
199 | | - eprintln!("error: {}", e); |
200 | | - exit(1); |
| 206 | + print_error_and_exit(e) |
201 | 207 | } else { |
202 | 208 | e |
203 | 209 | } |
@@ -616,3 +622,30 @@ fn signer_from_path_with_config( |
616 | 622 | config, |
617 | 623 | ) |
618 | 624 | } |
| 625 | + |
| 626 | +/// A wrapper function around the `solana_clap_v3_utils` `signer_from_source |
| 627 | +/// with_config` function. If the signer source is a pubkey, then it checks for |
| 628 | +/// signing-only or if null signer is allowed and creates a null signer. |
| 629 | +/// Otherwise, it invokes the `solana_clap_v3_utils` version of the function. |
| 630 | +fn signer_from_source_with_config( |
| 631 | + matches: &ArgMatches, |
| 632 | + source: &SignerSource, |
| 633 | + keypair_name: &str, |
| 634 | + wallet_manager: &mut Option<Rc<RemoteWalletManager>>, |
| 635 | + config: &SignerFromPathConfig, |
| 636 | +) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> { |
| 637 | + if let SignerSourceKind::Pubkey(pubkey) = source.kind { |
| 638 | + if matches.try_contains_id(SIGNER_ARG.name).is_err() |
| 639 | + && (config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name)?) |
| 640 | + { |
| 641 | + return Ok(Box::new(NullSigner::new(&pubkey))); |
| 642 | + } |
| 643 | + } |
| 644 | + solana_clap_v3_utils::keypair::signer_from_source_with_config( |
| 645 | + matches, |
| 646 | + source, |
| 647 | + keypair_name, |
| 648 | + wallet_manager, |
| 649 | + config, |
| 650 | + ) |
| 651 | +} |
0 commit comments