Skip to content

Commit

Permalink
feat: update proxy query + context functions
Browse files Browse the repository at this point in the history
  • Loading branch information
frdomovic committed Dec 3, 2024
1 parent 5e92b50 commit b306727
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion contracts/icp/context-config/context_contract.did
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ service : () -> {
privileges : (blob, vec blob) -> (
vec record { blob; vec ICCapability },
) query;
proxy_contract : (blob) -> (principal) query;
proxy_contract : (blob) -> (text) query;
set_proxy_code : (blob) -> (Result);
}
22 changes: 12 additions & 10 deletions contracts/icp/context-config/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ fn application_revision(context_id: ICContextId) -> u64 {
}

#[query]
fn proxy_contract(context_id: ICContextId) -> Principal {
CONTEXT_CONFIGS.with(|configs| {
let configs = configs.borrow();
let context = configs
.contexts
.get(&context_id)
.expect("context does not exist");

(*context.proxy).clone()
})
fn proxy_contract(context_id: ICContextId) -> String {
CONTEXT_CONFIGS
.with(|configs: &std::cell::RefCell<crate::ContextConfigs>| {
let configs = configs.borrow();
let context = configs
.contexts
.get(&context_id)
.expect("context does not exist");

(*context.proxy).clone()
})
.to_string()
}

#[query]
Expand Down
9 changes: 2 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,7 +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::icp::{ICContextId, ICContextIdentity};
use crate::client::env::config::types::starknet::{
CallData, StarknetMembers, StarknetMembersRequest,
};
Expand Down Expand Up @@ -108,12 +108,7 @@ impl Method<Icp> for MembersRequest {
fn encode(self) -> eyre::Result<Vec<u8>> {
let context_id: ICContextId = (*self.context_id).rt()?;

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

fn decode(response: Vec<u8>) -> eyre::Result<Self::Returns> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use candid::Decode;
use candid::{Decode, Encode};
use serde::Serialize;
use starknet::core::codec::Encode as StarknetEncode;
use starknet_crypto::Felt;

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::repr::Repr;
use crate::repr::{Repr, ReprTransmute};
use crate::types::ContextId;

#[derive(Copy, Clone, Debug, Serialize)]
Expand Down Expand Up @@ -66,7 +67,8 @@ impl Method<Icp> for ProxyContractRequest {
type Returns = String;

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

fn decode(response: Vec<u8>) -> eyre::Result<Self::Returns> {
Expand Down

0 comments on commit b306727

Please sign in to comment.