Transactional storage for Tezos Smart Rollup kernels.
This crate supports dealing with objects for updating storage. All objects are stored in durable storage.
To use this crate, provide a definition of an object. The object structure should follow these guidelines:
From<OwnedPath>
mut
in
case of setters).NB an object must only look in durable storage prefixed by its
OwnedPath
.
To use this crate, create the wanted value struct and storage object like so:
``` use tezossmartrolluphost::runtime::Runtime; use tezossmartrolluphost::path::{concat, RefPath, OwnedPath}; use tezossmartrollupstorage::storage::Storage; use tezossmartrollupmock::MockHost;
struct MyValue { path: OwnedPath, }
const VALUEPATH: RefPath = RefPath::assertfrom(b"/value");
impl MyValue { pub fn setter(&mut self, host: &mut impl Runtime, v: &str) { let valuepath = concat(&self.path, &VALUEPATH) .expect("Could not get path for value"); host.storewrite(&valuepath, v.as_bytes(), 0) .expect("Could not set value"); }
pub fn getter(
&mut self,
host: &impl Runtime,
) -> Vec
impl From
const VALUESPATH: RefPath = RefPath::assertfrom(b"/values");
let mut host = MockHost::default();
let mut storage = Storage::
storage.begin_transaction(&mut host) .expect("Could not begin transaction");
let valueid = RefPath::assertfrom(b"/my.value.id");
let mut value = storage.createnew(&mut host, &valueid) .expect("Could not create new value") .expect("Value already exists");
value.setter(&mut host, "some value");
storage.commit_transaction(&mut host) .expect("Could not commit transaction"); ```