From 29c3737704605b728227ec1bfb8544e1b542de7a Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Fri, 5 Dec 2025 07:46:59 +0200 Subject: [PATCH] fix: lint fix comments addressed --- key_protocol/Cargo.toml | 1 - .../key_management/key_tree/chain_index.rs | 8 +--- .../src/key_management/key_tree/mod.rs | 44 +++++++++---------- wallet/src/cli/mod.rs | 4 +- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/key_protocol/Cargo.toml b/key_protocol/Cargo.toml index 4f94c79e..a5625159 100644 --- a/key_protocol/Cargo.toml +++ b/key_protocol/Cargo.toml @@ -22,4 +22,3 @@ path = "../common" [dependencies.nssa] path = "../nssa" -features = ["no_docker"] diff --git a/key_protocol/src/key_management/key_tree/chain_index.rs b/key_protocol/src/key_management/key_tree/chain_index.rs index 31445e79..8b28327b 100644 --- a/key_protocol/src/key_management/key_tree/chain_index.rs +++ b/key_protocol/src/key_management/key_tree/chain_index.rs @@ -102,13 +102,7 @@ impl ChainIndex { } pub fn depth(&self) -> u32 { - let mut res = 0; - - for cci in &self.0 { - res += cci + 1; - } - - res + self.0.iter().map(|cci| cci + 1).sum() } } diff --git a/key_protocol/src/key_management/key_tree/mod.rs b/key_protocol/src/key_management/key_tree/mod.rs index 5f2616d0..b75671ee 100644 --- a/key_protocol/src/key_management/key_tree/mod.rs +++ b/key_protocol/src/key_management/key_tree/mod.rs @@ -115,13 +115,13 @@ impl KeyTree { &mut self, parent_cci: &ChainIndex, ) -> Option<(nssa::AccountId, ChainIndex)> { - let father_keys = self.key_map.get(parent_cci)?; + let parent_keys = self.key_map.get(parent_cci)?; let next_child_id = self .find_next_last_child_of_id(parent_cci) .expect("Can be None only if parent is not present"); let next_cci = parent_cci.nth_child(next_child_id); - let child_keys = father_keys.nth_child(next_child_id); + let child_keys = parent_keys.nth_child(next_child_id); let account_id = child_keys.account_id(); self.key_map.insert(next_cci.clone(), child_keys); @@ -174,11 +174,12 @@ impl KeyTree { } impl KeyTree { + #[allow(clippy::result_large_err)] pub fn generate_new_node( &mut self, parent_cci: &ChainIndex, ) -> Result<(nssa::AccountId, ChainIndex), KeyTreeGenerationError> { - let father_keys = + let parent_keys = self.key_map .get(parent_cci) .ok_or(KeyTreeGenerationError::ParentChainIdNotFound( @@ -190,21 +191,20 @@ impl KeyTree { let next_cci = parent_cci.nth_child(next_child_id); if let Some(prev_cci) = next_cci.previous_in_line() { - let prev_keys = self.key_map.get(&prev_cci).expect( - format!("Constraint violated, previous child with id {prev_cci} is missing") - .as_str(), - ); + let prev_keys = self.key_map.get(&prev_cci).unwrap_or_else(|| { + panic!("Constraint violated, previous child with id {prev_cci} is missing") + }); if prev_keys.value.1 == nssa::Account::default() { return Err(KeyTreeGenerationError::PredecesorsNotInitialized(next_cci)); } - } else if *parent_cci != ChainIndex::root() { - if father_keys.value.1 == nssa::Account::default() { - return Err(KeyTreeGenerationError::PredecesorsNotInitialized(next_cci)); - } + } else if *parent_cci != ChainIndex::root() + && parent_keys.value.1 == nssa::Account::default() + { + return Err(KeyTreeGenerationError::PredecesorsNotInitialized(next_cci)); } - let child_keys = father_keys.nth_child(next_child_id); + let child_keys = parent_keys.nth_child(next_child_id); let account_id = child_keys.account_id(); self.key_map.insert(next_cci.clone(), child_keys); @@ -221,7 +221,7 @@ impl KeyTree { /// If account is default, removes them. /// /// Chain must be parsed for accounts beforehand - pub fn cleanup_tree_for_depth(&mut self, depth: u32) { + pub fn cleanup_tree_remove_ininit_for_depth(&mut self, depth: u32) { let mut id_stack = vec![ChainIndex::root()]; while let Some(curr_id) = id_stack.pop() { @@ -244,12 +244,13 @@ impl KeyTree { } impl KeyTree { + #[allow(clippy::result_large_err)] pub async fn generate_new_node( &mut self, parent_cci: &ChainIndex, client: Arc, ) -> Result<(nssa::AccountId, ChainIndex), KeyTreeGenerationError> { - let father_keys = + let parent_keys = self.key_map .get(parent_cci) .ok_or(KeyTreeGenerationError::ParentChainIdNotFound( @@ -261,10 +262,9 @@ impl KeyTree { let next_cci = parent_cci.nth_child(next_child_id); if let Some(prev_cci) = next_cci.previous_in_line() { - let prev_keys = self.key_map.get(&prev_cci).expect( - format!("Constraint violated, previous child with id {prev_cci} is missing") - .as_str(), - ); + let prev_keys = self.key_map.get(&prev_cci).unwrap_or_else(|| { + panic!("Constraint violated, previous child with id {prev_cci} is missing") + }); let prev_acc = client .get_account(prev_keys.account_id().to_string()) .await? @@ -275,7 +275,7 @@ impl KeyTree { } } else if *parent_cci != ChainIndex::root() { let parent_acc = client - .get_account(father_keys.account_id().to_string()) + .get_account(parent_keys.account_id().to_string()) .await? .account; @@ -284,7 +284,7 @@ impl KeyTree { } } - let child_keys = father_keys.nth_child(next_child_id); + let child_keys = parent_keys.nth_child(next_child_id); let account_id = child_keys.account_id(); self.key_map.insert(next_cci.clone(), child_keys); @@ -299,7 +299,7 @@ impl KeyTree { /// depth`. /// /// If account is default, removes them. - pub async fn cleanup_tree_for_depth( + pub async fn cleanup_tree_remove_ininit_for_depth( &mut self, depth: u32, client: Arc, @@ -615,7 +615,7 @@ mod tests { .unwrap(); acc.value.1.balance = 6; - tree.cleanup_tree_for_depth(10); + tree.cleanup_tree_remove_ininit_for_depth(10); let mut key_set_res = HashSet::new(); key_set_res.insert("/0".to_string()); diff --git a/wallet/src/cli/mod.rs b/wallet/src/cli/mod.rs index 1f0e53b7..07bf252c 100644 --- a/wallet/src/cli/mod.rs +++ b/wallet/src/cli/mod.rs @@ -231,7 +231,7 @@ pub async fn execute_keys_restoration(password: String, depth: u32) -> Result<() .storage .user_data .public_key_tree - .cleanup_tree_for_depth(depth, wallet_core.sequencer_client.clone()) + .cleanup_tree_remove_ininit_for_depth(depth, wallet_core.sequencer_client.clone()) .await?; println!("Public tree cleaned up"); @@ -258,7 +258,7 @@ pub async fn execute_keys_restoration(password: String, depth: u32) -> Result<() .storage .user_data .private_key_tree - .cleanup_tree_for_depth(depth); + .cleanup_tree_remove_ininit_for_depth(depth); println!("Private tree cleaned up");