use serde::{Deserialize, Serialize};
#[cfg(feature = "nns-host")]
pub(super) const NNS_REGISTRY_VERSION_REPORT_SCHEMA_VERSION: u32 = 2;
#[cfg(feature = "nns-host")]
pub(super) const NNS_CERTIFIED_REGISTRY_DELTA_BATCH_SCHEMA_VERSION: u32 = 2;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NnsRegistryVersionRequest {
pub network: String,
pub source_endpoint: String,
pub now_unix_secs: u64,
}
impl NnsRegistryVersionRequest {
#[must_use]
pub fn new(
network: impl Into<String>,
source_endpoint: impl Into<String>,
now_unix_secs: u64,
) -> Self {
Self {
network: network.into(),
source_endpoint: source_endpoint.into(),
now_unix_secs,
}
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsRegistryVersionReport {
pub schema_version: u32,
pub network: String,
pub registry_canister_id: String,
pub registry_version: u64,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub certification: NnsRegistryCertification,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsRegistryCertification {
pub certificate_verified: bool,
pub certificate_time_nanos: u64,
pub certificate_time: String,
pub root_key_digest: String,
pub certificate_hex: String,
pub certificate_bytes: usize,
pub hash_tree_hex: String,
pub hash_tree_bytes: usize,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NnsCertifiedRegistryDeltaBatchRequest {
pub network: String,
pub source_endpoint: String,
pub requested_version: u64,
pub now_unix_secs: u64,
}
impl NnsCertifiedRegistryDeltaBatchRequest {
#[must_use]
pub fn new(
network: impl Into<String>,
source_endpoint: impl Into<String>,
requested_version: u64,
now_unix_secs: u64,
) -> Self {
Self {
network: network.into(),
source_endpoint: source_endpoint.into(),
requested_version,
now_unix_secs,
}
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsCertifiedRegistryDeltaBatchReport {
pub schema_version: u32,
pub network: String,
pub registry_canister_id: String,
pub requested_version: u64,
pub certified_latest_version: u64,
pub first_version: Option<u64>,
pub last_version: Option<u64>,
pub version_count: usize,
pub mutation_count: usize,
pub precondition_count: usize,
pub inline_value_bytes: usize,
pub chunk_value_bytes: usize,
pub value_bytes: usize,
pub chunk_reference_count: usize,
pub more_available: bool,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub query_call_count: u64,
pub chunk_query_call_count: u64,
pub certified_response_bytes: usize,
pub chunk_response_bytes: usize,
pub response_bytes: usize,
pub limits: NnsCertifiedRegistryDeltaLimits,
pub versions: Vec<NnsCertifiedRegistryDeltaVersion>,
pub certification: NnsRegistryCertification,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsCertifiedRegistryDeltaLimits {
pub max_versions: usize,
pub max_mutations: usize,
pub max_preconditions: usize,
pub max_key_bytes: usize,
pub max_inline_value_bytes: usize,
pub max_chunk_references: usize,
pub max_chunk_bytes: usize,
pub max_reconstructed_value_bytes: usize,
pub max_value_bytes: usize,
pub max_chunk_response_bytes: usize,
pub max_response_body_bytes: usize,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsCertifiedRegistryDeltaVersion {
pub version: u64,
pub timestamp_nanoseconds: u64,
pub mutations: Vec<NnsCertifiedRegistryMutation>,
pub preconditions: Vec<NnsCertifiedRegistryPrecondition>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsCertifiedRegistryMutation {
pub mutation_type: i32,
pub mutation_kind: NnsCertifiedRegistryMutationKind,
pub key_hex: String,
pub value_encoding: NnsCertifiedRegistryValueEncoding,
pub chunk_sha256_hexes: Vec<String>,
pub value_hex: Option<String>,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum NnsCertifiedRegistryValueEncoding {
Absent,
Inline,
Chunked,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum NnsCertifiedRegistryMutationKind {
Insert,
Update,
Delete,
Upsert,
}
#[cfg(feature = "nns-host")]
impl NnsCertifiedRegistryMutationKind {
pub(super) const fn raw_type(self) -> i32 {
match self {
Self::Insert => 0,
Self::Update => 1,
Self::Delete => 2,
Self::Upsert => 4,
}
}
pub(super) const fn from_raw_type(value: i32) -> Option<Self> {
match value {
0 => Some(Self::Insert),
1 => Some(Self::Update),
2 => Some(Self::Delete),
4 => Some(Self::Upsert),
_ => None,
}
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsCertifiedRegistryPrecondition {
pub key_hex: String,
pub expected_version: u64,
}