Skip to main content

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

1use std::path::PathBuf;
2
3///
4/// NnsNodeOperatorCacheRequest
5///
6/// Cache identity used by NNS node operator report reads.
7///
8
9#[derive(Clone, Debug, Eq, PartialEq)]
10pub struct NnsNodeOperatorCacheRequest {
11    pub icp_root: PathBuf,
12    pub network: String,
13}
14
15impl NnsNodeOperatorCacheRequest {
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/// NnsNodeOperatorListRequest
27///
28/// Request for the complete NNS node operator inventory report.
29///
30
31#[derive(Clone, Debug, Eq, PartialEq)]
32pub struct NnsNodeOperatorListRequest {
33    pub cache: NnsNodeOperatorCacheRequest,
34    pub source_endpoint: String,
35    pub now_unix_secs: u64,
36}
37
38impl NnsNodeOperatorListRequest {
39    #[must_use]
40    pub fn new(
41        cache: NnsNodeOperatorCacheRequest,
42        source_endpoint: impl Into<String>,
43        now_unix_secs: u64,
44    ) -> Self {
45        Self {
46            cache,
47            source_endpoint: source_endpoint.into(),
48            now_unix_secs,
49        }
50    }
51}
52
53///
54/// NnsNodeOperatorInfoRequest
55///
56/// Request for one NNS node operator selected by principal or prefix.
57///
58
59#[derive(Clone, Debug, Eq, PartialEq)]
60pub struct NnsNodeOperatorInfoRequest {
61    pub cache: NnsNodeOperatorCacheRequest,
62    pub source_endpoint: String,
63    pub input: String,
64    pub now_unix_secs: u64,
65}
66
67impl NnsNodeOperatorInfoRequest {
68    #[must_use]
69    pub fn new(
70        cache: NnsNodeOperatorCacheRequest,
71        source_endpoint: impl Into<String>,
72        input: impl Into<String>,
73        now_unix_secs: u64,
74    ) -> Self {
75        Self {
76            cache,
77            source_endpoint: source_endpoint.into(),
78            input: input.into(),
79            now_unix_secs,
80        }
81    }
82}
83
84///
85/// NnsNodeOperatorRefreshRequest
86///
87/// Host request for refreshing the cached NNS node operator inventory.
88///
89
90#[cfg(feature = "host")]
91#[derive(Clone, Debug, Eq, PartialEq)]
92pub struct NnsNodeOperatorRefreshRequest {
93    pub cache: NnsNodeOperatorCacheRequest,
94    pub source_endpoint: String,
95    pub now_unix_secs: u64,
96    pub lock_stale_after_seconds: u64,
97    pub dry_run: bool,
98    pub output_path: Option<PathBuf>,
99}
100
101#[cfg(feature = "host")]
102impl NnsNodeOperatorRefreshRequest {
103    #[must_use]
104    pub fn new(
105        cache: NnsNodeOperatorCacheRequest,
106        source_endpoint: impl Into<String>,
107        now_unix_secs: u64,
108        lock_stale_after_seconds: u64,
109    ) -> Self {
110        Self {
111            cache,
112            source_endpoint: source_endpoint.into(),
113            now_unix_secs,
114            lock_stale_after_seconds,
115            dry_run: false,
116            output_path: None,
117        }
118    }
119
120    #[must_use]
121    pub const fn with_dry_run(mut self, dry_run: bool) -> Self {
122        self.dry_run = dry_run;
123        self
124    }
125
126    #[must_use]
127    pub fn with_output_path(mut self, output_path: impl Into<PathBuf>) -> Self {
128        self.output_path = Some(output_path.into());
129        self
130    }
131}
132
133#[cfg(feature = "host")]
134impl_nns_leaf_cache_and_refresh_requests!(
135    NnsNodeOperatorCacheRequest,
136    NnsNodeOperatorRefreshRequest
137);