From 9518bca5bcdb39378317f08e9fa595d6624240fc Mon Sep 17 00:00:00 2001 From: FroVolod Date: Mon, 19 Feb 2024 19:31:26 +0200 Subject: [PATCH 1/2] start --- .../account/view_account_summary/mod.rs | 51 ++++++++++--------- src/common.rs | 6 +-- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index 3c0543546..2ee9cf63c 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -81,28 +81,33 @@ impl ViewAccountSummaryContext { .try_collect(), )?; - let contract_account_id = network_config.get_near_social_account_id_from_network()?; - - let social_db = network_config - .json_rpc_client() - .blocking_call_view_function( - &contract_account_id, - "get", - serde_json::to_vec(&serde_json::json!({ - "keys": vec![format!("{account_id}/profile/**")], - }))?, - block_reference.clone(), - ) - .wrap_err_with(|| { - format!("Failed to fetch query for view method: 'get {account_id}/profile/**' (contract <{}> on network <{}>)", - contract_account_id, - network_config.network_name - ) - })? - .parse_result_from_json::() - .wrap_err_with(|| { - format!("Failed to parse view function call return value for {account_id}/profile.") - })?; + let optional_account_profile = + if let Ok(contract_account_id) = network_config.get_near_social_account_id_from_network() { + let social_db = network_config + .json_rpc_client() + .blocking_call_view_function( + &contract_account_id, + "get", + serde_json::to_vec(&serde_json::json!({ + "keys": vec![format!("{account_id}/profile/**")], + }))?, + block_reference.clone(), + ) + .wrap_err_with(|| { + format!("Failed to fetch query for view method: 'get {account_id}/profile/**' (contract <{}> on network <{}>)", + contract_account_id, + network_config.network_name + ) + })? + .parse_result_from_json::() + .wrap_err_with(|| { + format!("Failed to parse view function call return value for {account_id}/profile.") + })?; + + social_db.accounts.get(&account_id).cloned() + } else { + None + }; crate::common::display_account_info( &rpc_query_response.block_hash, @@ -111,7 +116,7 @@ impl ViewAccountSummaryContext { &delegated_stake, &account_view, &access_key_list.keys, - social_db.accounts.get(&account_id) + optional_account_profile ); Ok(()) diff --git a/src/common.rs b/src/common.rs index 1c025bf0b..98da1e6f5 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1570,7 +1570,7 @@ pub fn display_account_info( >, account_view: &near_primitives::views::AccountView, access_keys: &[near_primitives::views::AccessKeyInfoView], - optional_account_profile: Option<&near_socialdb_client::types::socialdb_types::AccountProfile>, + optional_account_profile: Option, ) { let mut table: Table = Table::new(); table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); @@ -1643,7 +1643,7 @@ pub fn display_account_profile( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, account_id: &near_primitives::types::AccountId, - optional_account_profile: Option<&near_socialdb_client::types::socialdb_types::AccountProfile>, + optional_account_profile: Option, ) { let mut table = Table::new(); table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); @@ -1661,7 +1661,7 @@ fn profile_table( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, account_id: &near_primitives::types::AccountId, - optional_account_profile: Option<&near_socialdb_client::types::socialdb_types::AccountProfile>, + optional_account_profile: Option, table: &mut Table, ) { if let Some(account_profile) = optional_account_profile { From e1f58bdaedfeaebb5f0112ab9a97d7ab9fe20202 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Mon, 19 Feb 2024 21:32:30 +0100 Subject: [PATCH 2/2] refactored --- src/commands/account/view_account_summary/mod.rs | 6 +++--- src/common.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index 2ee9cf63c..a378c6747 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -83,7 +83,7 @@ impl ViewAccountSummaryContext { let optional_account_profile = if let Ok(contract_account_id) = network_config.get_near_social_account_id_from_network() { - let social_db = network_config + let mut social_db = network_config .json_rpc_client() .blocking_call_view_function( &contract_account_id, @@ -104,7 +104,7 @@ impl ViewAccountSummaryContext { format!("Failed to parse view function call return value for {account_id}/profile.") })?; - social_db.accounts.get(&account_id).cloned() + social_db.accounts.remove(&account_id) } else { None }; @@ -116,7 +116,7 @@ impl ViewAccountSummaryContext { &delegated_stake, &account_view, &access_key_list.keys, - optional_account_profile + optional_account_profile.as_ref() ); Ok(()) diff --git a/src/common.rs b/src/common.rs index 98da1e6f5..1c025bf0b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1570,7 +1570,7 @@ pub fn display_account_info( >, account_view: &near_primitives::views::AccountView, access_keys: &[near_primitives::views::AccessKeyInfoView], - optional_account_profile: Option, + optional_account_profile: Option<&near_socialdb_client::types::socialdb_types::AccountProfile>, ) { let mut table: Table = Table::new(); table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); @@ -1643,7 +1643,7 @@ pub fn display_account_profile( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, account_id: &near_primitives::types::AccountId, - optional_account_profile: Option, + optional_account_profile: Option<&near_socialdb_client::types::socialdb_types::AccountProfile>, ) { let mut table = Table::new(); table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); @@ -1661,7 +1661,7 @@ fn profile_table( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, account_id: &near_primitives::types::AccountId, - optional_account_profile: Option, + optional_account_profile: Option<&near_socialdb_client::types::socialdb_types::AccountProfile>, table: &mut Table, ) { if let Some(account_profile) = optional_account_profile {