Skip to main content

canic_core/ops/runtime/
install_source.rs

1//! Module: ops::runtime::install_source
2//!
3//! Responsibility: describe approved Store-backed chunk sources for install workflows.
4//! Does not own: source resolution, publication, storage, or install execution.
5//! Boundary: the control plane supplies exact source metadata to installation workflows.
6
7use crate::cdk::types::Principal;
8
9///
10/// ApprovedModuleSource
11///
12/// Approved install source metadata and payload for one canister role.
13///
14
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub struct ApprovedModuleSource {
17    source_canister: Principal,
18    source_label: String,
19    module_hash: Vec<u8>,
20    chunk_hashes: Vec<Vec<u8>>,
21    payload_size_bytes: u64,
22}
23
24impl ApprovedModuleSource {
25    /// Construct one chunk-store-backed module source.
26    #[must_use]
27    pub const fn chunked(
28        source_canister: Principal,
29        source_label: String,
30        module_hash: Vec<u8>,
31        chunk_hashes: Vec<Vec<u8>>,
32        payload_size_bytes: u64,
33    ) -> Self {
34        Self {
35            source_canister,
36            source_label,
37            module_hash,
38            chunk_hashes,
39            payload_size_bytes,
40        }
41    }
42
43    /// Return the Store canister that owns the approved chunk set.
44    #[must_use]
45    pub const fn source_canister(&self) -> &Principal {
46        &self.source_canister
47    }
48
49    /// Return the logical source label used for logs and status output.
50    #[must_use]
51    pub fn source_label(&self) -> &str {
52        &self.source_label
53    }
54
55    /// Return the installable wasm module hash.
56    #[must_use]
57    pub fn module_hash(&self) -> &[u8] {
58        &self.module_hash
59    }
60
61    /// Return the raw payload size in bytes.
62    #[must_use]
63    pub const fn payload_size_bytes(&self) -> u64 {
64        self.payload_size_bytes
65    }
66
67    /// Return the approved chunk hashes in deterministic install order.
68    #[must_use]
69    pub fn chunk_hashes(&self) -> &[Vec<u8>] {
70        &self.chunk_hashes
71    }
72
73    /// Return the approved chunk count.
74    #[must_use]
75    pub const fn chunk_count(&self) -> usize {
76        self.chunk_hashes.len()
77    }
78}