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