ic_query/subnet_catalog/resolver/
model.rs1use crate::subnet_catalog::{RoutingRange, SubnetCatalogProvenance, SubnetInfo};
6use candid::Principal;
7use serde::{Deserialize, Serialize};
8use std::str::FromStr;
9
10#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
17#[serde(rename_all = "snake_case")]
18pub enum ResolveAs {
19 Subnet,
21 Canister,
23}
24
25impl ResolveAs {
26 #[must_use]
28 pub const fn as_str(self) -> &'static str {
29 match self {
30 Self::Subnet => "subnet",
31 Self::Canister => "canister",
32 }
33 }
34}
35
36impl FromStr for ResolveAs {
37 type Err = String;
38
39 fn from_str(value: &str) -> Result<Self, Self::Err> {
40 match value {
41 "subnet" => Ok(Self::Subnet),
42 "canister" => Ok(Self::Canister),
43 other => Err(format!("invalid value {other}; use subnet or canister")),
44 }
45 }
46}
47
48#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
55#[serde(rename_all = "snake_case")]
56pub enum ResolvedSubnetSubject {
57 Subnet,
59 Canister,
61}
62
63impl ResolvedSubnetSubject {
64 #[must_use]
66 pub const fn as_str(self) -> &'static str {
67 match self {
68 Self::Subnet => "subnet",
69 Self::Canister => "canister",
70 }
71 }
72}
73
74#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
81pub struct ResolvedSubnet {
82 pub input_principal: String,
83 pub resolved_as: ResolvedSubnetSubject,
84 pub resolved_from: String,
85 pub subnet: SubnetInfo,
86 pub matched_canister_principal: Option<String>,
87 pub matched_routing_range: Option<RoutingRange>,
88 pub catalog_digest: String,
90 pub provenance: SubnetCatalogProvenance,
92}
93
94#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
101pub struct ResolvedCanisterRoute {
102 pub canister: Principal,
104 pub subnet: Principal,
106 pub subnet_info: SubnetInfo,
108 pub matched_range: RoutingRange,
110 pub registry_version: u64,
112 pub catalog_digest: [u8; 32],
114 pub provenance: SubnetCatalogProvenance,
116}