Skip to main content

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 log_memory_limit: Nat,
60    pub wasm_memory_limit: Nat,
61    pub wasm_memory_threshold: Nat,
62    pub environment_variables: Vec<EnvironmentVariable>,
63}
64
65///
66/// LogVisibility
67///
68
69#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
70pub enum LogVisibility {
71    #[serde(rename = "controllers")]
72    Controllers,
73    #[serde(rename = "public")]
74    Public,
75    #[serde(rename = "allowed_viewers")]
76    AllowedViewers(Vec<Principal>),
77}
78
79///
80/// EnvironmentVariable
81///
82
83#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
84pub struct EnvironmentVariable {
85    pub name: String,
86    pub value: String,
87}
88
89///
90/// MemoryMetrics
91///
92
93#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
94pub struct MemoryMetrics {
95    pub wasm_memory_size: Nat,
96    pub stable_memory_size: Nat,
97    pub global_memory_size: Nat,
98    pub wasm_binary_size: Nat,
99    pub custom_sections_size: Nat,
100    pub canister_history_size: Nat,
101    pub wasm_chunk_store_size: Nat,
102    pub snapshots_size: Nat,
103}
104
105///
106/// QueryStats
107///
108
109#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
110pub struct QueryStats {
111    pub num_calls_total: Nat,
112    pub num_instructions_total: Nat,
113    pub request_payload_bytes_total: Nat,
114    pub response_payload_bytes_total: Nat,
115}