From 32a728d585fff614ea74a9bde5604aebe552810c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2020 07:02:11 -0800 Subject: [PATCH] Clarify account creation error messages in CLI (bp #7719) (#7745) automerge --- cli/src/nonce.rs | 18 ++++++++++++------ cli/src/stake.rs | 16 ++++++++++------ cli/src/storage.rs | 13 +++++++++++++ cli/src/vote.rs | 17 ++++++++++++++--- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/cli/src/nonce.rs b/cli/src/nonce.rs index 0927f798de..286370ae33 100644 --- a/cli/src/nonce.rs +++ b/cli/src/nonce.rs @@ -363,12 +363,18 @@ pub fn process_create_nonce_account( (&nonce_account_pubkey, "nonce_account_pubkey".to_string()), )?; - if rpc_client.get_account(&nonce_account_pubkey).is_ok() { - return Err(CliError::BadParameter(format!( - "Unable to create nonce account. Nonce account already exists: {}", - nonce_account_pubkey, - )) - .into()); + if let Ok(nonce_account) = rpc_client.get_account(&nonce_account_pubkey) { + let err_msg = if nonce_account.owner == system_program::id() + && State::::state(&nonce_account).is_ok() + { + format!("Nonce account {} already exists", nonce_account_pubkey) + } else { + format!( + "Account {} already exists and is not a nonce account", + nonce_account_pubkey + ) + }; + return Err(CliError::BadParameter(err_msg).into()); } let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(NonceState::size())?; diff --git a/cli/src/stake.rs b/cli/src/stake.rs index 5ef01abae3..520aa699e3 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -527,12 +527,16 @@ pub fn process_create_stake_account( (&stake_account_pubkey, "stake_account_pubkey".to_string()), )?; - if rpc_client.get_account(&stake_account_pubkey).is_ok() { - return Err(CliError::BadParameter(format!( - "Unable to create stake account. Stake account already exists: {}", - stake_account_pubkey - )) - .into()); + if let Ok(stake_account) = rpc_client.get_account(&stake_account_pubkey) { + let err_msg = if stake_account.owner == solana_stake_program::id() { + format!("Stake account {} already exists", stake_account_pubkey) + } else { + format!( + "Account {} already exists and is not a stake account", + stake_account_pubkey + ) + }; + return Err(CliError::BadParameter(err_msg).into()); } let minimum_balance = diff --git a/cli/src/storage.rs b/cli/src/storage.rs index 93f7981001..56657e078b 100644 --- a/cli/src/storage.rs +++ b/cli/src/storage.rs @@ -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)? diff --git a/cli/src/vote.rs b/cli/src/vote.rs index 88a8804fbd..eb9cfc71d4 100644 --- a/cli/src/vote.rs +++ b/cli/src/vote.rs @@ -9,10 +9,9 @@ use crate::{ use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand}; use solana_clap_utils::{input_parsers::*, input_validators::*}; use solana_client::rpc_client::RpcClient; -use solana_sdk::signature::Keypair; use solana_sdk::{ - account::Account, pubkey::Pubkey, signature::KeypairUtil, system_instruction::SystemError, - transaction::Transaction, + account::Account, pubkey::Pubkey, signature::Keypair, signature::KeypairUtil, + system_instruction::SystemError, transaction::Transaction, }; use solana_vote_program::{ vote_instruction::{self, VoteError}, @@ -295,6 +294,18 @@ pub fn process_create_vote_account( (&vote_account_pubkey, "vote_account_pubkey".to_string()), )?; + if let Ok(vote_account) = rpc_client.get_account(&vote_account_pubkey) { + let err_msg = if vote_account.owner == solana_vote_program::id() { + format!("Vote account {} already exists", vote_account_pubkey) + } else { + format!( + "Account {} already exists and is not a vote account", + vote_account_pubkey + ) + }; + return Err(CliError::BadParameter(err_msg).into()); + } + let required_balance = rpc_client .get_minimum_balance_for_rent_exemption(VoteState::size_of())? .max(1);