canic_core/dto/
canister.rs

1use crate::dto::prelude::*;
2
3///
4/// CanisterInfo
5///
6
7#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
8pub struct CanisterInfo {
9    pub pid: Principal,
10    pub role: CanisterRole,
11    pub parent_pid: Option<Principal>,
12    pub module_hash: Option<Vec<u8>>,
13    pub created_at: u64,
14}
15
16///
17/// CanisterStatusResponse
18///
19
20#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
21pub struct CanisterStatusResponse {
22    pub status: CanisterStatusType,
23    pub settings: CanisterSettings,
24    pub module_hash: Option<Vec<u8>>,
25    pub memory_size: Nat,
26    pub memory_metrics: MemoryMetrics,
27    pub cycles: Nat,
28    pub reserved_cycles: Nat,
29    pub idle_cycles_burned_per_day: Nat,
30    pub query_stats: QueryStats,
31}
32
33///
34/// CanisterStatusType
35///
36
37#[derive(CandidType, Clone, Copy, Debug, Deserialize, Serialize)]
38pub enum CanisterStatusType {
39    #[serde(rename = "running")]
40    Running,
41    #[serde(rename = "stopping")]
42    Stopping,
43    #[serde(rename = "stopped")]
44    Stopped,
45}
46
47///
48/// CanisterSettings
49///
50
51#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
52pub struct CanisterSettings {
53    pub controllers: Vec<Principal>,
54    pub compute_allocation: Nat,
55    pub memory_allocation: Nat,
56    pub freezing_threshold: Nat,
57    pub reserved_cycles_limit: Nat,
58    pub log_visibility: LogVisibility,
59    pub wasm_memory_limit: Nat,
60    pub wasm_memory_threshold: Nat,
61    pub environment_variables: Vec<EnvironmentVariable>,
62}
63
64///
65/// LogVisibility
66///
67
68#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
69pub enum LogVisibility {
70    #[serde(rename = "controllers")]
71    Controllers,
72    #[serde(rename = "public")]
73    Public,
74    #[serde(rename = "allowed_viewers")]
75    AllowedViewers(Vec<Principal>),
76}
77
78///
79/// EnvironmentVariable
80///
81
82#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
83pub struct EnvironmentVariable {
84    pub name: String,
85    pub value: String,
86}
87
88///
89/// MemoryMetrics
90///
91
92#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
93pub struct MemoryMetrics {
94    pub wasm_memory_size: Nat,
95    pub stable_memory_size: Nat,
96    pub global_memory_size: Nat,
97    pub wasm_binary_size: Nat,
98    pub custom_sections_size: Nat,
99    pub canister_history_size: Nat,
100    pub wasm_chunk_store_size: Nat,
101    pub snapshots_size: Nat,
102}
103
104///
105/// QueryStats
106///
107
108#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
109pub struct QueryStats {
110    pub num_calls_total: Nat,
111    pub num_instructions_total: Nat,
112    pub request_payload_bytes_total: Nat,
113    pub response_payload_bytes_total: Nat,
114}