use crate::{
ffi,
storage::{StorageValue, TransientStorageValue},
Asm,
};
pub trait Storage {
#[cfg(not(target_family = "wasm"))]
const STORAGE_KEY: [u8; 32];
const STORAGE_SLOT: i32;
type Value: StorageValue + Asm;
fn get() -> Self::Value {
Asm::push(Self::STORAGE_SLOT);
Self::Value::sload()
}
fn set(value: Self::Value) {
value.push();
Asm::push(Self::STORAGE_SLOT);
unsafe {
ffi::evm::sstore();
}
}
}
pub trait TransientStorage {
#[cfg(not(target_family = "wasm"))]
const STORAGE_KEY: [u8; 32];
const STORAGE_SLOT: i32;
type Value: TransientStorageValue + Asm;
fn get() -> Self::Value {
Asm::push(Self::STORAGE_SLOT);
Self::Value::tload()
}
fn set(value: Self::Value) {
value.push();
Asm::push(Self::STORAGE_SLOT);
unsafe {
ffi::evm::tstore();
}
}
}