Skip to content

Commit

Permalink
chore: improve client SDK with CanisterCaller trait
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jan 18, 2025
1 parent ebf72f0 commit 0ac7c0d
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 570 deletions.
11 changes: 6 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ strip = true
opt-level = 's'

[workspace.package]
version = "0.6.5"
version = "0.6.6"
edition = "2021"
repository = "https://github.com/ldclabs/ic-cose"
keywords = ["config", "cbor", "canister", "icp", "encryption"]
Expand Down
1 change: 1 addition & 0 deletions src/ic_cose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ categories.workspace = true
license.workspace = true

[dependencies]
async-trait = { workspace = true }
candid = { workspace = true }
serde_bytes = { workspace = true }
rand = { workspace = true }
Expand Down
46 changes: 0 additions & 46 deletions src/ic_cose/src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use candid::{
utils::{encode_args, ArgumentEncoder},
CandidType, Decode, Principal,
};
use ic_agent::{Agent, Identity};
use ic_cose_types::format_error;
use std::sync::Arc;
Expand All @@ -19,45 +15,3 @@ pub async fn build_agent(host: &str, identity: Arc<dyn Identity>) -> Result<Agen

Ok(agent)
}

pub async fn update_call<In, Out>(
agent: &Agent,
canister_id: &Principal,
method_name: &str,
args: In,
) -> Result<Out, String>
where
In: ArgumentEncoder + Send,
Out: CandidType + for<'a> candid::Deserialize<'a>,
{
let input = encode_args(args).map_err(format_error)?;
let res = agent
.update(canister_id, method_name)
.with_arg(input)
.call_and_wait()
.await
.map_err(format_error)?;
let output = Decode!(res.as_slice(), Out).map_err(format_error)?;
Ok(output)
}

pub async fn query_call<In, Out>(
agent: &Agent,
canister_id: &Principal,
method_name: &str,
args: In,
) -> Result<Out, String>
where
In: ArgumentEncoder + Send,
Out: CandidType + for<'a> candid::Deserialize<'a>,
{
let input = encode_args(args).map_err(format_error)?;
let res = agent
.query(canister_id, method_name)
.with_arg(input)
.call()
.await
.map_err(format_error)?;
let output = Decode!(res.as_slice(), Out).map_err(format_error)?;
Ok(output)
}
Loading

0 comments on commit 0ac7c0d

Please sign in to comment.