use crate::cli::{
clap::{required_string, required_typed, typed_option},
common::{OutputFormat, SOURCE_ENDPOINT_ARG, output_format},
};
use clap::ArgMatches;
use ic_query::nns::NnsGovernanceRefreshRequest;
use ic_query::nns::governance::NnsGovernanceRequest;
use std::path::PathBuf;
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::nns) struct NnsCommonOptions {
pub(in crate::nns) network: String,
pub(in crate::nns) format: OutputFormat,
pub(in crate::nns) source_endpoint: String,
}
impl NnsCommonOptions {
pub(in crate::nns) fn into_governance_request(
self,
now_unix_secs: u64,
) -> (OutputFormat, NnsGovernanceRequest) {
(
self.format,
NnsGovernanceRequest::replica_query_from_unix_secs(
self.network,
self.source_endpoint,
now_unix_secs,
"ic-query",
),
)
}
pub(in crate::nns) fn from_matches(matches: &ArgMatches, network: &str) -> Self {
Self {
network: network.to_string(),
format: output_format(matches),
source_endpoint: required_string(matches, SOURCE_ENDPOINT_ARG),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::nns) struct NnsPagedRefreshOptions {
pub(in crate::nns) common: NnsCommonOptions,
pub(in crate::nns) page_size: u32,
pub(in crate::nns) max_pages: Option<u32>,
}
impl NnsPagedRefreshOptions {
pub(in crate::nns) fn from_matches(matches: &ArgMatches, network: &str) -> Self {
let common = NnsCommonOptions::from_matches(matches, network);
Self {
common,
page_size: required_typed(matches, "page-size"),
max_pages: typed_option(matches, "max-pages"),
}
}
pub(in crate::nns) fn into_request(
self,
cache_root: PathBuf,
now_unix_secs: u64,
) -> NnsGovernanceRefreshRequest {
NnsGovernanceRefreshRequest::new(
cache_root,
self.common.network,
self.common.source_endpoint,
now_unix_secs,
self.page_size,
)
.with_max_pages(self.max_pages)
}
}