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 occupied_store_size: String,
145    pub max_store_bytes: u64,
146    pub max_store_size: String,
147    pub remaining_store_bytes: u64,
148    pub remaining_store_size: String,
149    pub headroom_bytes: Option<u64>,
150    pub headroom_size: Option<String>,
151    pub within_headroom: bool,
152    pub template_count: u32,
153    pub max_templates: Option<u32>,
154    pub release_count: u32,
155    pub max_template_versions_per_template: Option<u16>,
156    pub templates: Vec<WasmStoreTemplateStatusResponse>,
157}
158
159///
160/// WasmStorePublicationSlotResponse
161///
162
163#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
164pub enum WasmStorePublicationSlotResponse {
165    Active,
166    Detached,
167    Retired,
168}
169
170///
171/// WasmStoreOverviewStoreResponse
172///
173
174#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
175pub struct WasmStoreOverviewStoreResponse {
176    pub binding: WasmStoreBinding,
177    pub pid: Principal,
178    pub created_at: u64,
179    pub publication_slot: Option<WasmStorePublicationSlotResponse>,
180    pub gc: WasmStoreGcStatusResponse,
181    pub payload_bytes: u64,
182    pub payload_size: String,
183    pub max_store_bytes: u64,
184    pub max_store_size: String,
185    pub remaining_payload_bytes: u64,
186    pub remaining_payload_size: String,
187    pub headroom_bytes: Option<u64>,
188    pub headroom_size: Option<String>,
189    pub within_headroom: bool,
190    pub template_count: u32,
191    pub max_templates: Option<u32>,
192    pub release_count: u32,
193    pub max_template_versions_per_template: Option<u16>,
194    pub templates: Vec<WasmStoreTemplateStatusResponse>,
195}
196
197///
198/// WasmStoreOverviewResponse
199///
200
201#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
202pub struct WasmStoreOverviewResponse {
203    pub publication: WasmStorePublicationStateResponse,
204    pub stores: Vec<WasmStoreOverviewStoreResponse>,
205}
206
207///
208/// TemplateStagingStatusResponse
209///
210
211#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
212pub struct TemplateStagingStatusResponse {
213    pub role: CanisterRole,
214    pub template_id: TemplateId,
215    pub version: TemplateVersion,
216    pub store_binding: WasmStoreBinding,
217    pub chunking_mode: TemplateChunkingMode,
218    pub payload_size_bytes: u64,
219    pub payload_size: String,
220    pub chunk_set_present: bool,
221    pub expected_chunk_count: u32,
222    pub stored_chunk_count: u32,
223    pub publishable: bool,
224}
225
226///
227/// WasmStoreBootstrapDebugResponse
228///
229
230#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
231pub struct WasmStoreBootstrapDebugResponse {
232    pub ready_for_bootstrap: bool,
233    pub bootstrap: Option<TemplateStagingStatusResponse>,
234    pub staged: Vec<TemplateStagingStatusResponse>,
235}
236
237///
238/// WasmStorePublicationStateResponse
239///
240
241#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
242pub struct WasmStorePublicationStateResponse {
243    pub active_binding: Option<WasmStoreBinding>,
244    pub detached_binding: Option<WasmStoreBinding>,
245    pub retired_binding: Option<WasmStoreBinding>,
246    pub generation: u64,
247    pub changed_at: u64,
248    pub retired_at: u64,
249}
250
251///
252/// WasmStorePublicationFinalizationStatusResponse
253///
254
255#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
256pub struct WasmStorePublicationFinalizationStatusResponse {
257    pub finalized_binding: Option<WasmStoreBinding>,
258    pub finalized_at: u64,
259}
260
261///
262/// WasmStoreRetiredStoreStatusResponse
263///
264
265#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
266pub struct WasmStoreRetiredStoreStatusResponse {
267    pub retired_binding: WasmStoreBinding,
268    pub generation: u64,
269    pub retired_at: u64,
270    pub gc_ready: bool,
271    pub reclaimable_store_bytes: u64,
272    pub store: WasmStoreStatusResponse,
273}
274
275///
276/// WasmStoreFinalizedStoreResponse
277///
278
279#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
280pub struct WasmStoreFinalizedStoreResponse {
281    pub binding: WasmStoreBinding,
282    pub store_pid: Principal,
283}
284
285///
286/// WasmStoreAdminCommand
287///
288
289#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
290pub enum WasmStoreAdminCommand {
291    PublishCurrentReleaseToStore {
292        store_pid: Principal,
293    },
294    PublishCurrentReleaseToCurrentStore,
295    SetPublicationBinding {
296        binding: WasmStoreBinding,
297    },
298    ClearPublicationBinding,
299    RetireDetachedBinding,
300    PrepareRetiredStoreGc,
301    BeginRetiredStoreGc,
302    CompleteRetiredStoreGc,
303    FinalizeRetiredBinding,
304    DeleteFinalizedStore {
305        binding: WasmStoreBinding,
306        store_pid: Principal,
307    },
308}
309
310///
311/// WasmStoreAdminResponse
312///
313
314#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
315pub enum WasmStoreAdminResponse {
316    PublishedCurrentReleaseToStore {
317        store_pid: Principal,
318    },
319    PublishedCurrentReleaseToCurrentStore,
320    SetPublicationBinding {
321        binding: WasmStoreBinding,
322    },
323    ClearedPublicationBinding,
324    RetiredDetachedBinding {
325        binding: Option<WasmStoreBinding>,
326    },
327    PreparedRetiredStoreGc {
328        binding: Option<WasmStoreBinding>,
329    },
330    BeganRetiredStoreGc {
331        binding: Option<WasmStoreBinding>,
332    },
333    CompletedRetiredStoreGc {
334        binding: Option<WasmStoreBinding>,
335    },
336    FinalizedRetiredBinding {
337        result: Option<WasmStoreFinalizedStoreResponse>,
338    },
339    DeletedFinalizedStore {
340        binding: WasmStoreBinding,
341        store_pid: Principal,
342    },
343}