From f4194bb73ce15a04c55dadb7324b210c60496b2c Mon Sep 17 00:00:00 2001 From: alenmestrov Date: Fri, 29 Nov 2024 18:04:26 +0100 Subject: [PATCH] fix: linter --- contracts/icp/context-config/src/guard.rs | 2 +- contracts/icp/context-config/src/lib.rs | 4 +- contracts/icp/context-config/src/mutate.rs | 42 ++++++------------- contracts/icp/context-config/src/query.rs | 1 + contracts/icp/context-config/src/types.rs | 15 ++++--- .../icp/context-config/tests/integration.rs | 2 +- 6 files changed, 25 insertions(+), 41 deletions(-) diff --git a/contracts/icp/context-config/src/guard.rs b/contracts/icp/context-config/src/guard.rs index f07d4ff0d..7004f9b2b 100644 --- a/contracts/icp/context-config/src/guard.rs +++ b/contracts/icp/context-config/src/guard.rs @@ -1,6 +1,6 @@ +use std::collections::BTreeSet; use std::fmt; use std::ops::{Deref, DerefMut}; -use std::collections::BTreeSet; use calimero_context_config::types::Revision; use candid::CandidType; diff --git a/contracts/icp/context-config/src/lib.rs b/contracts/icp/context-config/src/lib.rs index ffbb6827c..ed3a1bb84 100644 --- a/contracts/icp/context-config/src/lib.rs +++ b/contracts/icp/context-config/src/lib.rs @@ -1,5 +1,5 @@ -use std::{cell::RefCell, collections::HashMap}; -use std::collections::BTreeMap; +use std::cell::RefCell; +use std::collections::{BTreeMap, HashMap}; use candid::CandidType; use guard::Guard; diff --git a/contracts/icp/context-config/src/mutate.rs b/contracts/icp/context-config/src/mutate.rs index 5576ef084..ea7e4449b 100644 --- a/contracts/icp/context-config/src/mutate.rs +++ b/contracts/icp/context-config/src/mutate.rs @@ -2,14 +2,12 @@ use std::ops::Deref; use calimero_context_config::repr::{ReprBytes, ReprTransmute}; - use crate::guard::Guard; -use crate::Context; use crate::types::{ ContextRequest, ContextRequestKind, ICApplication, ICCapability, ICContextId, ICContextIdentity, ICPSigned, ICSignerId, Request, RequestKind, }; -use crate::CONTEXT_CONFIGS; +use crate::{Context, CONTEXT_CONFIGS}; #[ic_cdk::update] pub fn mutate(signed_request: ICPSigned) -> Result<(), String> { @@ -29,14 +27,7 @@ pub fn mutate(signed_request: ICPSigned) -> Result<(), String> { ContextRequestKind::Add { author_id, application, - } => { - add_context( - &request.signer_id, - context_id, - author_id, - application, - ) - } + } => add_context(&request.signer_id, context_id, author_id, application), ContextRequestKind::UpdateApplication { application } => { update_application(&request.signer_id, &context_id.clone(), application.clone()) } @@ -46,20 +37,16 @@ pub fn mutate(signed_request: ICPSigned) -> Result<(), String> { ContextRequestKind::RemoveMembers { members } => { remove_members(&request.signer_id, &context_id.clone(), members.clone()) } - ContextRequestKind::Grant { capabilities } => { - grant( - &request.signer_id, - &context_id.clone(), - capabilities.clone(), - ) - } - ContextRequestKind::Revoke { capabilities } => { - revoke( - &request.signer_id, - &context_id.clone(), - capabilities.clone(), - ) - } + ContextRequestKind::Grant { capabilities } => grant( + &request.signer_id, + &context_id.clone(), + capabilities.clone(), + ), + ContextRequestKind::Revoke { capabilities } => revoke( + &request.signer_id, + &context_id.clone(), + capabilities.clone(), + ), ContextRequestKind::UpdateProxyContract => { // TODO: Implement update_proxy_contract Ok(()) @@ -84,10 +71,7 @@ fn add_context( // Create context with guards let context = Context { - application: Guard::new( - author_id.rt().expect("infallible conversion"), - application, - ), + application: Guard::new(author_id.rt().expect("infallible conversion"), application), members: Guard::new( author_id.rt().expect("infallible conversion"), vec![author_id.rt().expect("infallible conversion")], diff --git a/contracts/icp/context-config/src/query.rs b/contracts/icp/context-config/src/query.rs index 7d3e19639..79ad2a7b9 100644 --- a/contracts/icp/context-config/src/query.rs +++ b/contracts/icp/context-config/src/query.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; + use calimero_context_config::repr::ReprTransmute; use ic_cdk_macros::query; diff --git a/contracts/icp/context-config/src/types.rs b/contracts/icp/context-config/src/types.rs index 827be2685..e23f7117e 100644 --- a/contracts/icp/context-config/src/types.rs +++ b/contracts/icp/context-config/src/types.rs @@ -60,7 +60,9 @@ impl ReprBytes for ICSignerId { } } -#[derive(CandidType, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Copy)] +#[derive( + CandidType, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Copy, +)] pub struct ICContextIdentity(Identity); impl ICContextIdentity { @@ -75,7 +77,7 @@ impl ReprBytes for ICContextIdentity { type Error = LengthMismatch; fn as_bytes(&self) -> Self::EncodeBytes<'_> { - self.0.0 + self.0 .0 } fn from_bytes(f: F) -> repr::Result @@ -292,15 +294,12 @@ impl ICPSigned { F: FnOnce(&[u8]) -> R, { let bytes = serde_json::to_vec(&payload)?; - + let signature = sign(&bytes) .into_result() .map_err(ICPSignedError::DerivationError)?; - Ok(Self { - payload, - signature, - }) + Ok(Self { payload, signature }) } pub fn parse(&self, f: F) -> Result> @@ -309,7 +308,7 @@ impl ICPSigned { F: FnOnce(&T) -> R, { let bytes = serde_json::to_vec(&self.payload)?; - + let signer_id = f(&self.payload) .into_result() .map_err(ICPSignedError::DerivationError)?; diff --git a/contracts/icp/context-config/tests/integration.rs b/contracts/icp/context-config/tests/integration.rs index b142116b5..98a8c165b 100644 --- a/contracts/icp/context-config/tests/integration.rs +++ b/contracts/icp/context-config/tests/integration.rs @@ -1,6 +1,6 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use calimero_context_config::repr::ReprBytes; +use calimero_context_config::repr::ReprBytes; use candid::Principal; use context_contract::types::{ ContextRequest, ContextRequestKind, ICApplication, ICApplicationId, ICBlobId, ICCapability,