diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 7ccb868c4c..c719088e41 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -490,6 +490,12 @@ pub enum ClusterCommand { List, } +fn get_keypair(path: String) -> Result { + let keypair = solana_sdk::signature::read_keypair_file(&path) + .map_err(|_| anyhow!("Unable to read keypair file ({})", path))?; + Ok(keypair) +} + pub fn entry(opts: Opts) -> Result<()> { let restore_cbs = override_toolchain(&opts.cfg_override)?; let result = process_command(opts); @@ -2267,8 +2273,7 @@ fn idl_set_buffer( priority_fee: Option, ) -> Result { with_workspace(cfg_override, |cfg| { - let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string()) - .map_err(|_| anyhow!("Unable to read keypair file"))?; + let keypair = get_keypair(cfg.provider.wallet.to_string())?; let url = cluster_url(cfg, &cfg.test_validator); let client = create_client(url); @@ -2386,8 +2391,8 @@ fn idl_set_authority( None => IdlAccount::address(&program_id), Some(addr) => addr, }; - let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string()) - .map_err(|_| anyhow!("Unable to read keypair file"))?; + let keypair = get_keypair(cfg.provider.wallet.to_string())?; + let url = cluster_url(cfg, &cfg.test_validator); let client = create_client(url); @@ -2470,8 +2475,8 @@ fn idl_close_account( print_only: bool, priority_fee: Option, ) -> Result<()> { - let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string()) - .map_err(|_| anyhow!("Unable to read keypair file"))?; + let keypair = get_keypair(cfg.provider.wallet.to_string())?; + let url = cluster_url(cfg, &cfg.test_validator); let client = create_client(url); @@ -2523,8 +2528,8 @@ fn idl_write( priority_fee: Option, ) -> Result<()> { // Misc. - let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string()) - .map_err(|_| anyhow!("Unable to read keypair file"))?; + let keypair = get_keypair(cfg.provider.wallet.to_string())?; + let url = cluster_url(cfg, &cfg.test_validator); let client = create_client(url); @@ -3707,8 +3712,7 @@ fn create_idl_account( ) -> Result { // Misc. let idl_address = IdlAccount::address(program_id); - let keypair = solana_sdk::signature::read_keypair_file(keypair_path) - .map_err(|_| anyhow!("Unable to read keypair file"))?; + let keypair = get_keypair(cfg.provider.wallet.to_string())?; let url = cluster_url(cfg, &cfg.test_validator); let client = create_client(url); let idl_data = serialize_idl(idl)?; @@ -3789,8 +3793,7 @@ fn create_idl_buffer( idl: &Idl, priority_fee: Option, ) -> Result { - let keypair = solana_sdk::signature::read_keypair_file(keypair_path) - .map_err(|_| anyhow!("Unable to read keypair file"))?; + let keypair = get_keypair(cfg.provider.wallet.to_string())?; let url = cluster_url(cfg, &cfg.test_validator); let client = create_client(url);