[][src]Struct cita_state::State

pub struct State<B> {
    pub db: B,
    pub root: H256,
    pub cache: RefCell<HashMap<Address, StateObjectEntry>>,
    pub checkpoints: RefCell<Vec<HashMap<Address, Option<StateObjectEntry>>>>,
}

State is the one who managers all accounts and states in Ethereum's system.

Fields

db: Broot: H256cache: RefCell<HashMap<Address, StateObjectEntry>>checkpoints: RefCell<Vec<HashMap<Address, Option<StateObjectEntry>>>>

Checkpoints are used to revert to history.

Methods

impl<B: DB> State<B>[src]

pub fn new(db: B) -> Result<State<B>, Error>[src]

Creates empty state for test.

pub fn from_existing(db: B, root: H256) -> Result<State<B>, Error>[src]

Creates new state with existing state root

pub fn new_contract(
    &mut self,
    contract: &Address,
    balance: U256,
    nonce: U256,
    code: Vec<u8>
) -> StateObject
[src]

Create a contract account with code or not Overwrite the code if the contract already exists

pub fn kill_contract(&mut self, contract: &Address)[src]

Kill a contract.

pub fn kill_garbage(&mut self, inused: &HashSet<Address>)[src]

Remove any touched empty or dust accounts.

pub fn clear(&mut self)[src]

Clear cache Note that the cache is just a HashMap, so memory explosion will be happend if you never call clear(). You should decide for yourself when to call this function.

pub fn get_state_object(
    &mut self,
    address: &Address
) -> Result<Option<StateObject>, Error>
[src]

Get state object.

pub fn get_state_object_or_default(
    &mut self,
    address: &Address
) -> Result<StateObject, Error>
[src]

Get state object. If not exists, create a fresh one.

pub fn exist(&mut self, address: &Address) -> Result<bool, Error>[src]

Check if an account exists.

pub fn is_empty(&mut self, address: &Address) -> Result<bool, Error>[src]

Check if an account is empty. Empty is defined according to EIP161 (balance = nonce = code = 0).

pub fn set_storage(
    &mut self,
    address: &Address,
    key: H256,
    value: H256
) -> Result<(), Error>
[src]

Set (key, value) in storage cache.

pub fn set_code(
    &mut self,
    address: &Address,
    code: Vec<u8>
) -> Result<(), Error>
[src]

Set code for an account.

pub fn add_balance(
    &mut self,
    address: &Address,
    incr: U256
) -> Result<(), Error>
[src]

Add balance by incr for an account.

pub fn sub_balance(&mut self, a: &Address, decr: U256) -> Result<(), Error>[src]

Sub balance by decr for an account.

pub fn transfer_balance(
    &mut self,
    from: &Address,
    to: &Address,
    by: U256
) -> Result<(), Error>
[src]

Transfer balance from from to to by by.

pub fn inc_nonce(&mut self, address: &Address) -> Result<(), Error>[src]

Increase nonce for an account.

pub fn commit(&mut self) -> Result<(), Error>[src]

Flush the data from cache to database.

pub fn checkpoint(&mut self) -> usize[src]

Create a recoverable checkpoint of this state. Return the checkpoint index.

pub fn discard_checkpoint(&mut self)[src]

Merge last checkpoint with previous.

pub fn revert_checkpoint(&mut self)[src]

Revert to the last checkpoint and discard it.

Trait Implementations

impl<B: DB> StateObjectInfo for State<B>[src]

Auto Trait Implementations

impl<B> Send for State<B> where
    B: Send

impl<B> !Sync for State<B>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same for T

type Output = T

Should always be Self