use super::{NnsInventoryError, NnsInventoryRefreshRequest, source::NnsNodeProviderSource};
use crate::nns::{
LiveNnsSource, NnsInventoryRefreshReport,
inventory::{
collect_registry_inventory, nns_registry_inventory_cache_path,
nns_registry_inventory_refresh_lock_path,
},
};
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
pub struct NnsNodeProviderRefreshReport {
pub inventory: NnsInventoryRefreshReport,
pub metadata: NnsInventoryRefreshReport,
}
pub async fn refresh_nns_node_provider_report(
request: &NnsInventoryRefreshRequest,
) -> Result<NnsNodeProviderRefreshReport, NnsInventoryError> {
refresh_nns_node_provider_report_with_source(request, &LiveNnsSource::default()).await
}
pub async fn refresh_nns_node_provider_report_with_source(
request: &NnsInventoryRefreshRequest,
source: &dyn NnsNodeProviderSource,
) -> Result<NnsNodeProviderRefreshReport, NnsInventoryError> {
super::enforce_mainnet_network(&request.cache.network)?;
if let Some(output) = &request.output_path {
let paths = [
nns_registry_inventory_cache_path(&request.cache.cache_root, &request.cache.network),
nns_registry_inventory_refresh_lock_path(
&request.cache.cache_root,
&request.cache.network,
),
super::cache::nns_node_provider_cache_path(
&request.cache.cache_root,
&request.cache.network,
),
super::cache::nns_node_provider_refresh_lock_path(
&request.cache.cache_root,
&request.cache.network,
),
];
let protected = paths
.iter()
.map(std::path::PathBuf::as_path)
.collect::<Vec<_>>();
crate::cache_file::validate_output_path(output, &protected).map_err(|source| {
NnsInventoryError::Cache {
collection: super::COLLECTION,
source: crate::HostCacheError::operation("node-provider", source),
}
})?;
}
let mut inventory_request = request.clone();
inventory_request.output_path = None;
let (snapshot, inventory) = collect_registry_inventory(&inventory_request, source).await?;
let (_, metadata) = super::cache::collect_metadata(request, source, &snapshot).await?;
Ok(NnsNodeProviderRefreshReport {
inventory,
metadata,
})
}