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())
})?;
// 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![];
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()),
)?;
let nonce_account_check = rpc_client.get_account(&nonce_account);
if nonce_account_check.is_err() {
return Err(CliError::BadParameter(
"Unable to create new nonce, no nonce account found".to_string(),
)
if let Err(err) = rpc_client.get_account(&nonce_account) {
return Err(CliError::BadParameter(format!(
"Unable to advance nonce account {}. error: {}",
nonce_account, err
))
.into());
}

View File

@ -1718,7 +1718,7 @@ pub fn process_show_stake_account(
use_lamports_unit,
&stake_history,
&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 {
@ -1787,10 +1787,10 @@ pub fn process_delegate_stake(
// voted at the tip of the ledger
let vote_account_data = rpc_client
.get_account(vote_account_pubkey)
.map_err(|_| {
.map_err(|err| {
CliError::RpcRequestError(format!(
"Vote account not found: {}",
vote_account_pubkey
"Vote account not found: {}. error: {}",
vote_account_pubkey, err,
))
})?
.data;
@ -1878,13 +1878,13 @@ pub fn process_delegate_stake(
}
}
pub fn is_stake_program_v2_enabled(rpc_client: &RpcClient) -> bool {
rpc_client
.get_account(&feature_set::stake_program_v2::id())
.ok()
.and_then(|account| feature::from_account(&account))
pub fn is_stake_program_v2_enabled(
rpc_client: &RpcClient,
) -> Result<bool, Box<dyn std::error::Error>> {
let feature_account = rpc_client.get_account(&feature_set::stake_program_v2::id())?;
Ok(feature::from_account(&feature_account)
.and_then(|feature| feature.activated_at)
.is_some()
.is_some())
}
#[cfg(test)]