Skip to main content

canic_core/dto/
memory.rs

1use crate::dto::prelude::*;
2
3///
4/// MemoryLedgerResponse
5///
6
7#[derive(CandidType, Clone, Debug, Deserialize)]
8pub struct MemoryLedgerResponse {
9    pub ledger_schema_version: u32,
10    pub physical_format_id: u32,
11    pub current_generation: u64,
12    pub commit_recovery: MemoryCommitRecoveryResponse,
13    pub authorities: Vec<MemoryRangeAuthorityEntry>,
14    pub memories: Vec<MemoryLedgerMemoryEntry>,
15    pub records: Vec<MemoryAllocationRecordEntry>,
16    pub generations: Vec<MemoryLedgerGenerationEntry>,
17}
18
19///
20/// MemoryCommitRecoveryResponse
21///
22
23#[derive(CandidType, Clone, Debug, Deserialize)]
24pub struct MemoryCommitRecoveryResponse {
25    pub slot0: MemoryCommitSlotResponse,
26    pub slot1: MemoryCommitSlotResponse,
27    pub authoritative_generation: Option<u64>,
28    pub recovery_error: Option<MemoryCommitRecoveryErrorResponse>,
29}
30
31///
32/// MemoryCommitSlotResponse
33///
34
35#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
36pub struct MemoryCommitSlotResponse {
37    pub present: bool,
38    pub generation: Option<u64>,
39    pub valid: bool,
40}
41
42///
43/// MemoryCommitRecoveryErrorResponse
44///
45
46#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
47pub enum MemoryCommitRecoveryErrorResponse {
48    NoValidGeneration,
49    AmbiguousGeneration,
50    GenerationOverflow,
51    UnexpectedGeneration,
52}
53
54///
55/// MemoryRangeAuthorityEntry
56///
57
58#[derive(CandidType, Clone, Debug, Deserialize)]
59pub struct MemoryRangeAuthorityEntry {
60    pub owner: String,
61    pub start: u8,
62    pub end: u8,
63    pub mode: MemoryRangeAuthorityMode,
64    pub purpose: String,
65}
66
67///
68/// MemoryRangeAuthorityMode
69///
70
71#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
72pub enum MemoryRangeAuthorityMode {
73    Reserved,
74    Allowed,
75}
76
77///
78/// MemoryLedgerMemoryEntry
79///
80
81#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
82pub struct MemoryLedgerMemoryEntry {
83    pub memory_manager_id: u8,
84    pub stable_key: String,
85    pub state: MemoryAllocationState,
86    pub size: MemoryAllocationSizeEntry,
87}
88
89///
90/// MemoryAllocationRecordEntry
91///
92
93#[derive(CandidType, Clone, Debug, Deserialize)]
94pub struct MemoryAllocationRecordEntry {
95    pub memory_manager_id: Option<u8>,
96    pub stable_key: String,
97    pub state: MemoryAllocationState,
98    pub memory_size: Option<MemoryAllocationSizeEntry>,
99    pub first_generation: u64,
100    pub last_seen_generation: u64,
101    pub retired_generation: Option<u64>,
102    pub schema_history: Vec<MemorySchemaMetadataEntry>,
103}
104
105///
106/// MemoryAllocationSizeEntry
107///
108
109#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
110pub struct MemoryAllocationSizeEntry {
111    pub wasm_pages: u64,
112    pub bytes: u64,
113}
114
115///
116/// MemoryAllocationState
117///
118
119#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
120pub enum MemoryAllocationState {
121    Reserved,
122    Active,
123    Retired,
124}
125
126///
127/// MemorySchemaMetadataEntry
128///
129
130#[derive(CandidType, Clone, Debug, Deserialize)]
131pub struct MemorySchemaMetadataEntry {
132    pub generation: u64,
133    pub schema_version: Option<u32>,
134    pub schema_fingerprint: Option<String>,
135}
136
137///
138/// MemoryLedgerGenerationEntry
139///
140
141#[derive(CandidType, Clone, Debug, Deserialize)]
142pub struct MemoryLedgerGenerationEntry {
143    pub generation: u64,
144    pub parent_generation: Option<u64>,
145    pub runtime_fingerprint: Option<String>,
146    pub declaration_count: u32,
147    pub committed_at: Option<u64>,
148}