oasis_contract_sdk_storage/
cell.rs1use std::marker::PhantomData;
3
4use oasis_contract_sdk::storage::{ConfidentialStore, PublicStore};
5
6macro_rules! declare_cell {
7 ($name:ident, $store:ident) => {
8 pub struct $name<'key, T> {
10 key: &'key [u8],
11 _type: PhantomData<T>,
12 }
13
14 impl<'key, T> $name<'key, T> {
15 pub const fn new(key: &'key [u8]) -> Self {
17 Self {
18 key,
19 _type: PhantomData,
20 }
21 }
22
23 pub fn clear(&self, store: &mut dyn $store) {
25 store.remove(self.key);
26 }
27 }
28
29 impl<'key, T> $name<'key, T>
30 where
31 T: cbor::Decode,
32 {
33 pub fn get(&self, store: &dyn $store) -> Option<T> {
40 store
41 .get(self.key)
42 .map(|raw| cbor::from_slice(&raw).unwrap())
43 }
44 }
45
46 impl<'key, T> $name<'key, T>
47 where
48 T: cbor::Encode,
49 {
50 pub fn set(&self, store: &mut dyn $store, value: T) {
52 store.insert(self.key, &cbor::to_vec(value));
53 }
54 }
55 };
56}
57
58declare_cell!(PublicCell, PublicStore);
59declare_cell!(ConfidentialCell, ConfidentialStore);