#[cfg(feature = "host")]
mod cache;
mod model;
#[cfg(feature = "host")]
mod source;
mod text;
#[cfg(feature = "host")]
use crate::{HostCacheError, nns::NnsGovernanceQueryError, runtime::RuntimeError};
#[cfg(feature = "host")]
use std::path::PathBuf;
#[cfg(feature = "host")]
use thiserror::Error as ThisError;
#[cfg(feature = "host")]
pub use cache::{
DEFAULT_NNS_NEURON_REFRESH_LOCK_STALE_SECONDS, NnsNeuronCacheStatusReport,
NnsNeuronCacheSummary, NnsNeuronRefreshReport, build_nns_neuron_cache_status_report,
build_nns_neuron_info_report_from_cache, build_nns_neuron_list_report_from_cache,
nns_neuron_cache_path, nns_neuron_refresh_attempt_path, nns_neuron_refresh_lock_path,
refresh_nns_neuron_cache, refresh_nns_neuron_cache_with_progress,
refresh_nns_neuron_cache_with_source,
};
pub use model::{
NnsKnownNeuronData, NnsNeuronBallotRow, NnsNeuronInfoReport, NnsNeuronInfoRequest,
NnsNeuronListReport, NnsNeuronListRequest, NnsNeuronRow,
};
#[cfg(feature = "host")]
pub use source::{
NnsNeuronPage, NnsNeuronSource, build_nns_neuron_info_report,
build_nns_neuron_info_report_with_source, build_nns_neuron_list_report,
build_nns_neuron_list_report_with_source,
};
#[cfg(feature = "host")]
pub use text::{nns_neuron_cache_status_report_text, nns_neuron_refresh_report_text};
pub use text::{nns_neuron_info_report_text, nns_neuron_list_report_text};
#[cfg(all(test, feature = "host"))]
mod tests;
pub const DEFAULT_NNS_NEURON_SOURCE_ENDPOINT: &str = "https://icp-api.io";
pub const NNS_NEURON_MAX_PAGE_SIZE: u32 = 300;
#[cfg(feature = "host")]
const NNS_NEURON_CACHE_SCHEMA_VERSION: u32 = 1;
#[cfg(feature = "host")]
const NNS_NEURON_INFO_REPORT_SCHEMA_VERSION: u32 = 1;
#[cfg(feature = "host")]
const NNS_NEURON_LIST_REPORT_SCHEMA_VERSION: u32 = 1;
#[cfg(feature = "host")]
const NNS_NEURON_REFRESH_REPORT_SCHEMA_VERSION: u32 = 1;
#[cfg(feature = "host")]
const NNS_NEURON_CACHE_STATUS_REPORT_SCHEMA_VERSION: u32 = 1;
#[cfg(feature = "host")]
const NNS_NEURON_FETCHED_BY: &str = "ic-query";
#[cfg(feature = "host")]
#[derive(Debug, ThisError)]
pub enum NnsNeuronHostError {
#[error(
"`icq nns neuron` supports only the mainnet `ic` network\n\nThe public neuron index is queried from the Internet Computer mainnet Governance canister.\n\nTry:\n icq --network ic nns neuron list"
)]
UnsupportedNetwork {
network: String,
},
#[error("invalid NNS neuron page size {page_size}; expected 1..={max_page_size}")]
InvalidPageSize {
page_size: u32,
max_page_size: u32,
},
#[error(transparent)]
GovernanceQuery(#[from] NnsGovernanceQueryError),
#[error("NNS Governance rejected the neuron query with code {error_type}: {message}")]
Governance {
error_type: i32,
message: String,
},
#[error("NNS neuron {neuron_id} was not found")]
NeuronNotFound {
neuron_id: u64,
},
#[error("NNS Governance returned a neuron row without an id")]
MissingNeuronId,
#[error("invalid NNS neuron page: {reason}")]
InvalidPage {
reason: String,
},
#[error(
"NNS neuron refresh stopped after {pages_fetched} pages and {rows_fetched} rows: {reason}"
)]
IncompleteRefresh {
pages_fetched: u32,
rows_fetched: usize,
reason: String,
},
#[error("invalid NNS neuron cache at {}: {reason}", path.display())]
InvalidCache {
path: PathBuf,
reason: String,
},
#[error(transparent)]
Cache(#[from] HostCacheError),
#[error(transparent)]
Runtime(#[from] RuntimeError),
}
#[cfg(feature = "host")]
fn enforce_mainnet_network(network: &str) -> Result<(), NnsNeuronHostError> {
crate::network::enforce_mainnet_network_with(network, |network| {
NnsNeuronHostError::UnsupportedNetwork { network }
})
}