ic_query/nns/governance/
request.rs1use crate::subnet_catalog::format_utc_timestamp_secs;
8use serde::{Deserialize, Serialize};
9
10#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
17#[serde(tag = "source_transport", rename_all = "snake_case")]
18pub enum NnsGovernanceSourceSelection {
19 ReplicaQuery {
21 endpoint: String,
23 fetched_by: String,
25 },
26 ReplicatedInterCanisterCall,
28}
29
30#[derive(Clone, Debug, Eq, PartialEq)]
37pub struct NnsGovernanceRequest {
38 pub network: String,
40 pub fetched_at: String,
42 pub source: NnsGovernanceSourceSelection,
44}
45
46impl NnsGovernanceRequest {
47 #[must_use]
49 pub fn replica_query(
50 network: impl Into<String>,
51 endpoint: impl Into<String>,
52 fetched_at: impl Into<String>,
53 fetched_by: impl Into<String>,
54 ) -> Self {
55 Self {
56 network: network.into(),
57 fetched_at: fetched_at.into(),
58 source: NnsGovernanceSourceSelection::ReplicaQuery {
59 endpoint: endpoint.into(),
60 fetched_by: fetched_by.into(),
61 },
62 }
63 }
64
65 #[must_use]
67 pub fn replica_query_from_unix_secs(
68 network: impl Into<String>,
69 endpoint: impl Into<String>,
70 fetched_at_unix_secs: u64,
71 fetched_by: impl Into<String>,
72 ) -> Self {
73 Self::replica_query(
74 network,
75 endpoint,
76 format_utc_timestamp_secs(fetched_at_unix_secs),
77 fetched_by,
78 )
79 }
80
81 #[must_use]
83 pub fn replicated_inter_canister_call(
84 network: impl Into<String>,
85 fetched_at: impl Into<String>,
86 ) -> Self {
87 Self {
88 network: network.into(),
89 fetched_at: fetched_at.into(),
90 source: NnsGovernanceSourceSelection::ReplicatedInterCanisterCall,
91 }
92 }
93
94 #[must_use]
96 pub fn replicated_inter_canister_call_from_unix_secs(
97 network: impl Into<String>,
98 fetched_at_unix_secs: u64,
99 ) -> Self {
100 Self::replicated_inter_canister_call(
101 network,
102 format_utc_timestamp_secs(fetched_at_unix_secs),
103 )
104 }
105}