Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov committed Nov 29, 2024
1 parent 6cfc54c commit f4194bb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 41 deletions.
2 changes: 1 addition & 1 deletion contracts/icp/context-config/src/guard.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions contracts/icp/context-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
42 changes: 13 additions & 29 deletions contracts/icp/context-config/src/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Request>) -> Result<(), String> {
Expand All @@ -29,14 +27,7 @@ pub fn mutate(signed_request: ICPSigned<Request>) -> 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())
}
Expand All @@ -46,20 +37,16 @@ pub fn mutate(signed_request: ICPSigned<Request>) -> 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(())
Expand All @@ -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")],
Expand Down
1 change: 1 addition & 0 deletions contracts/icp/context-config/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;

use calimero_context_config::repr::ReprTransmute;
use ic_cdk_macros::query;

Expand Down
15 changes: 7 additions & 8 deletions contracts/icp/context-config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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: F) -> repr::Result<Self, Self::Error>
Expand Down Expand Up @@ -292,15 +294,12 @@ impl<T: CandidType + Serialize + Clone> ICPSigned<T> {
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<R, F>(&self, f: F) -> Result<T, ICPSignedError<R::Error>>
Expand All @@ -309,7 +308,7 @@ impl<T: CandidType + Serialize + Clone> ICPSigned<T> {
F: FnOnce(&T) -> R,
{
let bytes = serde_json::to_vec(&self.payload)?;

let signer_id = f(&self.payload)
.into_result()
.map_err(ICPSignedError::DerivationError)?;
Expand Down
2 changes: 1 addition & 1 deletion contracts/icp/context-config/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit f4194bb

Please sign in to comment.