junobuild_shared/ic/api.rs
1use candid::Principal;
2use ic_cdk::api::{canister_self, debug_print, msg_caller};
3
4/// Returns the **principal** of the current module.
5///
6/// This is a shorthand for [`ic_cdk::api::canister_self`],
7/// kept for readability and to align with the concise naming convention
8/// used our helpers.
9///
10/// # Example
11/// ```ignore
12/// let current_module = core::ic::id();
13/// ```
14pub fn id() -> Principal {
15 canister_self()
16}
17
18/// Returns the **principal** of the caller that invoked the current module.
19///
20/// This is a shorthand for [`ic_cdk::api::msg_caller`],
21/// kept for readability and to align with the concise naming convention
22/// used our helpers.
23///
24/// # Example
25/// ```ignore
26/// let user = core::ic::caller();
27/// ```
28pub fn caller() -> Principal {
29 msg_caller()
30}
31
32/// Prints a debug message to the Juno runtime logs.
33///
34/// This is a shorthand for [`ic_cdk::api::debug_print`],
35/// kept for readability and to align with the concise naming convention
36/// used in our helpers.
37///
38/// In the Juno Console, these messages appear in the logs of the current module.
39///
40/// # Example
41/// ```ignore
42/// core::ic::print("Satellite started successfully");
43/// ```
44pub fn print<S: AsRef<str>>(s: S) {
45 debug_print(s)
46}