diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index 3b33a2d0..0f5fd8a6 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -109,47 +109,49 @@ fn get_account_inquiry( .ok() }); let validators = if let Some(validators) = historically_delegated_validators { - validators + Ok(validators) } else if let Some(staking_pools_factory_account_id) = &network_config.staking_pools_factory_account_id { crate::common::fetch_currently_active_staking_pools( &json_rpc_client, staking_pools_factory_account_id, - )? + ) } else { - Default::default() + Ok(Default::default()) }; let runtime = tokio::runtime::Builder::new_multi_thread() .enable_all() .build()?; let concurrency = 10; - let delegated_stake: std::collections::BTreeMap< - near_primitives::types::AccountId, - near_token::NearToken, - > = runtime.block_on( - futures::stream::iter(validators) - .map(|validator_account_id| async { - let balance = get_delegated_staked_balance( - &json_rpc_client, - block_reference, - &validator_account_id, - account_id, - ) - .await?; - Ok::<_, color_eyre::eyre::Report>((validator_account_id, balance)) - }) - .buffer_unordered(concurrency) - .filter(|balance_result| { - futures::future::ready(if let Ok((_, balance)) = balance_result { - !balance.is_zero() - } else { - true + let delegated_stake: color_eyre::Result< + std::collections::BTreeMap, + > = match validators { + Ok(validators) => Ok(runtime.block_on( + futures::stream::iter(validators) + .map(|validator_account_id| async { + let balance = get_delegated_staked_balance( + &json_rpc_client, + block_reference, + &validator_account_id, + account_id, + ) + .await?; + Ok::<_, color_eyre::eyre::Report>((validator_account_id, balance)) }) - }) - .try_collect(), - )?; + .buffer_unordered(concurrency) + .filter(|balance_result| { + futures::future::ready(if let Ok((_, balance)) = balance_result { + !balance.is_zero() + } else { + true + }) + }) + .try_collect(), + )?), + Err(err) => Err(err), + }; let optional_account_profile = get_account_profile(account_id, network_config, block_reference) .ok() @@ -159,7 +161,7 @@ fn get_account_inquiry( &rpc_query_response.block_hash, &rpc_query_response.block_height, account_id, - &delegated_stake, + delegated_stake, &account_view, access_key_list.as_ref(), optional_account_profile.as_ref(), diff --git a/src/common.rs b/src/common.rs index c81e0645..870829e9 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1567,7 +1567,7 @@ pub fn fetch_currently_active_staking_pools( include_proof: false, }, }) - .context("Failed to fetch query ViewState for on the selected network")?; + .map_err(color_eyre::Report::msg)?; if let near_jsonrpc_primitives::types::query::QueryResponseKind::ViewState(result) = query_view_method_response.kind { @@ -1699,9 +1699,8 @@ pub fn display_account_info( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, account_id: &near_primitives::types::AccountId, - delegated_stake: &std::collections::BTreeMap< - near_primitives::types::AccountId, - near_token::NearToken, + delegated_stake: color_eyre::Result< + std::collections::BTreeMap, >, account_view: &near_primitives::views::AccountView, access_key_list: Option<&near_primitives::views::AccessKeyList>, @@ -1728,11 +1727,21 @@ pub fn display_account_info( Fy->near_token::NearToken::from_yoctonear(account_view.locked) ]); - for (validator_id, stake) in delegated_stake { - table.add_row(prettytable::row![ - Fg->format!("Delegated stake with <{validator_id}>"), - Fy->stake - ]); + match delegated_stake { + Ok(delegated_stake) => { + for (validator_id, stake) in delegated_stake { + table.add_row(prettytable::row![ + Fg->format!("Delegated stake with <{validator_id}>"), + Fy->stake + ]); + } + } + Err(err) => { + table.add_row(prettytable::row![ + Fg->"Delegated stake", + Fr->err + ]); + } } table.add_row(prettytable::row![