use crate::{
cdk::types::Principal,
model::topology::{TopologyEntry, TopologyRegistry},
storage::{canister::CanisterRecord, stable::registry::subnet::SubnetRegistryData},
};
pub struct TopologyEntryMapper;
impl TopologyEntryMapper {
#[must_use]
pub fn record_to_entry(pid: Principal, record: CanisterRecord) -> TopologyEntry {
TopologyEntry {
pid,
role: record.role,
parent_pid: record.parent_pid,
module_hash: record.module_hash,
}
}
}
pub struct TopologyRegistryMapper;
impl TopologyRegistryMapper {
#[must_use]
pub fn data_to_registry(data: SubnetRegistryData) -> TopologyRegistry {
TopologyRegistry {
entries: data
.entries
.into_iter()
.map(|entry| TopologyEntryMapper::record_to_entry(entry.pid, entry.record))
.collect(),
}
}
}