use crate::subnet_catalog::format_utc_timestamp_secs;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(tag = "source_transport", rename_all = "snake_case")]
pub enum NnsGovernanceSourceSelection {
ReplicaQuery {
endpoint: String,
fetched_by: String,
},
ReplicatedInterCanisterCall,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NnsGovernanceRequest {
pub network: String,
pub fetched_at: String,
pub source: NnsGovernanceSourceSelection,
}
impl NnsGovernanceRequest {
#[must_use]
pub fn replica_query(
network: impl Into<String>,
endpoint: impl Into<String>,
fetched_at: impl Into<String>,
fetched_by: impl Into<String>,
) -> Self {
Self {
network: network.into(),
fetched_at: fetched_at.into(),
source: NnsGovernanceSourceSelection::ReplicaQuery {
endpoint: endpoint.into(),
fetched_by: fetched_by.into(),
},
}
}
#[must_use]
pub fn replica_query_from_unix_secs(
network: impl Into<String>,
endpoint: impl Into<String>,
fetched_at_unix_secs: u64,
fetched_by: impl Into<String>,
) -> Self {
Self::replica_query(
network,
endpoint,
format_utc_timestamp_secs(fetched_at_unix_secs),
fetched_by,
)
}
#[must_use]
pub fn replicated_inter_canister_call(
network: impl Into<String>,
fetched_at: impl Into<String>,
) -> Self {
Self {
network: network.into(),
fetched_at: fetched_at.into(),
source: NnsGovernanceSourceSelection::ReplicatedInterCanisterCall,
}
}
#[must_use]
pub fn replicated_inter_canister_call_from_unix_secs(
network: impl Into<String>,
fetched_at_unix_secs: u64,
) -> Self {
Self::replicated_inter_canister_call(
network,
format_utc_timestamp_secs(fetched_at_unix_secs),
)
}
}