canic_core/dto/
canister.rs1use crate::dto::prelude::*;
2
3pub use crate::domain::canister::{CanisterStatusType, LogVisibility};
4
5#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
10pub struct CanisterInfo {
11 pub pid: Principal,
12 pub role: CanisterRole,
13 pub parent_pid: Option<Principal>,
14 pub module_hash: Option<Vec<u8>>,
15 pub created_at: u64,
16}
17
18#[derive(CandidType, Clone, Debug, Deserialize)]
23pub struct CanisterStatusResponse {
24 pub status: CanisterStatusType,
25 pub settings: CanisterSettings,
26 pub module_hash: Option<Vec<u8>>,
27 pub memory_size: Nat,
28 pub memory_metrics: MemoryMetrics,
29 pub cycles: Nat,
30 pub reserved_cycles: Nat,
31 pub idle_cycles_burned_per_day: Nat,
32 pub query_stats: QueryStats,
33}
34
35#[derive(CandidType, Clone, Debug, Deserialize)]
40pub struct CanisterSettings {
41 pub controllers: Vec<Principal>,
42 pub compute_allocation: Nat,
43 pub memory_allocation: Nat,
44 pub freezing_threshold: Nat,
45 pub reserved_cycles_limit: Nat,
46 pub log_visibility: LogVisibility,
47 pub log_memory_limit: Nat,
48 pub wasm_memory_limit: Nat,
49 pub wasm_memory_threshold: Nat,
50 pub environment_variables: Vec<EnvironmentVariable>,
51}
52
53#[derive(CandidType, Clone, Debug, Deserialize)]
58pub struct EnvironmentVariable {
59 pub name: String,
60 pub value: String,
61}
62
63#[derive(CandidType, Clone, Debug, Deserialize)]
68pub struct MemoryMetrics {
69 pub wasm_memory_size: Nat,
70 pub stable_memory_size: Nat,
71 pub global_memory_size: Nat,
72 pub wasm_binary_size: Nat,
73 pub custom_sections_size: Nat,
74 pub canister_history_size: Nat,
75 pub wasm_chunk_store_size: Nat,
76 pub snapshots_size: Nat,
77}
78
79#[derive(CandidType, Clone, Debug, Deserialize)]
84pub struct QueryStats {
85 pub num_calls_total: Nat,
86 pub num_instructions_total: Nat,
87 pub request_payload_bytes_total: Nat,
88 pub response_payload_bytes_total: Nat,
89}
90
91#[cfg(test)]
92mod tests {
93 use super::*;
94 use candid::{Decode, Encode};
95 use serde::de::DeserializeOwned;
96 use std::fmt::Debug;
97
98 #[test]
99 fn canister_status_enums_roundtrip_candid_through_dto_path() {
100 assert_enum_candid_contract(CanisterStatusType::Stopping);
101 assert_enum_candid_contract(LogVisibility::AllowedViewers(vec![Principal::anonymous()]));
102 }
103
104 fn assert_enum_candid_contract<T>(value: T)
105 where
106 T: CandidType + Clone + Debug + DeserializeOwned + Eq,
107 {
108 let bytes = Encode!(&value).expect("encode canister enum");
109 let decoded = Decode!(&bytes, T).expect("decode canister enum");
110
111 assert_eq!(decoded, value);
112 }
113}