Skip to main content

canic_host/icp/
model.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5pub(super) const LOCAL_ICP_TARGET: &str = "local";
6pub(super) const REQUIRED_ICP_CLI_VERSION: &str = "1.2.0";
7pub(super) const ICP_CLI_SUPPORTED_VERSION_RANGE: &str = ">=1.2.0, <2.0.0";
8
9/// Direct local replica endpoint used when ICP project state is unavailable.
10///
11#[derive(Clone, Debug, Eq, PartialEq)]
12pub struct LocalReplicaTarget {
13    pub url: String,
14    pub root_key: String,
15}
16
17///
18/// IcpRawOutput
19///
20
21#[derive(Clone, Debug, Eq, PartialEq)]
22pub struct IcpRawOutput {
23    pub success: bool,
24    pub status: String,
25    pub stdout: Vec<u8>,
26    pub stderr: Vec<u8>,
27}
28
29///
30/// IcpCli
31///
32
33#[derive(Clone, Debug)]
34pub struct IcpCli {
35    pub(super) remote_calls: std::sync::Arc<std::sync::atomic::AtomicU64>,
36    pub(super) executable: String,
37    pub(super) environment: Option<String>,
38    pub(super) cwd: Option<PathBuf>,
39    pub(super) local_replica: Option<LocalReplicaTarget>,
40    pub(super) inherited_fd: Option<i32>,
41    pub(super) identity_password_file: Option<PathBuf>,
42}
43
44///
45/// IcpCliVersion
46///
47#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
48pub(super) struct IcpCliVersion {
49    pub(super) major: u64,
50    pub(super) minor: u64,
51    pub(super) patch: u64,
52}
53
54///
55/// IcpSnapshot
56///
57
58#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
59pub struct IcpSnapshot {
60    pub snapshot_id: String,
61    pub taken_at_timestamp: Option<u64>,
62    pub total_size_bytes: Option<u64>,
63}
64
65///
66/// IcpCanisterStatusReport
67///
68
69#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
70pub struct IcpCanisterStatusReport {
71    #[serde(default, rename = "version", alias = "canister_version")]
72    pub canister_version: Option<u64>,
73    #[serde(default, rename = "controllers")]
74    pub public_controllers: Option<Vec<String>>,
75    pub id: String,
76    pub name: Option<String>,
77    pub status: Option<String>,
78    pub settings: Option<IcpCanisterStatusSettings>,
79    pub module_hash: Option<String>,
80    pub memory_size: Option<String>,
81    pub cycles: Option<String>,
82    pub reserved_cycles: Option<String>,
83    pub idle_cycles_burned_per_day: Option<String>,
84}
85
86///
87/// IcpCanisterStatusSettings
88///
89
90#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
91pub struct IcpCanisterStatusSettings {
92    #[serde(default)]
93    pub controllers: Vec<String>,
94    pub compute_allocation: Option<String>,
95    pub memory_allocation: Option<String>,
96    pub freezing_threshold: Option<String>,
97    pub reserved_cycles_limit: Option<String>,
98    pub wasm_memory_limit: Option<String>,
99    pub wasm_memory_threshold: Option<String>,
100    pub log_memory_limit: Option<String>,
101}
102
103/// Transport context identity excludes informational counters.
104#[derive(Eq, PartialEq)]
105struct IcpCommandIdentity<'a> {
106    executable: &'a str,
107    environment: Option<&'a str>,
108    cwd: Option<&'a std::path::Path>,
109    local_replica: Option<&'a LocalReplicaTarget>,
110    inherited_fd: Option<i32>,
111    identity_password_file: Option<&'a std::path::Path>,
112}
113
114impl IcpCli {
115    fn command_identity(&self) -> IcpCommandIdentity<'_> {
116        IcpCommandIdentity {
117            executable: &self.executable,
118            environment: self.environment.as_deref(),
119            cwd: self.cwd.as_deref(),
120            local_replica: self.local_replica.as_ref(),
121            inherited_fd: self.inherited_fd,
122            identity_password_file: self.identity_password_file.as_deref(),
123        }
124    }
125}
126
127impl PartialEq for IcpCli {
128    fn eq(&self, other: &Self) -> bool {
129        self.command_identity() == other.command_identity()
130    }
131}
132impl Eq for IcpCli {}