CLI: Surface account query errors

This commit is contained in:
Trent Nelson
2021-02-02 12:25:30 -07:00
committed by Trent Nelson
parent 6cf6ef3a32
commit 3abb39c04f
3 changed files with 16 additions and 16 deletions

View File

@ -1636,7 +1636,7 @@ pub fn process_show_stakes(
CliError::RpcRequestError("Failed to deserialize stake history".to_string()) CliError::RpcRequestError("Failed to deserialize stake history".to_string())
})?; })?;
// At v1.6, this check can be removed and simply passed as `true` // At v1.6, this check can be removed and simply passed as `true`
let stake_program_v2_enabled = is_stake_program_v2_enabled(rpc_client); let stake_program_v2_enabled = is_stake_program_v2_enabled(rpc_client)?;
let mut stake_accounts: Vec<CliKeyedStakeState> = vec![]; let mut stake_accounts: Vec<CliKeyedStakeState> = vec![];
for (stake_pubkey, stake_account) in all_stake_accounts { for (stake_pubkey, stake_account) in all_stake_accounts {

View File

@ -457,11 +457,11 @@ pub fn process_new_nonce(
(&nonce_account, "nonce_account_pubkey".to_string()), (&nonce_account, "nonce_account_pubkey".to_string()),
)?; )?;
let nonce_account_check = rpc_client.get_account(&nonce_account); if let Err(err) = rpc_client.get_account(&nonce_account) {
if nonce_account_check.is_err() { return Err(CliError::BadParameter(format!(
return Err(CliError::BadParameter( "Unable to advance nonce account {}. error: {}",
"Unable to create new nonce, no nonce account found".to_string(), nonce_account, err
) ))
.into()); .into());
} }

View File

@ -1718,7 +1718,7 @@ pub fn process_show_stake_account(
use_lamports_unit, use_lamports_unit,
&stake_history, &stake_history,
&clock, &clock,
is_stake_program_v2_enabled(rpc_client), // At v1.6, this check can be removed and simply passed as `true` is_stake_program_v2_enabled(rpc_client)?, // At v1.6, this check can be removed and simply passed as `true`
); );
if state.stake_type == CliStakeType::Stake { if state.stake_type == CliStakeType::Stake {
@ -1787,10 +1787,10 @@ pub fn process_delegate_stake(
// voted at the tip of the ledger // voted at the tip of the ledger
let vote_account_data = rpc_client let vote_account_data = rpc_client
.get_account(vote_account_pubkey) .get_account(vote_account_pubkey)
.map_err(|_| { .map_err(|err| {
CliError::RpcRequestError(format!( CliError::RpcRequestError(format!(
"Vote account not found: {}", "Vote account not found: {}. error: {}",
vote_account_pubkey vote_account_pubkey, err,
)) ))
})? })?
.data; .data;
@ -1878,13 +1878,13 @@ pub fn process_delegate_stake(
} }
} }
pub fn is_stake_program_v2_enabled(rpc_client: &RpcClient) -> bool { pub fn is_stake_program_v2_enabled(
rpc_client rpc_client: &RpcClient,
.get_account(&feature_set::stake_program_v2::id()) ) -> Result<bool, Box<dyn std::error::Error>> {
.ok() let feature_account = rpc_client.get_account(&feature_set::stake_program_v2::id())?;
.and_then(|account| feature::from_account(&account)) Ok(feature::from_account(&feature_account)
.and_then(|feature| feature.activated_at) .and_then(|feature| feature.activated_at)
.is_some() .is_some())
} }
#[cfg(test)] #[cfg(test)]