Clarify account creation error messages in CLI (#7719)
* Clarify account creation error messages in CLI * feedback * Fix rebase
This commit is contained in:
		| @@ -379,12 +379,18 @@ pub fn process_create_nonce_account( | |||||||
|         (&nonce_account_address, "nonce_account".to_string()), |         (&nonce_account_address, "nonce_account".to_string()), | ||||||
|     )?; |     )?; | ||||||
|  |  | ||||||
|     if rpc_client.get_account(&nonce_account_address).is_ok() { |     if let Ok(nonce_account) = rpc_client.get_account(&nonce_account_address) { | ||||||
|         return Err(CliError::BadParameter(format!( |         let err_msg = if nonce_account.owner == system_program::id() | ||||||
|             "Unable to create nonce account. Nonce account already exists: {}", |             && State::<NonceState>::state(&nonce_account).is_ok() | ||||||
|             nonce_account_pubkey, |         { | ||||||
|         )) |             format!("Nonce account {} already exists", nonce_account_address) | ||||||
|         .into()); |         } else { | ||||||
|  |             format!( | ||||||
|  |                 "Account {} already exists and is not a nonce account", | ||||||
|  |                 nonce_account_address | ||||||
|  |             ) | ||||||
|  |         }; | ||||||
|  |         return Err(CliError::BadParameter(err_msg).into()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(NonceState::size())?; |     let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(NonceState::size())?; | ||||||
|   | |||||||
| @@ -542,12 +542,16 @@ pub fn process_create_stake_account( | |||||||
|         (&stake_account_address, "stake_account".to_string()), |         (&stake_account_address, "stake_account".to_string()), | ||||||
|     )?; |     )?; | ||||||
|  |  | ||||||
|     if rpc_client.get_account(&stake_account_address).is_ok() { |     if let Ok(stake_account) = rpc_client.get_account(&stake_account_address) { | ||||||
|         return Err(CliError::BadParameter(format!( |         let err_msg = if stake_account.owner == solana_stake_program::id() { | ||||||
|             "Unable to create stake account. Stake account already exists: {}", |             format!("Stake account {} already exists", stake_account_address) | ||||||
|  |         } else { | ||||||
|  |             format!( | ||||||
|  |                 "Account {} already exists and is not a stake account", | ||||||
|                 stake_account_address |                 stake_account_address | ||||||
|         )) |             ) | ||||||
|         .into()); |         }; | ||||||
|  |         return Err(CliError::BadParameter(err_msg).into()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let minimum_balance = |     let minimum_balance = | ||||||
|   | |||||||
| @@ -163,6 +163,19 @@ pub fn process_create_storage_account( | |||||||
|             "storage_account_pubkey".to_string(), |             "storage_account_pubkey".to_string(), | ||||||
|         ), |         ), | ||||||
|     )?; |     )?; | ||||||
|  |  | ||||||
|  |     if let Ok(storage_account) = rpc_client.get_account(&storage_account_pubkey) { | ||||||
|  |         let err_msg = if storage_account.owner == solana_storage_program::id() { | ||||||
|  |             format!("Storage account {} already exists", storage_account_pubkey) | ||||||
|  |         } else { | ||||||
|  |             format!( | ||||||
|  |                 "Account {} already exists and is not a storage account", | ||||||
|  |                 storage_account_pubkey | ||||||
|  |             ) | ||||||
|  |         }; | ||||||
|  |         return Err(CliError::BadParameter(err_msg).into()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     use solana_storage_program::storage_contract::STORAGE_ACCOUNT_SPACE; |     use solana_storage_program::storage_contract::STORAGE_ACCOUNT_SPACE; | ||||||
|     let required_balance = rpc_client |     let required_balance = rpc_client | ||||||
|         .get_minimum_balance_for_rent_exemption(STORAGE_ACCOUNT_SPACE as usize)? |         .get_minimum_balance_for_rent_exemption(STORAGE_ACCOUNT_SPACE as usize)? | ||||||
|   | |||||||
| @@ -9,10 +9,10 @@ use crate::{ | |||||||
| use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand}; | use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand}; | ||||||
| use solana_clap_utils::{input_parsers::*, input_validators::*}; | use solana_clap_utils::{input_parsers::*, input_validators::*}; | ||||||
| use solana_client::rpc_client::RpcClient; | use solana_client::rpc_client::RpcClient; | ||||||
| use solana_sdk::signature::Keypair; |  | ||||||
| use solana_sdk::{ | use solana_sdk::{ | ||||||
|     account::Account, |     account::Account, | ||||||
|     pubkey::Pubkey, |     pubkey::Pubkey, | ||||||
|  |     signature::Keypair, | ||||||
|     signature::KeypairUtil, |     signature::KeypairUtil, | ||||||
|     system_instruction::{create_address_with_seed, SystemError}, |     system_instruction::{create_address_with_seed, SystemError}, | ||||||
|     transaction::Transaction, |     transaction::Transaction, | ||||||
| @@ -314,12 +314,16 @@ pub fn process_create_vote_account( | |||||||
|         (&identity_pubkey, "identity_pubkey".to_string()), |         (&identity_pubkey, "identity_pubkey".to_string()), | ||||||
|     )?; |     )?; | ||||||
|  |  | ||||||
|     if rpc_client.get_account(&vote_account_address).is_ok() { |     if let Ok(vote_account) = rpc_client.get_account(&vote_account_address) { | ||||||
|         return Err(CliError::BadParameter(format!( |         let err_msg = if vote_account.owner == solana_vote_program::id() { | ||||||
|             "Unable to create vote account. Vote account already exists: {}", |             format!("Vote account {} already exists", vote_account_address) | ||||||
|  |         } else { | ||||||
|  |             format!( | ||||||
|  |                 "Account {} already exists and is not a vote account", | ||||||
|                 vote_account_address |                 vote_account_address | ||||||
|         )) |             ) | ||||||
|         .into()); |         }; | ||||||
|  |         return Err(CliError::BadParameter(err_msg).into()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let required_balance = rpc_client |     let required_balance = rpc_client | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user