From ec95a93bbd2c12af2fef26763eb9d5fa223e9df1 Mon Sep 17 00:00:00 2001 From: alenmestrov Date: Sun, 1 Dec 2024 18:30:28 +0100 Subject: [PATCH] fix: linter --- .../config/src/client/env/config/mutate.rs | 2 +- .../src/client/env/config/query/privileges.rs | 12 ++- .../config/src/client/env/config/types.rs | 2 +- .../config/src/client/env/config/types/icp.rs | 101 ++++++++++-------- 4 files changed, 64 insertions(+), 53 deletions(-) diff --git a/crates/context/config/src/client/env/config/mutate.rs b/crates/context/config/src/client/env/config/mutate.rs index 08c2d3b4d..819875d4b 100644 --- a/crates/context/config/src/client/env/config/mutate.rs +++ b/crates/context/config/src/client/env/config/mutate.rs @@ -6,7 +6,7 @@ use starknet::core::codec::Encode as StarknetEncode; use starknet::signers::SigningKey as StarknetSigningKey; use starknet_crypto::{poseidon_hash_many, Felt}; -use super::types::icp::{ICPSigned, ICPRequest}; +use super::types::icp::{ICPRequest, ICPSigned}; use super::types::starknet::{Request as StarknetRequest, Signed as StarknetSigned}; use crate::client::env::{utils, Method}; use crate::client::protocol::icp::Icp; diff --git a/crates/context/config/src/client/env/config/query/privileges.rs b/crates/context/config/src/client/env/config/query/privileges.rs index 671c5e194..eb5d2cfe0 100644 --- a/crates/context/config/src/client/env/config/query/privileges.rs +++ b/crates/context/config/src/client/env/config/query/privileges.rs @@ -6,7 +6,9 @@ use serde::Serialize; use starknet::core::codec::{Decode as StarknetDecode, Encode as StarknetEncode, FeltWriter}; use starknet_crypto::Felt; -use crate::client::env::config::types::icp::{ICCapability, ICContextId, ICContextIdentity, ICSignerId}; +use crate::client::env::config::types::icp::{ + ICCapability, ICContextId, ICContextIdentity, ICSignerId, +}; use crate::client::env::config::types::starknet::{ CallData, ContextId as StarknetContextId, ContextIdentity as StarknetContextIdentity, StarknetPrivileges, @@ -138,17 +140,17 @@ impl<'a> Method for PrivilegesRequest<'a> { fn encode(self) -> eyre::Result> { // Convert context_id and identities to ICP types let context_id: ICContextId = (*self.context_id).rt()?; - let identities: Vec = self.identities + let identities: Vec = self + .identities .iter() .map(|id| (*id).rt()) .collect::, _>>()?; // Create a tuple of the values we want to encode let payload = (context_id, identities); - + // Encode using Candid - Encode!(&payload) - .map_err(|e| eyre::eyre!("Failed to encode privileges request: {}", e)) + Encode!(&payload).map_err(|e| eyre::eyre!("Failed to encode privileges request: {}", e)) } fn decode(response: Vec) -> eyre::Result { diff --git a/crates/context/config/src/client/env/config/types.rs b/crates/context/config/src/client/env/config/types.rs index aa1efa641..916121133 100644 --- a/crates/context/config/src/client/env/config/types.rs +++ b/crates/context/config/src/client/env/config/types.rs @@ -1,2 +1,2 @@ +pub mod icp; pub mod starknet; -pub mod icp; \ No newline at end of file diff --git a/crates/context/config/src/client/env/config/types/icp.rs b/crates/context/config/src/client/env/config/types/icp.rs index c07c0670f..779745c01 100644 --- a/crates/context/config/src/client/env/config/types/icp.rs +++ b/crates/context/config/src/client/env/config/types/icp.rs @@ -1,20 +1,18 @@ use std::borrow::Cow; use std::marker::PhantomData; - - use bs58::decode::Result as Bs58Result; -use crate::repr::{self, LengthMismatch, Repr, ReprBytes, ReprTransmute}; -use crate::RequestKind; -use crate::types::{ - Application, ApplicationMetadata, ApplicationSource, Capability, IntoResult, SignerId, -}; use candid::CandidType; use ed25519_dalek::{Verifier, VerifyingKey}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use thiserror::Error as ThisError; -use crate::ContextRequestKind; + +use crate::repr::{self, LengthMismatch, Repr, ReprBytes, ReprTransmute}; +use crate::types::{ + Application, ApplicationMetadata, ApplicationSource, Capability, IntoResult, SignerId, +}; +use crate::{ContextRequestKind, RequestKind}; #[derive( CandidType, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Hash, @@ -68,9 +66,9 @@ impl ReprBytes for ICSignerId { // From implementation for SignerId impl From for SignerId { - fn from(value: ICSignerId) -> Self { - value.rt().expect("infallible conversion") - } + fn from(value: ICSignerId) -> Self { + value.rt().expect("infallible conversion") + } } #[derive( @@ -231,13 +229,13 @@ pub enum ICCapability { // From implementation for Capability impl From for Capability { - fn from(value: ICCapability) -> Self { - match value { - ICCapability::ManageApplication => Capability::ManageApplication, - ICCapability::ManageMembers => Capability::ManageMembers, - ICCapability::Proxy => Capability::Proxy, - } - } + fn from(value: ICCapability) -> Self { + match value { + ICCapability::ManageApplication => Capability::ManageApplication, + ICCapability::ManageMembers => Capability::ManageMembers, + ICCapability::Proxy => Capability::Proxy, + } + } } #[derive(CandidType, Serialize, Deserialize, Debug, Clone)] @@ -396,49 +394,60 @@ impl From for ICCapability { } } - impl From> for ICPRequestKind { fn from(value: RequestKind<'_>) -> Self { match value { RequestKind::Context(context_request) => ICPRequestKind::Context(ICPContextRequest { - context_id: context_request.context_id.rt().expect("infallible conversion"), + context_id: context_request + .context_id + .rt() + .expect("infallible conversion"), kind: match context_request.kind { - ContextRequestKind::Add { author_id, application } => ICPContextRequestKind::Add { + ContextRequestKind::Add { + author_id, + application, + } => ICPContextRequestKind::Add { author_id: author_id.rt().expect("infallible conversion"), application: application.into(), }, - ContextRequestKind::UpdateApplication { application } => ICPContextRequestKind::UpdateApplication { - application: application.into(), - }, - ContextRequestKind::AddMembers { members } => ICPContextRequestKind::AddMembers { - members: members.into_iter() - .map(|m| m.rt().expect("infallible conversion")) - .collect(), - }, - ContextRequestKind::RemoveMembers { members } => ICPContextRequestKind::RemoveMembers { - members: members.into_iter() - .map(|m| m.rt().expect("infallible conversion")) - .collect(), - }, + ContextRequestKind::UpdateApplication { application } => { + ICPContextRequestKind::UpdateApplication { + application: application.into(), + } + } + ContextRequestKind::AddMembers { members } => { + ICPContextRequestKind::AddMembers { + members: members + .into_iter() + .map(|m| m.rt().expect("infallible conversion")) + .collect(), + } + } + ContextRequestKind::RemoveMembers { members } => { + ICPContextRequestKind::RemoveMembers { + members: members + .into_iter() + .map(|m| m.rt().expect("infallible conversion")) + .collect(), + } + } ContextRequestKind::Grant { capabilities } => ICPContextRequestKind::Grant { - capabilities: capabilities.into_iter() - .map(|(id, cap)| ( - id.rt().expect("infallible conversion"), - cap.into() - )) + capabilities: capabilities + .into_iter() + .map(|(id, cap)| (id.rt().expect("infallible conversion"), cap.into())) .collect(), }, ContextRequestKind::Revoke { capabilities } => ICPContextRequestKind::Revoke { - capabilities: capabilities.into_iter() - .map(|(id, cap)| ( - id.rt().expect("infallible conversion"), - cap.into() - )) + capabilities: capabilities + .into_iter() + .map(|(id, cap)| (id.rt().expect("infallible conversion"), cap.into())) .collect(), }, - ContextRequestKind::UpdateProxyContract => ICPContextRequestKind::UpdateProxyContract, + ContextRequestKind::UpdateProxyContract => { + ICPContextRequestKind::UpdateProxyContract + } }, }), } } -} \ No newline at end of file +}