Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov committed Dec 1, 2024
1 parent f9444f2 commit ec95a93
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 53 deletions.
2 changes: 1 addition & 1 deletion crates/context/config/src/client/env/config/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions crates/context/config/src/client/env/config/query/privileges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,17 +140,17 @@ impl<'a> Method<Icp> for PrivilegesRequest<'a> {
fn encode(self) -> eyre::Result<Vec<u8>> {
// Convert context_id and identities to ICP types
let context_id: ICContextId = (*self.context_id).rt()?;
let identities: Vec<ICContextIdentity> = self.identities
let identities: Vec<ICContextIdentity> = self
.identities
.iter()
.map(|id| (*id).rt())
.collect::<Result<Vec<_>, _>>()?;

// 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<u8>) -> eyre::Result<Self::Returns> {
Expand Down
2 changes: 1 addition & 1 deletion crates/context/config/src/client/env/config/types.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod icp;
pub mod starknet;
pub mod icp;
101 changes: 55 additions & 46 deletions crates/context/config/src/client/env/config/types/icp.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -68,9 +66,9 @@ impl ReprBytes for ICSignerId {

// From implementation for SignerId
impl From<ICSignerId> for SignerId {
fn from(value: ICSignerId) -> Self {
value.rt().expect("infallible conversion")
}
fn from(value: ICSignerId) -> Self {
value.rt().expect("infallible conversion")
}
}

#[derive(
Expand Down Expand Up @@ -231,13 +229,13 @@ pub enum ICCapability {

// From implementation for Capability
impl From<ICCapability> 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)]
Expand Down Expand Up @@ -396,49 +394,60 @@ impl From<Capability> for ICCapability {
}
}


impl From<RequestKind<'_>> 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
}
},
}),
}
}
}
}

0 comments on commit ec95a93

Please sign in to comment.