From 0dcd4067af5e0c430288eac701c007cacf554952 Mon Sep 17 00:00:00 2001 From: Fran Domovic Date: Mon, 2 Dec 2024 13:36:56 +0100 Subject: [PATCH] fix: update method calls --- .../config/src/client/env/config/mutate.rs | 6 +++++- .../client/env/config/query/application.rs | 6 +++--- .../env/config/query/application_revision.rs | 6 +++--- .../src/client/env/config/query/has_member.rs | 17 +++++++---------- .../src/client/env/config/query/members.rs | 19 ++++++++++++------- .../env/config/query/members_revision.rs | 6 +++--- .../config/src/client/env/config/types/icp.rs | 11 +++++++++-- .../context/config/src/client/protocol/icp.rs | 5 +++-- 8 files changed, 45 insertions(+), 31 deletions(-) diff --git a/crates/context/config/src/client/env/config/mutate.rs b/crates/context/config/src/client/env/config/mutate.rs index 819875d4b..e6e83ef9e 100644 --- a/crates/context/config/src/client/env/config/mutate.rs +++ b/crates/context/config/src/client/env/config/mutate.rs @@ -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}; @@ -142,7 +141,12 @@ impl<'a> Method 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) } diff --git a/crates/context/config/src/client/env/config/query/application.rs b/crates/context/config/src/client/env/config/query/application.rs index 5662b4e2e..96a5508e7 100644 --- a/crates/context/config/src/client/env/config/query/application.rs +++ b/crates/context/config/src/client/env/config/query/application.rs @@ -3,6 +3,7 @@ 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, }; @@ -10,8 +11,7 @@ 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)] @@ -101,7 +101,7 @@ impl Method for ApplicationRequest { const METHOD: &'static str = "application"; fn encode(self) -> eyre::Result> { - 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)) } diff --git a/crates/context/config/src/client/env/config/query/application_revision.rs b/crates/context/config/src/client/env/config/query/application_revision.rs index 474c518f5..2a63bad86 100644 --- a/crates/context/config/src/client/env/config/query/application_revision.rs +++ b/crates/context/config/src/client/env/config/query/application_revision.rs @@ -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)] @@ -64,7 +64,7 @@ impl Method for ApplicationRevisionRequest { const METHOD: &'static str = "application_revision"; fn encode(self) -> eyre::Result> { - 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)) } diff --git a/crates/context/config/src/client/env/config/query/has_member.rs b/crates/context/config/src/client/env/config/query/has_member.rs index 82a8ba7ad..060d29130 100644 --- a/crates/context/config/src/client/env/config/query/has_member.rs +++ b/crates/context/config/src/client/env/config/query/has_member.rs @@ -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)] @@ -80,14 +80,11 @@ impl Method for HasMemberRequest { const METHOD: &'static str = "has_member"; fn encode(self) -> eyre::Result> { - 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) -> eyre::Result { diff --git a/crates/context/config/src/client/env/config/query/members.rs b/crates/context/config/src/client/env/config/query/members.rs index 5acb8ecfc..828aec959 100644 --- a/crates/context/config/src/client/env/config/query/members.rs +++ b/crates/context/config/src/client/env/config/query/members.rs @@ -5,6 +5,7 @@ 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, }; @@ -12,8 +13,7 @@ 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)] @@ -106,19 +106,24 @@ impl Method for MembersRequest { const METHOD: &'static str = "members"; fn encode(self) -> eyre::Result> { - 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) -> eyre::Result { let decoded: Vec = Decode!(&response, Vec)?; - let value: Vec = decoded.into_iter().map(ContextIdentity::from).collect(); - Ok(value) + let converted: Result, _> = decoded + .into_iter() + .map(|id| id.rt()) + .collect(); + + Ok(converted?) } } diff --git a/crates/context/config/src/client/env/config/query/members_revision.rs b/crates/context/config/src/client/env/config/query/members_revision.rs index 8759de6d1..60fc82a67 100644 --- a/crates/context/config/src/client/env/config/query/members_revision.rs +++ b/crates/context/config/src/client/env/config/query/members_revision.rs @@ -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)] @@ -73,7 +73,7 @@ impl Method for MembersRevisionRequest { const METHOD: &'static str = "members_revision"; fn encode(self) -> eyre::Result> { - 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)) } 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 779745c01..861dc913b 100644 --- a/crates/context/config/src/client/env/config/types/icp.rs +++ b/crates/context/config/src/client/env/config/types/icp.rs @@ -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, @@ -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, @@ -303,7 +310,7 @@ pub enum ICPSignedError { } #[derive(Deserialize, Debug, Clone)] -struct Phantom(#[serde(skip)] std::marker::PhantomData); +struct Phantom(#[serde(skip)] PhantomData); impl CandidType for Phantom { fn _ty() -> candid::types::Type { diff --git a/crates/context/config/src/client/protocol/icp.rs b/crates/context/config/src/client/protocol/icp.rs index 8d9fd557f..a76d0a1e9 100644 --- a/crates/context/config/src/client/protocol/icp.rs +++ b/crates/context/config/src/client/protocol/icp.rs @@ -181,6 +181,7 @@ impl Network { method: String, args: Vec, ) -> Result, IcpError> { + println!("Here access to query"); self.client .fetch_root_key() .await @@ -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(), }), } }