1- use std:: str:: FromStr ;
2-
31use candid:: { candid_method, Principal } ;
4- use ic_cdk_macros:: update;
5-
62use 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
119fn main ( ) { }
1210
@@ -21,7 +19,7 @@ const CANISTER_ID: Option<&str> = None;
2119#[ update]
2220#[ candid_method( update) ]
2321pub 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) => {
0 commit comments