Skip to main content

canic_core/dto/template/
mod.rs

1use crate::dto::prelude::*;
2use crate::ids::{
3    TemplateChunkingMode, TemplateId, TemplateManifestState, TemplateVersion, WasmStoreBinding,
4    WasmStoreGcMode,
5};
6
7///
8/// TemplateManifestInput
9///
10
11#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
12pub struct TemplateManifestInput {
13    pub template_id: TemplateId,
14    pub role: CanisterRole,
15    pub version: TemplateVersion,
16    pub payload_hash: Vec<u8>,
17    pub payload_size_bytes: u64,
18    pub store_binding: WasmStoreBinding,
19    pub chunking_mode: TemplateChunkingMode,
20    pub manifest_state: TemplateManifestState,
21    pub approved_at: Option<u64>,
22    pub created_at: u64,
23}
24
25///
26/// TemplateManifestResponse
27///
28
29#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
30pub struct TemplateManifestResponse {
31    pub template_id: TemplateId,
32    pub role: CanisterRole,
33    pub version: TemplateVersion,
34    pub payload_hash: Vec<u8>,
35    pub payload_size_bytes: u64,
36    pub store_binding: WasmStoreBinding,
37    pub chunking_mode: TemplateChunkingMode,
38    pub manifest_state: TemplateManifestState,
39    pub approved_at: Option<u64>,
40    pub created_at: u64,
41}
42
43///
44/// TemplateChunkSetInput
45///
46
47#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
48pub struct TemplateChunkSetInput {
49    pub template_id: TemplateId,
50    pub version: TemplateVersion,
51    pub payload_hash: Vec<u8>,
52    pub payload_size_bytes: u64,
53    pub chunks: Vec<Vec<u8>>,
54}
55
56///
57/// TemplateChunkSetPrepareInput
58///
59
60#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
61pub struct TemplateChunkSetPrepareInput {
62    pub template_id: TemplateId,
63    pub version: TemplateVersion,
64    pub payload_hash: Vec<u8>,
65    pub payload_size_bytes: u64,
66    pub chunk_hashes: Vec<Vec<u8>>,
67}
68
69///
70/// TemplateChunkInput
71///
72
73#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
74pub struct TemplateChunkInput {
75    pub template_id: TemplateId,
76    pub version: TemplateVersion,
77    pub chunk_index: u32,
78    pub bytes: Vec<u8>,
79}
80
81///
82/// TemplateChunkSetInfoResponse
83///
84
85#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
86pub struct TemplateChunkSetInfoResponse {
87    pub chunk_hashes: Vec<Vec<u8>>,
88}
89
90///
91/// TemplateChunkResponse
92///
93
94#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
95pub struct TemplateChunkResponse {
96    pub bytes: Vec<u8>,
97}
98
99///
100/// WasmStoreCatalogEntryResponse
101///
102
103#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
104pub struct WasmStoreCatalogEntryResponse {
105    pub role: CanisterRole,
106    pub template_id: TemplateId,
107    pub version: TemplateVersion,
108    pub payload_hash: Vec<u8>,
109    pub payload_size_bytes: u64,
110}
111
112///
113/// WasmStoreTemplateStatusResponse
114///
115
116#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
117pub struct WasmStoreTemplateStatusResponse {
118    pub template_id: TemplateId,
119    pub versions: u16,
120}
121
122///
123/// WasmStoreGcStatusResponse
124///
125
126#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
127pub struct WasmStoreGcStatusResponse {
128    pub mode: WasmStoreGcMode,
129    pub changed_at: u64,
130    pub prepared_at: Option<u64>,
131    pub started_at: Option<u64>,
132    pub completed_at: Option<u64>,
133    pub runs_completed: u32,
134}
135
136///
137/// WasmStoreStatusResponse
138///
139
140#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
141pub struct WasmStoreStatusResponse {
142    pub gc: WasmStoreGcStatusResponse,
143    pub occupied_store_bytes: u64,
144    pub max_store_bytes: u64,
145    pub remaining_store_bytes: u64,
146    pub headroom_bytes: Option<u64>,
147    pub within_headroom: bool,
148    pub template_count: u32,
149    pub max_templates: Option<u32>,
150    pub release_count: u32,
151    pub max_template_versions_per_template: Option<u16>,
152    pub templates: Vec<WasmStoreTemplateStatusResponse>,
153}
154
155///
156/// WasmStorePublicationStateResponse
157///
158
159#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
160pub struct WasmStorePublicationStateResponse {
161    pub active_binding: Option<WasmStoreBinding>,
162    pub detached_binding: Option<WasmStoreBinding>,
163    pub retired_binding: Option<WasmStoreBinding>,
164    pub generation: u64,
165    pub changed_at: u64,
166    pub retired_at: u64,
167}
168
169///
170/// WasmStorePublicationFinalizationStatusResponse
171///
172
173#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
174pub struct WasmStorePublicationFinalizationStatusResponse {
175    pub finalized_binding: Option<WasmStoreBinding>,
176    pub finalized_at: u64,
177}
178
179///
180/// WasmStoreRetiredStoreStatusResponse
181///
182
183#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
184pub struct WasmStoreRetiredStoreStatusResponse {
185    pub retired_binding: WasmStoreBinding,
186    pub generation: u64,
187    pub retired_at: u64,
188    pub gc_ready: bool,
189    pub reclaimable_store_bytes: u64,
190    pub store: WasmStoreStatusResponse,
191}
192
193///
194/// WasmStoreFinalizedStoreResponse
195///
196
197#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
198pub struct WasmStoreFinalizedStoreResponse {
199    pub binding: WasmStoreBinding,
200    pub store_pid: Principal,
201}
202
203///
204/// WasmStoreAdminCommand
205///
206
207#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
208pub enum WasmStoreAdminCommand {
209    PublishCurrentReleaseToStore {
210        store_pid: Principal,
211    },
212    PublishCurrentReleaseToCurrentStore,
213    SetPublicationBinding {
214        binding: WasmStoreBinding,
215    },
216    ClearPublicationBinding,
217    RetireDetachedBinding,
218    PrepareRetiredStoreGc,
219    BeginRetiredStoreGc,
220    CompleteRetiredStoreGc,
221    FinalizeRetiredBinding,
222    DeleteFinalizedStore {
223        binding: WasmStoreBinding,
224        store_pid: Principal,
225    },
226}
227
228///
229/// WasmStoreAdminResponse
230///
231
232#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
233pub enum WasmStoreAdminResponse {
234    PublishedCurrentReleaseToStore {
235        store_pid: Principal,
236    },
237    PublishedCurrentReleaseToCurrentStore,
238    SetPublicationBinding {
239        binding: WasmStoreBinding,
240    },
241    ClearedPublicationBinding,
242    RetiredDetachedBinding {
243        binding: Option<WasmStoreBinding>,
244    },
245    PreparedRetiredStoreGc {
246        binding: Option<WasmStoreBinding>,
247    },
248    BeganRetiredStoreGc {
249        binding: Option<WasmStoreBinding>,
250    },
251    CompletedRetiredStoreGc {
252        binding: Option<WasmStoreBinding>,
253    },
254    FinalizedRetiredBinding {
255        result: Option<WasmStoreFinalizedStoreResponse>,
256    },
257    DeletedFinalizedStore {
258        binding: WasmStoreBinding,
259        store_pid: Principal,
260    },
261}