pub mod call;
pub mod ecdsa;
pub mod http;
pub mod ledger;
pub mod mgmt;
pub mod network;
pub mod nns;
pub mod xrc;
use crate::{
InternalError,
cdk::{self, types::Principal},
infra,
ops::OpsError,
};
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum IcOpsError {
#[error(transparent)]
Infra(#[from] infra::InfraError),
#[error(transparent)]
CallOps(#[from] call::CallError),
#[error(transparent)]
EcdsaOps(#[from] ecdsa::EcdsaOpsError),
#[error(transparent)]
HttpOps(#[from] http::HttpOpsError),
#[error(transparent)]
LedgerOps(#[from] ledger::LedgerOpsError),
#[error(transparent)]
XrcOps(#[from] xrc::XrcOpsError),
}
impl From<IcOpsError> for InternalError {
fn from(err: IcOpsError) -> Self {
OpsError::from(err).into()
}
}
pub struct IcOps;
impl IcOps {
#[must_use]
pub fn canister_self() -> Principal {
cdk::api::canister_self()
}
#[must_use]
pub fn msg_caller() -> Principal {
cdk::api::msg_caller()
}
#[must_use]
#[allow(
clippy::missing_const_for_fn,
reason = "wasm path delegates to ic0-backed caller lookup, which is not const"
)]
pub(crate) fn metadata_entropy_caller() -> Principal {
#[cfg(target_arch = "wasm32")]
{
Self::msg_caller()
}
#[cfg(not(target_arch = "wasm32"))]
{
Principal::anonymous()
}
}
#[must_use]
#[allow(
clippy::missing_const_for_fn,
reason = "wasm path delegates to ic0-backed canister lookup, which is not const"
)]
pub(crate) fn metadata_entropy_canister() -> Principal {
#[cfg(target_arch = "wasm32")]
{
Self::canister_self()
}
#[cfg(not(target_arch = "wasm32"))]
{
Principal::management_canister()
}
}
#[must_use]
pub fn now_secs() -> u64 {
cdk::utils::time::now_secs()
}
#[must_use]
pub fn now_millis() -> u64 {
cdk::utils::time::now_millis()
}
#[must_use]
pub fn now_micros() -> u64 {
cdk::utils::time::now_micros()
}
#[must_use]
pub fn now_nanos() -> u64 {
cdk::utils::time::now_nanos()
}
pub fn println(message: &str) {
cdk::println!("{message}");
}
pub fn spawn<F>(future: F)
where
F: Future<Output = ()> + 'static,
{
cdk::futures::spawn(future);
}
}