zink/storage/
value.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//! Key-Value storage
use crate::{ffi, storage::StorageValue, Asm};

/// Storage trait. Currently not for public use
pub trait Storage {
    #[cfg(not(target_family = "wasm"))]
    const STORAGE_KEY: [u8; 32];
    const STORAGE_SLOT: i32;

    type Value: StorageValue + Asm;

    /// Get value from storage.
    fn get() -> Self::Value {
        Asm::push(Self::STORAGE_SLOT);
        Self::Value::sload()
    }

    /// Set value to storage.
    fn set(value: Self::Value) {
        value.push();
        Asm::push(Self::STORAGE_SLOT);
        unsafe {
            ffi::evm::sstore();
        }
    }
}