Struct miden_objects::accounts::AccountStorage
source · pub struct AccountStorage { /* private fields */ }Expand description
Account storage consists of 256 index-addressable storage slots.
Each slot has a type which defines the size and the structure of the slot. Currently, the following types are supported:
- Scalar: a sequence of up to 256 words.
- Array: a sparse array of up to 2^n values where n > 1 and n <= 64 and each value contains up to 256 words.
- Map: a key-value map where keys are words and values contain up to 256 words.
Storage slots are stored in a simple Sparse Merkle Tree of depth 8. Slot 255 is always reserved and contains information about slot types of all other slots.
Optionally, a user can make use of storage maps. Storage maps are represented by a SMT and they can hold more data as there is in plain usage of the storage slots. The root of the SMT consumes one storage slot.
Implementations§
source§impl AccountStorage
impl AccountStorage
sourcepub const STORAGE_TREE_DEPTH: u8 = 8u8
pub const STORAGE_TREE_DEPTH: u8 = 8u8
Depth of the storage tree.
sourcepub const NUM_STORAGE_SLOTS: usize = 256usize
pub const NUM_STORAGE_SLOTS: usize = 256usize
Total number of storage slots.
sourcepub const SLOT_LAYOUT_COMMITMENT_INDEX: u8 = 255u8
pub const SLOT_LAYOUT_COMMITMENT_INDEX: u8 = 255u8
The storage slot at which the layout commitment is stored.
sourcepub fn new(
items: Vec<SlotItem>,
maps: BTreeMap<u8, StorageMap>,
) -> Result<AccountStorage, AccountError>
pub fn new( items: Vec<SlotItem>, maps: BTreeMap<u8, StorageMap>, ) -> Result<AccountStorage, AccountError>
Returns a new instance of account storage initialized with the provided items.
sourcepub fn get_item(&self, index: u8) -> Digest
pub fn get_item(&self, index: u8) -> Digest
Returns an item from the storage at the specified index.
If the item is not present in the storage, crate::EMPTY_WORD is returned.
sourcepub fn get_map_item(&self, index: u8, key: Word) -> Result<Word, AccountError>
pub fn get_map_item(&self, index: u8, key: Word) -> Result<Word, AccountError>
Returns a map item from the storage at the specified index.
If the item is not present in the storage, crate::EMPTY_WORD is returned.
sourcepub fn slots(&self) -> &SimpleSmt<STORAGE_TREE_DEPTH>
pub fn slots(&self) -> &SimpleSmt<STORAGE_TREE_DEPTH>
Returns a reference to the Sparse Merkle Tree that backs the storage slots.
sourcepub fn layout(&self) -> &[StorageSlotType]
pub fn layout(&self) -> &[StorageSlotType]
Returns layout info for this storage.
sourcepub fn layout_commitment(&self) -> Digest
pub fn layout_commitment(&self) -> Digest
Returns a commitment to the storage layout.
sourcepub fn maps(&self) -> &BTreeMap<u8, StorageMap>
pub fn maps(&self) -> &BTreeMap<u8, StorageMap>
Returns the storage maps for this storage.
sourcepub fn set_item(&mut self, index: u8, value: Word) -> Result<Word, AccountError>
pub fn set_item(&mut self, index: u8, value: Word) -> Result<Word, AccountError>
Updates the value of the storage slot at the specified index.
This method should be used only to update simple value slots. For updating values in storage maps, please see AccountStorage::set_map_item().
§Errors
Returns an error if:
- The index specifies a reserved storage slot.
- The update tries to set a slot of type array.
- The update has a value arity different from 0.
sourcepub fn set_map_item(
&mut self,
index: u8,
key: Word,
value: Word,
) -> Result<(Word, Word), AccountError>
pub fn set_map_item( &mut self, index: u8, key: Word, value: Word, ) -> Result<(Word, Word), AccountError>
Updates the value of a key-value pair of a storage map at the specified index.
This method should be used only to update storage maps. For updating values in storage slots, please see AccountStorage::set_item().
§Errors
Returns an error if:
- The index specifies a reserved storage slot.
- The index is not a map slot.
- The update tries to set a slot of type value or array.
- The update has a value arity different from 0.
Trait Implementations§
source§impl Clone for AccountStorage
impl Clone for AccountStorage
source§fn clone(&self) -> AccountStorage
fn clone(&self) -> AccountStorage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for AccountStorage
impl Debug for AccountStorage
source§impl Deserializable for AccountStorage
impl Deserializable for AccountStorage
source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source, attempts to deserialize these bytes
into Self, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl PartialEq for AccountStorage
impl PartialEq for AccountStorage
source§fn eq(&self, other: &AccountStorage) -> bool
fn eq(&self, other: &AccountStorage) -> bool
self and other values to be equal, and is used
by ==.source§impl Serializable for AccountStorage
impl Serializable for AccountStorage
source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self into bytes and writes these bytes into the target.source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Eq for AccountStorage
impl StructuralPartialEq for AccountStorage
Auto Trait Implementations§
impl Freeze for AccountStorage
impl RefUnwindSafe for AccountStorage
impl Send for AccountStorage
impl Sync for AccountStorage
impl Unpin for AccountStorage
impl UnwindSafe for AccountStorage
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)