ic-query 0.101.0

Internet Computer query library for CloudEngine, NNS, SNS, ICRC, system canisters, and public network metadata
Documentation
//! Module: sns::report::assemble
//!
//! Responsibility: assemble live and cached SNS neuron list reports.
//! Does not own: neuron fetching, sorting, cache loading, or rendering.
//! Boundary: carries source scope and pre-limit totals supplied by each caller.

use crate::report::{CollectionSourceRequest, ReportProvenance};
use crate::snapshot_cache::SnapshotEnvelope;
use crate::sns::report::SnsReportContext;
use crate::sns::report::{
    SNS_NEURONS_REPORT_SCHEMA_VERSION, SnsNeuronRow, SnsNeuronsReport, SnsNeuronsRequest,
};
use crate::sns::report::{SnsInstanceContext, cache_storage::SnsCacheMetadata};

/// Assemble selected neuron rows with their original acquisition scope and total.
pub(in crate::sns::report) fn sns_neurons_report_from_rows(
    request: &SnsNeuronsRequest,
    context: SnsReportContext,
    provenance: ReportProvenance,
    owner_principal_id: Option<String>,
    total_neuron_count: usize,
    neurons: Vec<SnsNeuronRow>,
) -> SnsNeuronsReport {
    SnsNeuronsReport {
        provenance,
        schema_version: SNS_NEURONS_REPORT_SCHEMA_VERSION,
        context,
        requested_limit: request.limit,
        owner_principal_id,

        sort: request.collection.sort_label().to_string(),
        total_neuron_count,

        neurons,
    }
}

impl SnsReportContext {
    pub(in crate::sns::report) fn from_snapshot<Data>(
        cache: SnapshotEnvelope<SnsCacheMetadata, Data>,
    ) -> (Self, Data) {
        (
            Self {
                instance: SnsInstanceContext {
                    network: cache.network,
                    fetched_at: cache.fetched_at,
                    source_endpoint: cache.source_endpoint,
                    fetched_by: cache.fetched_by,
                },
                governance_canister_id: cache.metadata.governance_canister_id,
            },
            cache.data,
        )
    }
    pub(in crate::sns::report) fn from_live(
        request: CollectionSourceRequest,
        governance_canister_id: String,
    ) -> Self {
        Self {
            instance: SnsInstanceContext {
                network: request.network,
                fetched_at: request.fetched_at,
                source_endpoint: request.endpoint,
                fetched_by: request.fetched_by,
            },
            governance_canister_id,
        }
    }
}