use candid::Principal;
#[cfg(target_arch = "wasm32")]
use ic_cdk::api::{
canister_self, debug_print, is_controller as ic_is_controller, msg_caller, time as ic_time,
};
#[cfg(target_arch = "wasm32")]
pub fn id() -> Principal {
canister_self()
}
#[cfg(not(target_arch = "wasm32"))]
pub fn id() -> Principal {
Principal::from_text("ck4tp-3iaaa-aaaal-ab7da-cai").unwrap()
}
#[cfg(target_arch = "wasm32")]
pub fn caller() -> Principal {
msg_caller()
}
#[cfg(not(target_arch = "wasm32"))]
pub fn caller() -> Principal {
Principal::from_text("bphsl-fvy2d-emlkg-wuhfe-fylew-25w4a-vpdm3-ajsos-ao4x5-sxn5j-jqe").unwrap()
}
#[cfg(target_arch = "wasm32")]
pub fn print<S: AsRef<str>>(s: S) {
debug_print(s)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn print<S: AsRef<str>>(_s: S) {
}
#[cfg(target_arch = "wasm32")]
pub fn time() -> u64 {
ic_time()
}
#[cfg(not(target_arch = "wasm32"))]
pub fn time() -> u64 {
use std::time::{SystemTime, UNIX_EPOCH};
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_nanos() as u64
}
#[cfg(target_arch = "wasm32")]
pub fn is_canister_controller(principal: &Principal) -> bool {
ic_is_controller(principal)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn is_canister_controller(principal: &Principal) -> bool {
*principal == Principal::from_text("ck4tp-3iaaa-aaaal-ab7da-cai").unwrap()
}