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