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 records: Vec<MemoryAllocationRecordEntry>,
15    pub generations: Vec<MemoryLedgerGenerationEntry>,
16}
17
18///
19/// MemoryCommitRecoveryResponse
20///
21
22#[derive(CandidType, Clone, Debug, Deserialize)]
23pub struct MemoryCommitRecoveryResponse {
24    pub slot0: MemoryCommitSlotResponse,
25    pub slot1: MemoryCommitSlotResponse,
26    pub authoritative_generation: Option<u64>,
27    pub recovery_error: Option<MemoryCommitRecoveryErrorResponse>,
28}
29
30///
31/// MemoryCommitSlotResponse
32///
33
34#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
35pub struct MemoryCommitSlotResponse {
36    pub present: bool,
37    pub generation: Option<u64>,
38    pub valid: bool,
39}
40
41///
42/// MemoryCommitRecoveryErrorResponse
43///
44
45#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
46pub enum MemoryCommitRecoveryErrorResponse {
47    NoValidGeneration,
48    AmbiguousGeneration,
49    GenerationOverflow,
50    UnexpectedGeneration,
51}
52
53///
54/// MemoryRangeAuthorityEntry
55///
56
57#[derive(CandidType, Clone, Debug, Deserialize)]
58pub struct MemoryRangeAuthorityEntry {
59    pub owner: String,
60    pub start: u8,
61    pub end: u8,
62    pub mode: MemoryRangeAuthorityMode,
63    pub purpose: String,
64}
65
66///
67/// MemoryRangeAuthorityMode
68///
69
70#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
71pub enum MemoryRangeAuthorityMode {
72    Reserved,
73    Allowed,
74}
75
76///
77/// MemoryAllocationRecordEntry
78///
79
80#[derive(CandidType, Clone, Debug, Deserialize)]
81pub struct MemoryAllocationRecordEntry {
82    pub memory_manager_id: Option<u8>,
83    pub stable_key: String,
84    pub state: MemoryAllocationState,
85    pub first_generation: u64,
86    pub last_seen_generation: u64,
87    pub retired_generation: Option<u64>,
88    pub schema_history: Vec<MemorySchemaMetadataEntry>,
89}
90
91///
92/// MemoryAllocationState
93///
94
95#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
96pub enum MemoryAllocationState {
97    Reserved,
98    Active,
99    Retired,
100}
101
102///
103/// MemorySchemaMetadataEntry
104///
105
106#[derive(CandidType, Clone, Debug, Deserialize)]
107pub struct MemorySchemaMetadataEntry {
108    pub generation: u64,
109    pub schema_version: Option<u32>,
110    pub schema_fingerprint: Option<String>,
111}
112
113///
114/// MemoryLedgerGenerationEntry
115///
116
117#[derive(CandidType, Clone, Debug, Deserialize)]
118pub struct MemoryLedgerGenerationEntry {
119    pub generation: u64,
120    pub parent_generation: Option<u64>,
121    pub runtime_fingerprint: Option<String>,
122    pub declaration_count: u32,
123    pub committed_at: Option<u64>,
124}