pub struct StateManager {
accounts: HashMap<String, AccountState>,
snapshots: Vec<StateSnapshot>,
change_log: Vec<StateChange>,
change_count: u64,
}Expand description
State manager for account and contract states
Fields§
§accounts: HashMap<String, AccountState>§snapshots: Vec<StateSnapshot>§change_log: Vec<StateChange>§change_count: u64Implementations§
§impl StateManager
impl StateManager
pub fn new(_config: &RuntimeConfig) -> Result<Self, RuntimeError>
pub fn new(_config: &RuntimeConfig) -> Result<Self, RuntimeError>
Create new state manager
§impl StateManager
impl StateManager
pub fn get_account(&self, address: &str) -> Option<&AccountState>
pub fn get_account(&self, address: &str) -> Option<&AccountState>
Get account state
pub fn get_balance(&self, address: &str) -> Result<u64, RuntimeError>
pub fn get_balance(&self, address: &str) -> Result<u64, RuntimeError>
Get account balance
pub fn set_balance(
&mut self,
address: &str,
balance: u64,
) -> Result<(), RuntimeError>
pub fn set_balance( &mut self, address: &str, balance: u64, ) -> Result<(), RuntimeError>
Set account balance
pub fn get_nonce(&self, address: &str) -> Result<u64, RuntimeError>
pub fn get_nonce(&self, address: &str) -> Result<u64, RuntimeError>
Get account nonce
pub fn set_nonce(
&mut self,
address: &str,
nonce: u64,
) -> Result<(), RuntimeError>
pub fn set_nonce( &mut self, address: &str, nonce: u64, ) -> Result<(), RuntimeError>
Set account nonce
pub fn set_code(
&mut self,
address: &str,
code: &[u8],
) -> Result<(), RuntimeError>
pub fn set_code( &mut self, address: &str, code: &[u8], ) -> Result<(), RuntimeError>
Set contract code
pub fn create_account(
&mut self,
address: &str,
initial_balance: u64,
) -> Result<(), RuntimeError>
pub fn create_account( &mut self, address: &str, initial_balance: u64, ) -> Result<(), RuntimeError>
Create new account
pub fn delete_account(&mut self, address: &str) -> Result<(), RuntimeError>
pub fn delete_account(&mut self, address: &str) -> Result<(), RuntimeError>
Delete account
pub fn account_exists(&self, address: &str) -> bool
pub fn account_exists(&self, address: &str) -> bool
Check if account exists
§impl StateManager
impl StateManager
pub fn create_snapshot(&mut self, description: String) -> u64
pub fn create_snapshot(&mut self, description: String) -> u64
Create state snapshot
pub fn get_snapshot(&self) -> StateSnapshot
pub fn get_snapshot(&self) -> StateSnapshot
Get state snapshot
pub fn restore_snapshot(
&mut self,
snapshot: StateSnapshot,
) -> Result<(), RuntimeError>
pub fn restore_snapshot( &mut self, snapshot: StateSnapshot, ) -> Result<(), RuntimeError>
Restore from snapshot
§impl StateManager
impl StateManager
pub fn change_count(&self) -> u64
pub fn change_count(&self) -> u64
Get change count
pub fn get_recent_changes(&self, count: usize) -> &[StateChange]
pub fn get_recent_changes(&self, count: usize) -> &[StateChange]
Get recent changes
pub fn clear_change_log(&mut self)
pub fn clear_change_log(&mut self)
Clear change log
§impl StateManager
impl StateManager
pub fn execute_batch(&mut self, batch: StateBatch) -> Result<(), RuntimeError>
pub fn execute_batch(&mut self, batch: StateBatch) -> Result<(), RuntimeError>
Execute state batch
fn apply_change(&mut self, change: &StateChange) -> Result<(), RuntimeError>
§impl StateManager
impl StateManager
pub fn query_state(&self, query: StateQuery) -> Vec<&AccountState>
pub fn query_state(&self, query: StateQuery) -> Vec<&AccountState>
Query state with filters
pub fn get_statistics(&self) -> StateStatistics
pub fn get_statistics(&self) -> StateStatistics
Get state statistics
§impl StateManager
impl StateManager
fn record_change(&mut self, change: StateChange)
fn calculate_hash(&self, data: &[u8]) -> String
fn current_timestamp(&self) -> u64
Trait Implementations§
Source§impl Clone for StateManager
impl Clone for StateManager
Source§fn clone(&self) -> StateManager
fn clone(&self) -> StateManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StateManager
impl Debug for StateManager
Source§impl Default for StateManager
impl Default for StateManager
Source§fn default() -> StateManager
fn default() -> StateManager
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for StateManager
impl RefUnwindSafe for StateManager
impl Send for StateManager
impl Sync for StateManager
impl Unpin for StateManager
impl UnwindSafe for StateManager
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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