Clarify account creation error messages in CLI (#7719)

* Clarify account creation error messages in CLI

* feedback

* Fix rebase
This commit is contained in:
Justin Starry
2020-01-10 12:25:07 +08:00
committed by GitHub
parent e90a31781c
commit bcd072c5e8
4 changed files with 46 additions and 19 deletions

View File

@@ -163,6 +163,19 @@ pub fn process_create_storage_account(
"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;
let required_balance = rpc_client
.get_minimum_balance_for_rent_exemption(STORAGE_ACCOUNT_SPACE as usize)?