StorageManager

Struct StorageManager 

Source
pub struct StorageManager {
    storage: HashMap<String, AccountStorage>,
    read_count: u64,
    write_count: u64,
    gas_costs: StorageGasCosts,
}
Expand description

Storage manager for contract storage

Fields§

§storage: HashMap<String, AccountStorage>§read_count: u64§write_count: u64§gas_costs: StorageGasCosts

Implementations§

§

impl StorageManager

pub fn new(_config: &RuntimeConfig) -> Result<Self, RuntimeError>

Create new storage manager

§

impl StorageManager

pub fn get( &mut self, account: &str, key: &[u8], ) -> Result<Option<Vec<u8>>, RuntimeError>

Get storage value

pub fn set( &mut self, account: &str, key: &[u8], value: &[u8], ) -> Result<(), RuntimeError>

Set storage value

pub fn delete(&mut self, account: &str, key: &[u8]) -> Result<(), RuntimeError>

Delete storage value

pub fn exists( &mut self, account: &str, key: &[u8], ) -> Result<bool, RuntimeError>

Check if storage key exists

§

impl StorageManager

pub fn get_storage_size(&self, account: &str) -> Result<usize, RuntimeError>

Get storage size for account

§

impl StorageManager

pub fn commit( &mut self, account: &str, ) -> Result<Vec<StorageChange>, RuntimeError>

Commit pending changes

pub fn rollback(&mut self, account: &str) -> Result<(), RuntimeError>

Rollback pending changes

pub fn get_pending_changes(&self, account: &str) -> Vec<&StorageChange>

Get all pending changes for account

pub fn calculate_pending_gas_cost(&self, account: &str) -> u64

Calculate total gas cost for pending changes

§

impl StorageManager

pub fn query( &mut self, query: StorageQuery, ) -> Result<Vec<(Vec<u8>, Vec<u8>)>, RuntimeError>

Query storage with filters

pub fn get_storage_root(&self, account: &str) -> Result<String, RuntimeError>

Get storage root hash for account (Neo compatibility)

§

impl StorageManager

pub fn read_count(&self) -> u64

Get read count

pub fn write_count(&self) -> u64

Get write count

pub fn get_statistics(&self) -> StorageStatistics

Get storage statistics

pub fn clear(&mut self)

Clear all storage (for testing)

§

impl StorageManager

fn calculate_storage_gas_cost( &self, change_type: &StorageChangeType, value_size: usize, ) -> u64

fn calculate_merkle_root(&self, items: &[(&Vec<u8>, &Vec<u8>)]) -> Vec<u8>

fn empty_root_hash(&self) -> Vec<u8>

Trait Implementations§

Source§

impl Debug for StorageManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.