ic-query 0.25.28

Internet Computer query library for NNS, SNS, ICRC, system canisters, and public network metadata
Documentation
//! Module: sns::report::neurons_cache::storage
//!
//! Responsibility: group neuron cache loading, lookup, and storage identity.
//! Does not own: refresh collection, attempt persistence, report rendering, or CLI parsing.
//! Boundary: centralizes cache-file storage reads for neuron cache reports.

use crate::sns::report::{
    SnsHostError,
    cache_storage::SnsCacheStorageFamily,
    neurons_cache::{
        SNS_NEURONS_CACHE_SCHEMA_VERSION,
        model::{SNS_NEURONS_CACHE_FIELDS, SnsNeuronsCacheRows},
        paths::SnsNeuronsCacheCollection,
    },
    source::validate_sns_neuron_rows,
};
use std::path::PathBuf;

mod lookup;

pub(super) use lookup::load_sns_neurons_cache_for_input;

impl SnsCacheStorageFamily for SnsNeuronsCacheCollection {
    type Data = SnsNeuronsCacheRows;

    const CACHE_SCHEMA_VERSION: u32 = SNS_NEURONS_CACHE_SCHEMA_VERSION;
    const CACHE_FIELDS: &'static [&'static str] = SNS_NEURONS_CACHE_FIELDS;
    const CACHE_ITEM_NAME: &'static str = "neuron";

    fn missing_cache_error(path: PathBuf) -> SnsHostError {
        SnsHostError::MissingNeuronsCache { path }
    }

    fn row_count(data: &Self::Data) -> usize {
        data.neurons.len()
    }

    fn validate_rows(data: &Self::Data) -> Result<(), String> {
        validate_sns_neuron_rows(&data.neurons)
    }
}