use crate::{
cdk::types::Cycles,
ids::{CanisterRole, ComponentInstanceId, ComponentSpecId, FleetBinding, SubnetId},
};
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(
CandidType, Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(transparent)]
pub struct ComponentTopologyDigest([u8; 32]);
impl ComponentTopologyDigest {
#[must_use]
pub const fn from_bytes(bytes: [u8; 32]) -> Self {
Self(bytes)
}
#[must_use]
pub const fn as_bytes(&self) -> &[u8; 32] {
&self.0
}
#[must_use]
pub const fn into_bytes(self) -> [u8; 32] {
self.0
}
}
impl fmt::Display for ComponentTopologyDigest {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
for byte in self.0 {
write!(formatter, "{byte:02x}")?;
}
Ok(())
}
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct CyclesFundingBudget {
pub window_secs: u64,
pub maximum_cycles: Cycles,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct ComponentSpecAdmission {
pub component_spec: ComponentSpecId,
pub spec_hash: [u8; 32],
pub maximum_root_instances: u32,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct FleetSubnetRootLimits {
pub maximum_component_instances: u32,
pub maximum_managed_canisters: u32,
pub maximum_registry_bytes: u64,
pub maximum_wasm_store_bytes: u64,
pub cycles_funding: CyclesFundingBudget,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct FleetCoordinatorBinding {
pub fleet: FleetBinding,
pub coordinator_subnet: SubnetId,
pub coordinator: Principal,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct FleetRegistryAuthority {
pub binding: FleetCoordinatorBinding,
pub epoch: u64,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct FleetSubnetRootBinding {
pub authority: FleetRegistryAuthority,
pub placement_subnet: SubnetId,
pub fleet_subnet_root: Principal,
pub component_admissions: Vec<ComponentSpecAdmission>,
pub component_topology_digest: ComponentTopologyDigest,
pub limits: FleetSubnetRootLimits,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct ComponentBinding {
pub authority: FleetRegistryAuthority,
pub component: ComponentInstanceId,
pub component_spec: ComponentSpecId,
pub spec_hash: [u8; 32],
pub role: CanisterRole,
pub placement_subnet: SubnetId,
pub fleet_subnet_root: Principal,
pub canister_id: Principal,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct ComponentChildBinding {
pub component: ComponentBinding,
pub role: CanisterRole,
pub canister_id: Principal,
}