Skip to main content

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

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