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.
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>) -> Result<AccountStorage, AccountError>
pub fn new(items: Vec<SlotItem>) -> 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, [ZERO; 4] 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.
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.