Skip to content

Commit 0aa2b05

Browse files
authored
1 parent 4e3bb4b commit 0aa2b05

File tree

18 files changed

+297
-326
lines changed

18 files changed

+297
-326
lines changed

Cargo.lock

Lines changed: 42 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ ic-http-types = { workspace = true }
3030
ic-metrics-encoder = { workspace = true }
3131
ic-stable-structures = { workspace = true }
3232
ic-cdk = { workspace = true }
33-
ic-cdk-macros = { workspace = true }
3433
ic-management-canister-types = { workspace = true }
3534
maplit = { workspace = true }
3635
minicbor = { workspace = true }
@@ -75,7 +74,7 @@ alloy-rpc-types = "1.0.23"
7574
assert_matches = "1.5.0"
7675
async-trait = "0.1.88"
7776
candid = { version = "0.10.13" }
78-
canhttp = { version = "0.2.0", features = ["json", "multi"] }
77+
canhttp = { version = "0.3.0", features = ["json", "multi"] }
7978
canlog = { version = "0.2.0", features = ["derive"] }
8079
candid_parser = { version = "0.1.4" }
8180
derive_more = { version = "2.0.1", features = ["from", "into"] }
@@ -84,7 +83,7 @@ ethnum = { version = "1.5.0", features = ["serde"] }
8483
getrandom = { version = "0.2", features = ["custom"] }
8584
hex = "0.4.3"
8685
http = "1.3.1"
87-
ic-cdk = "0.17.2"
86+
ic-cdk = "0.18.7"
8887
ic-cdk-bindgen = "0.1"
8988
ic-cdk-macros = "0.17.2"
9089
ic-certified-map = "0.4"

e2e/motoko/main.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ shared ({ caller = installer }) persistent actor class Main() {
1414

1515
// (`subnet name`, `nodes in subnet`, `expected cycles for JSON-RPC call`)
1616
type SubnetTarget = (Text, Nat32, Nat);
17-
transient let fiduciarySubnet : SubnetTarget = ("fiduciary", 34, 540_545_600);
17+
transient let fiduciarySubnet : SubnetTarget = ("fiduciary", 34, 400_299_200);
1818

1919
transient let testTargets = [
2020
// (`canister module`, `canister type`, `subnet`)

e2e/rust/src/main.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use std::str::FromStr;
2-
31
use candid::{candid_method, Principal};
4-
use ic_cdk_macros::update;
5-
62
use evm_rpc_types::{
73
Block, BlockTag, ConsensusStrategy, EthMainnetService, Hex32, MultiRpcResult, ProviderError,
84
RpcConfig, RpcError, RpcResult, RpcService, RpcServices,
95
};
6+
use ic_cdk::{call::Call, update};
7+
use std::str::FromStr;
108

119
fn main() {}
1210

@@ -21,7 +19,7 @@ const CANISTER_ID: Option<&str> = None;
2119
#[update]
2220
#[candid_method(update)]
2321
pub async fn test() {
24-
assert!(ic_cdk::api::is_controller(&ic_cdk::caller()));
22+
assert!(ic_cdk::api::is_controller(&ic_cdk::api::msg_caller()));
2523

2624
let canister_id = Principal::from_str(CANISTER_ID.unwrap())
2725
.expect("Error parsing canister ID environment variable");
@@ -34,18 +32,22 @@ pub async fn test() {
3432
);
3533

3634
// Get cycles cost
37-
let (cycles_result,): (Result<u128, RpcError>,) =
38-
ic_cdk::api::call::call(canister_id, "requestCost", params.clone())
39-
.await
40-
.unwrap();
35+
let cycles_result = Call::unbounded_wait(canister_id, "requestCost")
36+
.with_args(&params)
37+
.await
38+
.unwrap()
39+
.candid::<Result<u128, RpcError>>()
40+
.unwrap();
4141
let cycles = cycles_result
4242
.unwrap_or_else(|e| ic_cdk::trap(&format!("error in `request_cost`: {:?}", e)));
4343

4444
// Call without sending cycles
45-
let (result_without_cycles,): (Result<String, RpcError>,) =
46-
ic_cdk::api::call::call(canister_id, "request", params.clone())
47-
.await
48-
.unwrap();
45+
let result_without_cycles = Call::unbounded_wait(canister_id, "request")
46+
.with_args(&params)
47+
.await
48+
.unwrap()
49+
.candid::<Result<String, RpcError>>()
50+
.unwrap();
4951
match result_without_cycles {
5052
Ok(s) => ic_cdk::trap(&format!("response from `request` without cycles: {:?}", s)),
5153
Err(RpcError::ProviderError(ProviderError::TooFewCycles { expected, .. })) => {
@@ -55,10 +57,13 @@ pub async fn test() {
5557
}
5658

5759
// Call with expected number of cycles
58-
let (result,): (Result<String, RpcError>,) =
59-
ic_cdk::api::call::call_with_payment128(canister_id, "request", params, cycles)
60-
.await
61-
.unwrap();
60+
let result: Result<String, RpcError> = Call::unbounded_wait(canister_id, "request")
61+
.with_args(&params)
62+
.with_cycles(cycles)
63+
.await
64+
.unwrap()
65+
.candid::<Result<String, RpcError>>()
66+
.unwrap();
6267
match result {
6368
Ok(response) => {
6469
// Check response structure around gas price
@@ -72,10 +77,8 @@ pub async fn test() {
7277
}
7378

7479
// Call a Candid-RPC method
75-
let (results,): (MultiRpcResult<Block>,) = ic_cdk::api::call::call_with_payment128(
76-
canister_id,
77-
"eth_getBlockByNumber",
78-
(
80+
let results = Call::unbounded_wait(canister_id, "eth_getBlockByNumber")
81+
.with_args(&(
7982
RpcServices::EthMainnet(Some(vec![
8083
// EthMainnetService::Ankr, // Need API key
8184
EthMainnetService::BlockPi,
@@ -90,11 +93,12 @@ pub async fn test() {
9093
..Default::default()
9194
}),
9295
BlockTag::Number(19709434_u32.into()),
93-
),
94-
10000000000,
95-
)
96-
.await
97-
.unwrap();
96+
))
97+
.with_cycles(10000000000)
98+
.await
99+
.unwrap()
100+
.candid::<MultiRpcResult<Block>>()
101+
.unwrap();
98102
match results {
99103
MultiRpcResult::Consistent(result) => match result {
100104
Ok(block) => {

evm_rpc_client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ic-error-types = { workspace = true }
2121
serde = { workspace = true }
2222
serde_json = { workspace = true }
2323
strum = { workspace = true }
24+
thiserror = { workspace = true }
2425

2526
[dev-dependencies]
2627
alloy-dyn-abi = { workspace = true }

evm_rpc_client/src/fixtures/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
//!
33
//! Types and methods for this module are only available for non-canister architecture (non `wasm32`).
44
5-
use crate::{ClientBuilder, Runtime};
5+
use crate::{ClientBuilder, IcError, Runtime};
66
use async_trait::async_trait;
77
use candid::{utils::ArgumentEncoder, CandidType, Decode, Encode, Principal};
8-
use ic_error_types::RejectCode;
98
use serde::de::DeserializeOwned;
109
use std::collections::BTreeMap;
1110

@@ -82,7 +81,7 @@ impl StubRuntime {
8281
self
8382
}
8483

85-
fn call<Out>(&self, method: &str) -> Result<Out, (RejectCode, String)>
84+
fn call<Out>(&self, method: &str) -> Result<Out, IcError>
8685
where
8786
Out: CandidType + DeserializeOwned,
8887
{
@@ -109,7 +108,7 @@ impl Runtime for StubRuntime {
109108
method: &str,
110109
_args: In,
111110
_cycles: u128,
112-
) -> Result<Out, (RejectCode, String)>
111+
) -> Result<Out, IcError>
113112
where
114113
In: ArgumentEncoder + Send,
115114
Out: CandidType + DeserializeOwned,
@@ -122,7 +121,7 @@ impl Runtime for StubRuntime {
122121
_id: Principal,
123122
method: &str,
124123
_args: In,
125-
) -> Result<Out, (RejectCode, String)>
124+
) -> Result<Out, IcError>
126125
where
127126
In: ArgumentEncoder + Send,
128127
Out: CandidType + DeserializeOwned,

evm_rpc_client/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ use evm_rpc_types::{
127127
BlockTag, CallArgs, ConsensusStrategy, FeeHistoryArgs, GetLogsArgs, GetTransactionCountArgs,
128128
Hex, Hex32, RpcConfig, RpcServices,
129129
};
130-
use ic_error_types::RejectCode;
131130
#[cfg(feature = "alloy")]
132131
pub use request::alloy::AlloyResponseConverter;
133132
use request::{
@@ -139,7 +138,7 @@ use request::{
139138
SendRawTransactionRequest, SendRawTransactionRequestBuilder,
140139
};
141140
pub use request::{CandidResponseConverter, EvmRpcConfig};
142-
pub use runtime::{IcRuntime, Runtime};
141+
pub use runtime::{IcError, IcRuntime, Runtime};
143142
use serde::de::DeserializeOwned;
144143
use std::sync::Arc;
145144

@@ -783,7 +782,7 @@ impl<R: Runtime, C> EvmRpcClient<R, C> {
783782
async fn try_execute_request<Config, Params, CandidOutput, Output>(
784783
&self,
785784
request: Request<Config, Params, CandidOutput, Output>,
786-
) -> Result<Output, (RejectCode, String)>
785+
) -> Result<Output, IcError>
787786
where
788787
Config: CandidType + Send,
789788
Params: CandidType + Send,

evm_rpc_client/src/request/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#[cfg(feature = "alloy")]
22
pub(crate) mod alloy;
33

4+
use crate::runtime::IcError;
45
use crate::{EvmRpcClient, Runtime};
56
use candid::CandidType;
67
use evm_rpc_types::{
78
BlockTag, CallArgs, ConsensusStrategy, FeeHistoryArgs, GetLogsArgs, GetLogsRpcConfig,
89
GetTransactionCountArgs, Hex, Hex20, Hex32, MultiRpcResult, Nat256, RpcConfig, RpcServices,
910
};
10-
use ic_error_types::RejectCode;
1111
use serde::de::DeserializeOwned;
1212
use std::fmt::{Debug, Formatter};
1313
use strum::EnumIter;
@@ -508,7 +508,7 @@ impl<R: Runtime, Converter, Config, Params, CandidOutput, Output>
508508

509509
/// Constructs the [`Request`] and sends it using the [`EvmRpcClient`]. This method returns
510510
/// either the request response or any error that occurs while sending the request.
511-
pub async fn try_send(self) -> Result<Output, (RejectCode, String)>
511+
pub async fn try_send(self) -> Result<Output, IcError>
512512
where
513513
Config: CandidType + Send,
514514
Params: CandidType + Send,

0 commit comments

Comments
 (0)