Skip to main content

ic_query/sns/report/model/
identity.rs

1//! Canonical SNS canister identities shared by discovery, joined catalogs and reports.
2
3use serde::{Deserialize, Serialize};
4
5///
6/// MainnetSnsCanisters
7///
8/// Complete canister identities for one deployed SNS shared by sources and reports.
9///
10
11#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
12pub struct MainnetSnsCanisters {
13    /// SNS Root canister principal.
14    pub root_canister_id: String,
15    /// SNS Governance canister principal.
16    pub governance_canister_id: String,
17    /// SNS ledger canister principal.
18    pub ledger_canister_id: String,
19    /// SNS decentralization-swap canister principal.
20    pub swap_canister_id: String,
21    /// SNS ledger index canister principal.
22    pub index_canister_id: String,
23}
24
25///
26/// SnsInstanceContext
27///
28/// SNS instance identity and acquisition metadata shared by lookup reports.
29///
30
31#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
32pub struct SnsInstanceContext {
33    /// Requested IC network identity.
34    pub network: String,
35    /// SNS-W canister used for discovery.
36    pub sns_wasm_canister_id: String,
37    /// UTC collection timestamp.
38    pub fetched_at: String,
39    /// Explicit collection endpoint.
40    pub source_endpoint: String,
41    /// Collector identity.
42    pub fetched_by: String,
43    /// Current SNS-W list position.
44    pub id: usize,
45    /// Current SNS display name.
46    pub name: String,
47    /// Stable SNS Root canister identity.
48    pub root_canister_id: String,
49}
50
51///
52/// SnsReportContext
53///
54/// SNS identity and collection provenance shared by governance report envelopes.
55///
56
57#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
58pub struct SnsReportContext {
59    /// Shared record, flattened in JSON.
60    #[serde(flatten)]
61    pub instance: SnsInstanceContext,
62    /// Stable SNS Governance canister identity.
63    pub governance_canister_id: String,
64}
65
66impl<'de> Deserialize<'de> for SnsReportContext {
67    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
68    where
69        D: serde::Deserializer<'de>,
70    {
71        // A strict parent must see every consumed key; nested Serde flattening cannot track them.
72        #[derive(Deserialize)]
73        struct Fields {
74            network: String,
75            sns_wasm_canister_id: String,
76            fetched_at: String,
77            source_endpoint: String,
78            fetched_by: String,
79            id: usize,
80            name: String,
81            root_canister_id: String,
82            governance_canister_id: String,
83        }
84        let fields = Fields::deserialize(deserializer)?;
85        Ok(Self {
86            instance: SnsInstanceContext {
87                network: fields.network,
88                sns_wasm_canister_id: fields.sns_wasm_canister_id,
89                fetched_at: fields.fetched_at,
90                source_endpoint: fields.source_endpoint,
91                fetched_by: fields.fetched_by,
92                id: fields.id,
93                name: fields.name,
94                root_canister_id: fields.root_canister_id,
95            },
96            governance_canister_id: fields.governance_canister_id,
97        })
98    }
99}