Skip to main content

canic_core/dto/fixture_provisioning/
mod.rs

1//! Passive fixture content, Store publication and exact target grant contracts.
2
3use crate::ids::{ManagedCanisterBinding, ReleaseBuildId};
4use candid::{CandidType, Principal};
5use serde::{Deserialize, Serialize};
6
7/// One independently decodable opaque chunk selected by an application descriptor.
8#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
9pub struct FixtureChunkDescriptor {
10    pub digest: [u8; 32],
11    pub length: u32,
12}
13
14/// Release-independent fixture content; release authority binds its resulting digest.
15#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
16pub struct FixtureDescriptor {
17    pub schema_version: u16,
18    pub format_hash: [u8; 32],
19    pub encoded_length: u64,
20    pub chunks: Vec<FixtureChunkDescriptor>,
21    pub completion_summary: [u8; 32],
22}
23
24/// One bounded, sequential Store upload; exact earlier chunks may be replayed.
25#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
26pub struct FixtureChunkUpload {
27    pub content_id: [u8; 32],
28    pub index: u32,
29    pub bytes: Vec<u8>,
30}
31
32/// Durable source-byte progress; completion is not an application data receipt.
33#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
34pub struct FixtureSourceStatus {
35    pub content_id: [u8; 32],
36    pub next_chunk: u32,
37    pub chunk_count: u32,
38    pub received_bytes: u64,
39    pub complete: bool,
40}
41
42/// Root-derived installation authority independent of reusable content identity.
43#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
44pub struct FixtureTargetBinding {
45    pub target: ManagedCanisterBinding,
46    pub installation: [u8; 32],
47    pub release_build_id: ReleaseBuildId,
48    pub content_id: [u8; 32],
49}
50
51/// Compare-and-set read-grant intent; stale grant or revoke messages cannot replace it.
52#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
53pub struct FixtureGrantRequest {
54    pub expected_revision: u64,
55    pub binding: FixtureTargetBinding,
56    pub enabled: bool,
57}
58
59/// Current target authority, including revoked revisions retained against stale replay.
60#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
61pub struct FixtureGrant {
62    pub revision: u64,
63    pub binding: FixtureTargetBinding,
64    pub enabled: bool,
65}
66
67/// Authenticated target pull, pinned to the exact granted revision and content.
68#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
69pub struct FixtureChunkRead {
70    pub grant: FixtureGrant,
71    pub index: u32,
72}
73
74/// Closed Store outcomes for deterministic caller retry and conflict handling.
75#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
76pub enum FixtureStoreError {
77    Authority,
78    Bounds,
79    Capacity,
80    Conflict,
81    Content,
82    NotFound,
83    NotReady,
84    Sequence,
85}
86
87/// Immutable source selection installed by Root before the target can import data.
88#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
89pub struct FixtureAssignment {
90    pub store: Principal,
91    pub grant: FixtureGrant,
92    pub descriptor: FixtureDescriptor,
93}
94
95/// Application-owned durable evidence of validated data for one exact installation.
96#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
97pub struct FixtureImportReceipt {
98    pub binding: FixtureTargetBinding,
99    pub completion_summary: [u8; 32],
100}
101
102/// Read-only projection of the application's sole durable import checkpoint.
103#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
104pub struct FixtureImportProgress {
105    pub binding: FixtureTargetBinding,
106    pub next_chunk: u32,
107    pub receipt: Option<Box<FixtureImportReceipt>>,
108}
109
110/// Data prerequisite observed from protected selection and application-owned evidence.
111#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
112pub enum FixtureProvisioningStatus {
113    NotRequired,
114    AwaitingImporter,
115    Pending(Option<Box<FixtureImportProgress>>),
116    Complete(Box<FixtureImportReceipt>),
117    Failed(FixtureImportFailure),
118}
119
120/// Closed consumer failures preserve source, transport and application diagnostic owners.
121#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
122pub enum FixtureImportError {
123    Application { code: u32 },
124    Authority,
125    Busy,
126    Codec(crate::dto::error::Error),
127    ImporterMissing,
128    NotReady,
129    Progress,
130    Receipt,
131    Registration,
132    Runtime(crate::dto::error::Error),
133    Source(FixtureStoreError),
134    SourceRejected(crate::dto::error::Error),
135    Transport(crate::dto::error::Error),
136}
137
138/// Durable failure diagnostics retain the originating application or runtime owner.
139pub use crate::domain::fixture_import::FixtureImportFailure;