[−][src]Struct cita_state::State
State is the one who managers all accounts and states in Ethereum's system.
Fields
db: B
root: H256
cache: 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]
&mut self,
contract: &Address,
balance: U256,
nonce: U256,
code: Vec<u8>
) -> StateObject
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]
&mut self,
address: &Address
) -> Result<Option<StateObject>, Error>
Get state object.
pub fn get_state_object_or_default(
&mut self,
address: &Address
) -> Result<StateObject, Error>
[src]
&mut self,
address: &Address
) -> Result<StateObject, Error>
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]
&mut self,
address: &Address,
key: H256,
value: H256
) -> Result<(), Error>
Set (key, value) in storage cache.
pub fn set_code(
&mut self,
address: &Address,
code: Vec<u8>
) -> Result<(), Error>
[src]
&mut self,
address: &Address,
code: Vec<u8>
) -> Result<(), Error>
Set code for an account.
pub fn add_balance(
&mut self,
address: &Address,
incr: U256
) -> Result<(), Error>
[src]
&mut self,
address: &Address,
incr: U256
) -> Result<(), Error>
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]
&mut self,
from: &Address,
to: &Address,
by: U256
) -> Result<(), Error>
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]
fn nonce(&mut self, a: &Address) -> Result<U256, Error>
[src]
fn balance(&mut self, a: &Address) -> Result<U256, Error>
[src]
fn get_storage(&mut self, a: &Address, key: &H256) -> Result<H256, Error>
[src]
fn code(&mut self, a: &Address) -> Result<Vec<u8>, Error>
[src]
fn code_hash(&mut self, a: &Address) -> Result<H256, Error>
[src]
fn code_size(&mut self, a: &Address) -> Result<usize, Error>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same for T
type Output = T
Should always be Self