Skip to content

Commit

Permalink
chore: deprecate remaining items in api/call.rs (#546)
Browse files Browse the repository at this point in the history
* remove DecoderConfig from Call API

* deprecate note DecoderConfig

* PhantomData can be used for manual_reply

* deprecation note for ManualReply

* remove api_call.rs e2e test

* move is_recovering_from_trap to futures and re-export in lib.rs

* fix clippy

* deprecation note for the api/call module

* upgrade candid to 0.10.12
  • Loading branch information
lwshang authored Jan 15, 2025
1 parent 5fb07f5 commit 710fc59
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 304 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ic0 = { path = "ic0", version = "0.24.0-alpha.1" }
ic-cdk = { path = "ic-cdk", version = "0.18.0-alpha.1" }
ic-cdk-timers = { path = "ic-cdk-timers", version = "0.12.0-alpha.1" }

candid = "0.10.4"
candid = "0.10.12"
candid_parser = "0.1.4"
futures = "0.3"
hex = "0.4"
Expand Down
28 changes: 0 additions & 28 deletions e2e-tests/src/bin/api_call.rs

This file was deleted.

34 changes: 1 addition & 33 deletions e2e-tests/src/bin/call.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use candid::Encode;
use ic_cdk::api::canister_self;
use ic_cdk::call::{Call, ConfigurableCall, DecoderConfig, SendableCall};
use ic_cdk::call::{Call, ConfigurableCall, SendableCall};
use ic_cdk::update;

/// A simple endpoint that takes empty arguments.
Expand Down Expand Up @@ -44,14 +44,6 @@ async fn call_foo() {
.await
.unwrap();
assert_eq!(res.0, n);
let decoder_config = DecoderConfig::default();

let res: (u32,) = Call::new(canister_self(), "foo")
.with_decoder_config(decoder_config)
.call_tuple()
.await
.unwrap();
assert_eq!(res.0, n);
}

/// A simple endpoint that takes a single `u32` argument and returns it.
Expand Down Expand Up @@ -110,14 +102,6 @@ async fn call_echo_with_arg() {
.await
.unwrap();
assert_eq!(res.0, n);
let decoder_config = DecoderConfig::default();
let res: (u32,) = Call::new(canister_self(), "echo")
.with_arg(n)
.with_decoder_config(decoder_config)
.call_tuple()
.await
.unwrap();
assert_eq!(res.0, n);
}

/// `Call::new(...).with_args(...)` can be configured and called.
Expand Down Expand Up @@ -170,14 +154,6 @@ async fn call_echo_with_args() {
.await
.unwrap();
assert_eq!(res.0, n);
let decoder_config = DecoderConfig::default();
let res: (u32,) = Call::new(canister_self(), "echo")
.with_args((n,))
.with_decoder_config(decoder_config)
.call_tuple()
.await
.unwrap();
assert_eq!(res.0, n);
}

/// Call::new(...).with_raw_args(...) can be configured and called.
Expand Down Expand Up @@ -230,14 +206,6 @@ async fn call_echo_with_raw_args() {
.await
.unwrap();
assert_eq!(res.0, n);
let decoder_config = DecoderConfig::default();
let res: (u32,) = Call::new(canister_self(), "echo")
.with_raw_args(&bytes)
.with_decoder_config(decoder_config)
.call_tuple()
.await
.unwrap();
assert_eq!(res.0, n);
}

fn main() {}
32 changes: 30 additions & 2 deletions e2e-tests/src/bin/macros.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use candid::utils::{decode_args, decode_one};
use ic_cdk::api::msg_arg_data;
use ic_cdk::update;
use ic_cdk::{export_candid, update};
use std::marker::PhantomData;

#[update(decode_with = "decode_u0")]
fn u0() {}
Expand All @@ -25,4 +26,31 @@ fn decode_u2() -> (u32, u32) {
decode_args(&arg_bytes).unwrap()
}

fn main() {}
#[update(manual_reply = true)]
fn u_manual_reply() -> PhantomData<u32> {
let v: u32 = 1;
let reply_bytes = candid::encode_one(v).unwrap();
ic_cdk::api::msg_reply(reply_bytes);
PhantomData
}

export_candid! {}

fn main() {
println!("{}", __export_service());
}

#[cfg(test)]
mod tests {

#[test]
fn check_candid() {
let expected = "service : {
u0 : () -> ();
u1 : (nat32) -> ();
u2 : (nat32, nat32) -> ();
u_manual_reply : () -> (nat32);
}";
assert_eq!(expected, super::__export_service());
}
}
85 changes: 0 additions & 85 deletions e2e-tests/tests/api_call.rs

This file was deleted.

8 changes: 8 additions & 0 deletions e2e-tests/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ fn call_macros() {
(1u32, 2u32),
)
.unwrap();
let _: (u32,) = call_candid(
&pic,
canister_id,
RawEffectivePrincipal::None,
"u_manual_reply",
(),
)
.unwrap();
}
5 changes: 5 additions & 0 deletions ic-cdk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
use candid::Principal;
use std::{convert::TryFrom, num::NonZeroU64};

#[doc(hidden)]
#[deprecated(
since = "0.18.0",
note = "The `api::call` module is deprecated. Individual items within this module have their own deprecation notices with specific migration guidance."
)]
pub mod call;
pub mod management_canister;
#[doc(hidden)]
Expand Down
10 changes: 9 additions & 1 deletion ic-cdk/src/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ pub fn reply_raw(buf: &[u8]) {

#[deprecated(
since = "0.18.0",
note = "Please use `ic_cdk::call::DecoderConfig` instead."
note = "Please use `candid::de::DecoderConfig` instead."
)]
#[derive(Debug)]
/// Config to control the behavior of decoding canister endpoint arguments.
Expand Down Expand Up @@ -927,6 +927,10 @@ pub fn performance_counter(counter_type: u32) -> u64 {
///
/// Usable, but not required, as metadata when using `#[query(manual_reply = true)]`,
/// so an accurate Candid file can still be generated.
#[deprecated(
since = "0.18.0",
note = "Please use `std::marker::PhantomData` with manual_reply instead."
)]
#[derive(Debug, Copy, Clone, Default)]
pub struct ManualReply<T: ?Sized>(PhantomData<T>);

Expand Down Expand Up @@ -991,6 +995,10 @@ where
/// provides a convenient wrapper for this. In a destructor, `is_recovering_from_trap` serves the same purpose as
/// [std::thread::panicking] - it tells you whether the destructor is executing *because* of a trap,
/// as opposed to just because the scope was exited, so you could e.g. implement mutex poisoning.
#[deprecated(
since = "0.18.0",
note = "Please use `ic_cdk::is_recovering_from_trap` instead."
)]
pub fn is_recovering_from_trap() -> bool {
crate::futures::CLEANUP.load(Ordering::Relaxed)
}
Loading

0 comments on commit 710fc59

Please sign in to comment.