Skip to main content

neo_types/
storage.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4/// Neo N3 Storage Context type
5#[derive(Debug, Clone, PartialEq, Eq)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub struct NeoStorageContext {
8    id: u32,
9    read_only: bool,
10}
11
12impl NeoStorageContext {
13    pub fn new(id: u32) -> Self {
14        Self {
15            id,
16            read_only: false,
17        }
18    }
19
20    pub fn with_read_only(id: u32, read_only: bool) -> Self {
21        Self { id, read_only }
22    }
23
24    pub fn read_only(id: u32) -> Self {
25        Self {
26            id,
27            read_only: true,
28        }
29    }
30
31    pub fn id(&self) -> u32 {
32        self.id
33    }
34
35    pub fn is_read_only(&self) -> bool {
36        self.read_only
37    }
38
39    pub fn as_read_only(&self) -> Self {
40        Self {
41            id: self.id,
42            read_only: true,
43        }
44    }
45}