StateObject

Struct StateObject 

Source
pub struct StateObject {
    pub balance: U256,
    pub nonce: U256,
    pub storage_root: H256,
    pub code_hash: H256,
    pub code: Vec<u8>,
    pub code_size: usize,
    pub code_state: CodeState,
    pub storage_changes: HashMap<H256, H256>,
}

Fields§

§balance: U256§nonce: U256§storage_root: H256§code_hash: H256§code: Vec<u8>§code_size: usize§code_state: CodeState§storage_changes: HashMap<H256, H256>

Implementations§

Source§

impl StateObject

Source

pub fn new(balance: U256, nonce: U256) -> StateObject

Create a new account. Note: If contract account generated, make sure you use init_code on this before commiting.

Source

pub fn from_rlp(data: &[u8]) -> Result<StateObject, Error>

Create a new account from rlp bytes. Note: make sure you use read_code after this.

Source

pub fn account(&self) -> Account

Get the account from state object.

Source

pub fn rlp(&self) -> Vec<u8>

Get the rlp data.

Source

pub fn is_empty(&self) -> bool

Function is_empty returns whether the given account is empty. Empty is defined according to EIP161 (balance = nonce = code = 0).

Source

pub fn init_code(&mut self, code: Vec<u8>)

Init the code by given data.

Source

pub fn read_code<B: DB>(&mut self, db: Arc<B>) -> Result<(), Error>

Read the code from database by it’s codehash.

Source

pub fn inc_nonce(&mut self)

Add nonce by 1.

Source

pub fn add_balance(&mut self, x: U256)

Add balance. Note: overflowing is not allowed.

Source

pub fn sub_balance(&mut self, x: U256)

Sub balance. Note: overflowing is not allowed.

Source

pub fn set_storage(&mut self, key: H256, value: H256)

Set (key, value) in storage cache.

Source

pub fn get_storage_at_backend<B: DB>( &self, db: Arc<B>, key: &H256, ) -> Result<Option<H256>, Error>

Get value by key from database.

Source

pub fn get_storage_at_changes(&self, key: &H256) -> Option<H256>

Get value by key from storage cache.

Source

pub fn get_storage<B: DB>( &self, db: Arc<B>, key: &H256, ) -> Result<Option<H256>, Error>

Get value by key.

Source

pub fn get_storage_proof<B: DB>( &self, db: Arc<B>, key: &H256, ) -> Result<Vec<Vec<u8>>, Error>

Get storage proof

Source

pub fn commit_storage<B: DB>(&mut self, db: Arc<B>) -> Result<(), Error>

Flush data in storage cache to database.

Source

pub fn commit_code<B: DB>(&mut self, db: Arc<B>) -> Result<(), Error>

Flush code to database if necessary.

Source

pub fn clone_clean(&self) -> StateObject

Clone without storage changes.

Source

pub fn clone_dirty(&self) -> StateObject

Clone with storage changes.

Source

pub fn merge(&mut self, other: StateObject)

Merge with others.

Trait Implementations§

Source§

impl Clone for StateObject

Source§

fn clone(&self) -> StateObject

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StateObject

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<Account> for StateObject

Source§

fn from(account: Account) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.