Skip to main content

ic_query/nns/node/report/model/
request.rs

1use std::path::PathBuf;
2
3///
4/// NnsNodeCacheRequest
5///
6/// Cache identity used by NNS node report reads.
7///
8
9#[derive(Clone, Debug, Eq, PartialEq)]
10pub struct NnsNodeCacheRequest {
11    pub icp_root: PathBuf,
12    pub network: String,
13}
14
15impl NnsNodeCacheRequest {
16    #[must_use]
17    pub fn new(icp_root: impl Into<PathBuf>, network: impl Into<String>) -> Self {
18        Self {
19            icp_root: icp_root.into(),
20            network: network.into(),
21        }
22    }
23}
24
25///
26/// NnsNodeListRequest
27///
28/// Request for an optionally filtered NNS node inventory report.
29///
30
31#[derive(Clone, Debug, Eq, PartialEq)]
32pub struct NnsNodeListRequest {
33    pub cache: NnsNodeCacheRequest,
34    pub source_endpoint: String,
35    pub now_unix_secs: u64,
36    pub filters: NnsNodeListFilters,
37}
38
39impl NnsNodeListRequest {
40    #[must_use]
41    pub fn new(
42        cache: NnsNodeCacheRequest,
43        source_endpoint: impl Into<String>,
44        now_unix_secs: u64,
45    ) -> Self {
46        Self {
47            cache,
48            source_endpoint: source_endpoint.into(),
49            now_unix_secs,
50            filters: NnsNodeListFilters::default(),
51        }
52    }
53
54    #[must_use]
55    pub fn with_filters(mut self, filters: NnsNodeListFilters) -> Self {
56        self.filters = filters;
57        self
58    }
59
60    #[must_use]
61    pub fn with_subnet(mut self, subnet: impl Into<String>) -> Self {
62        self.filters.subnet = Some(subnet.into());
63        self
64    }
65
66    #[must_use]
67    pub fn with_subnet_kind(mut self, subnet_kind: impl Into<String>) -> Self {
68        self.filters.subnet_kind = Some(subnet_kind.into());
69        self
70    }
71
72    #[must_use]
73    pub fn with_data_center(mut self, data_center: impl Into<String>) -> Self {
74        self.filters.data_center = Some(data_center.into());
75        self
76    }
77
78    #[must_use]
79    pub fn with_node_provider(mut self, node_provider: impl Into<String>) -> Self {
80        self.filters.node_provider = Some(node_provider.into());
81        self
82    }
83
84    #[must_use]
85    pub fn with_node_operator(mut self, node_operator: impl Into<String>) -> Self {
86        self.filters.node_operator = Some(node_operator.into());
87        self
88    }
89}
90
91///
92/// NnsNodeInfoRequest
93///
94/// Request for one NNS node selected by principal or prefix.
95///
96
97#[derive(Clone, Debug, Eq, PartialEq)]
98pub struct NnsNodeInfoRequest {
99    pub cache: NnsNodeCacheRequest,
100    pub source_endpoint: String,
101    pub input: String,
102    pub now_unix_secs: u64,
103}
104
105impl NnsNodeInfoRequest {
106    #[must_use]
107    pub fn new(
108        cache: NnsNodeCacheRequest,
109        source_endpoint: impl Into<String>,
110        input: impl Into<String>,
111        now_unix_secs: u64,
112    ) -> Self {
113        Self {
114            cache,
115            source_endpoint: source_endpoint.into(),
116            input: input.into(),
117            now_unix_secs,
118        }
119    }
120}
121
122///
123/// NnsNodeRefreshRequest
124///
125/// Host request for refreshing the cached NNS node inventory.
126///
127
128#[cfg(feature = "host")]
129#[derive(Clone, Debug, Eq, PartialEq)]
130pub struct NnsNodeRefreshRequest {
131    pub cache: NnsNodeCacheRequest,
132    pub source_endpoint: String,
133    pub now_unix_secs: u64,
134    pub lock_stale_after_seconds: u64,
135    pub dry_run: bool,
136    pub output_path: Option<PathBuf>,
137}
138
139#[cfg(feature = "host")]
140impl NnsNodeRefreshRequest {
141    #[must_use]
142    pub fn new(
143        cache: NnsNodeCacheRequest,
144        source_endpoint: impl Into<String>,
145        now_unix_secs: u64,
146        lock_stale_after_seconds: u64,
147    ) -> Self {
148        Self {
149            cache,
150            source_endpoint: source_endpoint.into(),
151            now_unix_secs,
152            lock_stale_after_seconds,
153            dry_run: false,
154            output_path: None,
155        }
156    }
157
158    #[must_use]
159    pub const fn with_dry_run(mut self, dry_run: bool) -> Self {
160        self.dry_run = dry_run;
161        self
162    }
163
164    #[must_use]
165    pub fn with_output_path(mut self, output_path: impl Into<PathBuf>) -> Self {
166        self.output_path = Some(output_path.into());
167        self
168    }
169}
170
171#[cfg(feature = "host")]
172impl_nns_leaf_cache_and_refresh_requests!(NnsNodeCacheRequest, NnsNodeRefreshRequest);
173
174///
175/// NnsNodeListFilters
176///
177/// Relation filters applied to an NNS node inventory view.
178///
179
180#[derive(Clone, Debug, Default, Eq, PartialEq)]
181pub struct NnsNodeListFilters {
182    pub subnet: Option<String>,
183    pub subnet_kind: Option<String>,
184    pub data_center: Option<String>,
185    pub node_provider: Option<String>,
186    pub node_operator: Option<String>,
187}
188
189impl NnsNodeListFilters {
190    #[must_use]
191    pub const fn is_empty(&self) -> bool {
192        self.subnet.is_none()
193            && self.subnet_kind.is_none()
194            && self.data_center.is_none()
195            && self.node_provider.is_none()
196            && self.node_operator.is_none()
197    }
198}