1pub mod bootstrap;
11pub mod command;
12pub mod config;
13pub mod ic;
14pub mod orchestration;
15pub mod perf;
16pub mod placement;
17pub mod reserve;
18pub mod rpc;
19pub mod runtime;
20pub mod service;
21pub mod storage;
22pub mod wasm;
23
24use std::time::Duration;
25
26pub const OPS_INIT_DELAY: Duration = Duration::from_secs(10);
32
33pub const OPS_CYCLE_TRACK_INTERVAL: Duration = Duration::from_secs(60 * 10);
35
36pub const OPS_LOG_RETENTION_INTERVAL: Duration = Duration::from_secs(60 * 10);
38
39pub const OPS_RESERVE_INIT_DELAY: Duration = Duration::from_secs(30);
41
42pub const OPS_RESERVE_CHECK_INTERVAL: Duration = Duration::from_secs(30 * 60);
44
45pub mod prelude {
51 pub use crate::{
52 cdk::{
53 api::{canister_self, msg_caller},
54 candid::CandidType,
55 types::{Account, Int, Nat, Principal, Subaccount},
56 },
57 ids::CanisterRole,
58 log,
59 log::Level,
60 ops::{
61 OpsError,
62 ic::{call::Call, call_and_decode},
63 },
64 types::Cycles,
65 };
66 pub use serde::{Deserialize, Serialize};
67}
68
69use crate::{ThisError, ops::storage::env::EnvOps};
70
71#[derive(Debug, ThisError)]
77pub enum OpsError {
78 #[error("operation must be called from the root canister")]
80 NotRoot,
81
82 #[error("operation cannot be called from the root canister")]
84 IsRoot,
85
86 #[error(transparent)]
87 ConfigOpsError(#[from] config::ConfigOpsError),
88
89 #[error(transparent)]
90 IcOpsError(#[from] ic::IcOpsError),
91
92 #[error(transparent)]
93 OrchestrationOpsError(#[from] orchestration::OrchestrationOpsError),
94
95 #[error(transparent)]
96 ReserveOpsError(#[from] reserve::ReserveOpsError),
97
98 #[error(transparent)]
99 RpcOpsError(#[from] rpc::RpcOpsError),
100
101 #[error(transparent)]
102 StorageOpsError(#[from] storage::StorageOpsError),
103}
104
105impl OpsError {
106 pub fn require_root() -> Result<(), Self> {
108 if EnvOps::is_root() {
109 Ok(())
110 } else {
111 Err(Self::NotRoot)
112 }
113 }
114
115 pub fn deny_root() -> Result<(), Self> {
117 if EnvOps::is_root() {
118 Err(Self::IsRoot)
119 } else {
120 Ok(())
121 }
122 }
123}