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    Unknown,
53}
54
55///
56/// MemoryRangeAuthorityEntry
57///
58
59#[derive(CandidType, Clone, Debug, Deserialize)]
60pub struct MemoryRangeAuthorityEntry {
61    pub owner: String,
62    pub start: u8,
63    pub end: u8,
64    pub mode: MemoryRangeAuthorityMode,
65    pub purpose: String,
66}
67
68///
69/// MemoryRangeAuthorityMode
70///
71
72#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
73pub enum MemoryRangeAuthorityMode {
74    Reserved,
75    Allowed,
76}
77
78///
79/// MemoryLedgerMemoryEntry
80///
81
82#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
83pub struct MemoryLedgerMemoryEntry {
84    pub memory_manager_id: u8,
85    pub stable_key: String,
86    pub state: MemoryAllocationState,
87    pub size: MemoryAllocationSizeEntry,
88}
89
90///
91/// MemoryAllocationRecordEntry
92///
93
94#[derive(CandidType, Clone, Debug, Deserialize)]
95pub struct MemoryAllocationRecordEntry {
96    pub memory_manager_id: Option<u8>,
97    pub stable_key: String,
98    pub state: MemoryAllocationState,
99    pub memory_size: Option<MemoryAllocationSizeEntry>,
100    pub first_generation: u64,
101    pub last_seen_generation: u64,
102    pub retired_generation: Option<u64>,
103    pub schema_history: Vec<MemorySchemaMetadataEntry>,
104}
105
106///
107/// MemoryAllocationSizeEntry
108///
109
110#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
111pub struct MemoryAllocationSizeEntry {
112    pub wasm_pages: u64,
113    pub bytes: u64,
114}
115
116///
117/// MemoryAllocationState
118///
119
120#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
121pub enum MemoryAllocationState {
122    Reserved,
123    Active,
124    Retired,
125}
126
127///
128/// MemorySchemaMetadataEntry
129///
130
131#[derive(CandidType, Clone, Debug, Deserialize)]
132pub struct MemorySchemaMetadataEntry {
133    pub generation: u64,
134    pub schema_version: Option<u32>,
135    pub schema_fingerprint: Option<String>,
136}
137
138///
139/// MemoryLedgerGenerationEntry
140///
141
142#[derive(CandidType, Clone, Debug, Deserialize)]
143pub struct MemoryLedgerGenerationEntry {
144    pub generation: u64,
145    pub parent_generation: Option<u64>,
146    pub runtime_fingerprint: Option<String>,
147    pub declaration_count: u32,
148    pub committed_at: Option<u64>,
149}