canic_core/ops/ic/
call.rs

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