Skip to content

Commit

Permalink
fix: update method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
frdomovic committed Dec 2, 2024
1 parent ec95a93 commit 0dcd406
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 31 deletions.
6 changes: 5 additions & 1 deletion crates/context/config/src/client/env/config/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::client::protocol::near::Near;
use crate::client::protocol::starknet::Starknet;
use crate::client::transport::Transport;
use crate::client::{CallClient, ClientError, Operation};
// use crate::icpTypes::ICMutate;
use crate::repr::{Repr, ReprTransmute};
use crate::types::Signed;
use crate::{ContextIdentity, Request, RequestKind};
Expand Down Expand Up @@ -142,7 +141,12 @@ impl<'a> Method<Icp> for Mutate<'a> {

let signed = ICPSigned::new(request, |b| signer_sk.sign(b))?;

let encoded2 = Encode!(&signed)?;

let encoded = candid::encode_one(&signed)?;

println!("encoded: {:?}", encoded);
println!("encoded2: {:?}", encoded2);

Ok(encoded)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use serde::Serialize;
use starknet::core::codec::{Decode as StarknetDecode, Encode as StarknetEncode};
use starknet_crypto::Felt;

use crate::client::env::config::types::icp::{ICApplication, ICContextId};
use crate::client::env::config::types::starknet::{
Application as StarknetApplication, CallData, FeltPair,
};
use crate::client::env::Method;
use crate::client::protocol::icp::Icp;
use crate::client::protocol::near::Near;
use crate::client::protocol::starknet::Starknet;
use crate::icpTypes::{ICApplication, ICContextId};
use crate::repr::Repr;
use crate::repr::{Repr, ReprTransmute};
use crate::types::{Application, ApplicationMetadata, ApplicationSource, ContextId};

#[derive(Copy, Clone, Debug, Serialize)]
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Method<Icp> for ApplicationRequest {
const METHOD: &'static str = "application";

fn encode(self) -> eyre::Result<Vec<u8>> {
let context_id: ICContextId = self.context_id.into();
let context_id: ICContextId = (*self.context_id).rt()?;
Encode!(&context_id).map_err(|e| eyre::eyre!(e))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use candid::{Decode, Encode};
use serde::Serialize;
use starknet::core::codec::Encode as StarknetEncode;

use crate::client::env::config::types::icp::ICContextId;
use crate::client::env::config::types::starknet::{CallData, FeltPair};
use crate::client::env::Method;
use crate::client::protocol::icp::Icp;
use crate::client::protocol::near::Near;
use crate::client::protocol::starknet::Starknet;
use crate::icpTypes::ICContextId;
use crate::repr::Repr;
use crate::repr::{Repr, ReprTransmute};
use crate::types::{ContextId, Revision};

#[derive(Copy, Clone, Debug, Serialize)]
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Method<Icp> for ApplicationRevisionRequest {
const METHOD: &'static str = "application_revision";

fn encode(self) -> eyre::Result<Vec<u8>> {
let context_id: ICContextId = self.context_id.into();
let context_id: ICContextId = (*self.context_id).rt()?;
Encode!(&context_id).map_err(|e| eyre::eyre!(e))
}

Expand Down
17 changes: 7 additions & 10 deletions crates/context/config/src/client/env/config/query/has_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use candid::{Decode, Encode};
use serde::Serialize;
use starknet::core::codec::Encode as StarknetEncode;

use crate::client::env::config::types::icp::{ICContextId, ICContextIdentity};
use crate::client::env::config::types::starknet::{CallData, FeltPair};
use crate::client::env::Method;
use crate::client::protocol::icp::Icp;
use crate::client::protocol::near::Near;
use crate::client::protocol::starknet::Starknet;
use crate::icpTypes::{ICContextId, ICContextIdentity, ICHasMemberRequest};
use crate::repr::Repr;
use crate::repr::{Repr, ReprTransmute};
use crate::types::{ContextId, ContextIdentity};

#[derive(Copy, Clone, Debug, Serialize)]
Expand Down Expand Up @@ -80,14 +80,11 @@ impl Method<Icp> for HasMemberRequest {
const METHOD: &'static str = "has_member";

fn encode(self) -> eyre::Result<Vec<u8>> {
let context_id: ICContextId = self.context_id.into();
let identity: ICContextIdentity = self.identity.into();
let request = ICHasMemberRequest {
context_id,
identity,
};

Encode!(&request).map_err(|e| eyre::eyre!(e))
let context_id: ICContextId = (*self.context_id).rt()?;
let identity: ICContextIdentity = (*self.identity).rt()?;
let payload = (context_id, identity);

Encode!(&payload).map_err(|e| eyre::eyre!(e))
}

fn decode(response: Vec<u8>) -> eyre::Result<Self::Returns> {
Expand Down
19 changes: 12 additions & 7 deletions crates/context/config/src/client/env/config/query/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use serde::Serialize;
use starknet::core::codec::{Decode as StarknetDecode, Encode as StarknetEncode};
use starknet_crypto::Felt;

use crate::client::env::config::types::icp::{ICContextId, ICContextIdentity, ICMembersRequest};
use crate::client::env::config::types::starknet::{
CallData, StarknetMembers, StarknetMembersRequest,
};
use crate::client::env::Method;
use crate::client::protocol::icp::Icp;
use crate::client::protocol::near::Near;
use crate::client::protocol::starknet::Starknet;
use crate::icpTypes::{ICContextId, ICContextIdentity, ICMembersRequest};
use crate::repr::Repr;
use crate::repr::{Repr, ReprTransmute};
use crate::types::{ContextId, ContextIdentity};

#[derive(Copy, Clone, Debug, Serialize)]
Expand Down Expand Up @@ -106,19 +106,24 @@ impl Method<Icp> for MembersRequest {
const METHOD: &'static str = "members";

fn encode(self) -> eyre::Result<Vec<u8>> {
let context_id: ICContextId = self.context_id.into();
let request = ICMembersRequest {
let context_id: ICContextId = (*self.context_id).rt()?;

let payload: ICMembersRequest = ICMembersRequest {
context_id,
offset: self.offset,
length: self.length,
};
Encode!(&request).map_err(|e| eyre::eyre!(e))
Encode!(&payload).map_err(|e| eyre::eyre!(e))
}

fn decode(response: Vec<u8>) -> eyre::Result<Self::Returns> {
let decoded: Vec<ICContextIdentity> = Decode!(&response, Vec<ICContextIdentity>)?;
let value: Vec<ContextIdentity> = decoded.into_iter().map(ContextIdentity::from).collect();

Ok(value)
let converted: Result<Vec<ContextIdentity>, _> = decoded
.into_iter()
.map(|id| id.rt())
.collect();

Ok(converted?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use candid::{Decode, Encode};
use serde::Serialize;
use starknet::core::codec::Encode as StarknetEncode;

use crate::client::env::config::types::icp::ICContextId;
use crate::client::env::config::types::starknet::{CallData, ContextId as StarknetContextId};
use crate::client::env::Method;
use crate::client::protocol::icp::Icp;
use crate::client::protocol::near::Near;
use crate::client::protocol::starknet::Starknet;
use crate::icpTypes::ICContextId;
use crate::repr::Repr;
use crate::repr::{Repr, ReprTransmute};
use crate::types::{ContextId, Revision};

#[derive(Copy, Clone, Debug, Serialize)]
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Method<Icp> for MembersRevisionRequest {
const METHOD: &'static str = "members_revision";

fn encode(self) -> eyre::Result<Vec<u8>> {
let context_id: ICContextId = self.context_id.into();
let context_id: ICContextId = (*self.context_id).rt()?;
Encode!(&context_id).map_err(|e| eyre::eyre!(e))
}

Expand Down
11 changes: 9 additions & 2 deletions crates/context/config/src/client/env/config/types/icp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ impl ReprBytes for ICBlobId {
}
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct ICMembersRequest {
pub context_id: ICContextId,
pub offset: usize,
pub length: usize,
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct ICApplication {
pub id: ICApplicationId,
Expand Down Expand Up @@ -220,7 +227,7 @@ pub struct ICPContextRequest {
pub kind: ICPContextRequestKind,
}

#[derive(CandidType, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[derive(CandidType, Copy, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum ICCapability {
ManageApplication,
ManageMembers,
Expand Down Expand Up @@ -303,7 +310,7 @@ pub enum ICPSignedError<E> {
}

#[derive(Deserialize, Debug, Clone)]
struct Phantom<T>(#[serde(skip)] std::marker::PhantomData<T>);
struct Phantom<T>(#[serde(skip)] PhantomData<T>);

impl<T> CandidType for Phantom<T> {
fn _ty() -> candid::types::Type {
Expand Down
5 changes: 3 additions & 2 deletions crates/context/config/src/client/protocol/icp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl Network {
method: String,
args: Vec<u8>,
) -> Result<Vec<u8>, IcpError> {
println!("Here access to query");
self.client
.fetch_root_key()
.await
Expand Down Expand Up @@ -231,9 +232,9 @@ impl Network {
operation: ErrorOperation::Query,
reason: "Unexpected Poll response".to_string(),
}),
Err(_) => Err(IcpError::Custom {
Err(err) => Err(IcpError::Custom {
operation: ErrorOperation::Query,
reason: "No response".to_string(),
reason: err.to_string(),
}),
}
}
Expand Down

0 comments on commit 0dcd406

Please sign in to comment.