canic_core/ops/ic/
call.rs

1use crate::{
2    cdk::{call::Call as IcCall, candid::Principal},
3    model::metrics::{
4        icc::IccMetrics,
5        system::{SystemMetricKind, SystemMetrics},
6    },
7};
8
9///
10/// Call
11/// Wrapper around `ic_cdk::api::call::Call` that records metrics.
12///
13
14pub struct Call;
15
16impl Call {
17    #[must_use]
18    pub fn bounded_wait(canister_id: impl Into<Principal>, method: &str) -> IcCall<'_, '_> {
19        let canister_id: Principal = canister_id.into();
20
21        SystemMetrics::increment(SystemMetricKind::CanisterCall);
22        IccMetrics::increment(canister_id, method);
23
24        IcCall::bounded_wait(canister_id, method)
25    }
26
27    /// Create a call builder that will be awaited without cycle limits.
28    #[must_use]
29    pub fn unbounded_wait(canister_id: impl Into<Principal>, method: &str) -> IcCall<'_, '_> {
30        let canister_id: Principal = canister_id.into();
31
32        SystemMetrics::increment(SystemMetricKind::CanisterCall);
33        IccMetrics::increment(canister_id, method);
34
35        IcCall::unbounded_wait(canister_id, method)
36    }
37}