pub struct Account { /* private fields */ }
Expand description
Single account in the system.
Keeps track of changes to the code and storage.
The changes are applied in commit_storage
and commit_code
Implementations
sourceimpl Account
impl Account
sourcepub fn from_pod(pod: PodAccount) -> Account
pub fn from_pod(pod: PodAccount) -> Account
General constructor.
sourcepub fn new_basic(balance: U256, nonce: U256) -> Account
pub fn new_basic(balance: U256, nonce: U256) -> Account
Create a new account with the given balance.
sourcepub fn new_contract(
balance: U256,
nonce: U256,
original_storage_root: H256
) -> Account
pub fn new_contract(
balance: U256,
nonce: U256,
original_storage_root: H256
) -> Account
Create a new contract account.
NOTE: make sure you use init_code
on this before commit
ing.
sourcepub fn init_code(&mut self, code: Bytes)
pub fn init_code(&mut self, code: Bytes)
Set this account’s code to the given code.
NOTE: Account should have been created with new_contract()
sourcepub fn reset_code(&mut self, code: Bytes)
pub fn reset_code(&mut self, code: Bytes)
Reset this account’s code to the given code.
sourcepub fn reset_code_and_storage(
&mut self,
code: Arc<Bytes>,
storage: HashMap<H256, H256>
)
pub fn reset_code_and_storage(
&mut self,
code: Arc<Bytes>,
storage: HashMap<H256, H256>
)
Reset this account’s code and storage to given values.
sourcepub fn set_storage(&mut self, key: H256, value: H256)
pub fn set_storage(&mut self, key: H256, value: H256)
Set (and cache) the contents of the trie’s storage at key
to value
.
sourcepub fn storage_at(
&self,
db: &dyn HashDB<KeccakHasher, DBValue>,
key: &H256
) -> TrieResult<H256>
pub fn storage_at(
&self,
db: &dyn HashDB<KeccakHasher, DBValue>,
key: &H256
) -> TrieResult<H256>
Get (and cache) the contents of the trie’s storage at key
.
Takes modified storage into account.
sourcepub fn original_storage_at(
&self,
db: &dyn HashDB<KeccakHasher, DBValue>,
key: &H256
) -> TrieResult<H256>
pub fn original_storage_at(
&self,
db: &dyn HashDB<KeccakHasher, DBValue>,
key: &H256
) -> TrieResult<H256>
Get (and cache) the contents of the trie’s storage at key
.
Does not take modified storage into account.
sourcepub fn cached_storage_at(&self, key: &H256) -> Option<H256>
pub fn cached_storage_at(&self, key: &H256) -> Option<H256>
Get cached storage value if any. Returns None
if the
key is not in the cache.
sourcepub fn cached_original_storage_at(&self, key: &H256) -> Option<H256>
pub fn cached_original_storage_at(&self, key: &H256) -> Option<H256>
Get cached original storage value after last state commitment. Returns None
if the key is not in the cache.
sourcepub fn address_hash(&self, address: &Address) -> H256
pub fn address_hash(&self, address: &Address) -> H256
return and cache keccak(address)
, address
must be the address of this
account.
sourcepub fn code(&self) -> Option<Arc<Bytes>>
pub fn code(&self) -> Option<Arc<Bytes>>
returns the account’s code. If None
then the code cache isn’t available -
get someone who knows to call note_code
.
sourcepub fn code_size(&self) -> Option<usize>
pub fn code_size(&self) -> Option<usize>
returns the account’s code size. If None
then the code cache or code size cache isn’t available -
get someone who knows to call note_code
.
sourcepub fn cache_code(
&mut self,
db: &dyn HashDB<KeccakHasher, DBValue>
) -> Option<Arc<Bytes>>
pub fn cache_code(
&mut self,
db: &dyn HashDB<KeccakHasher, DBValue>
) -> Option<Arc<Bytes>>
Provide a database to get code_hash
. Should not be called if it is a contract without code. Returns the cached code, if successful.
sourcepub fn cache_given_code(&mut self, code: Arc<Bytes>)
pub fn cache_given_code(&mut self, code: Arc<Bytes>)
Provide code to cache. For correctness, should be the correct code for the account.
sourcepub fn cache_code_size(
&mut self,
db: &dyn HashDB<KeccakHasher, DBValue>
) -> bool
pub fn cache_code_size(
&mut self,
db: &dyn HashDB<KeccakHasher, DBValue>
) -> bool
Provide a database to get code_size
. Should not be called if it is a contract without code. Returns whether
the cache succeeds.
sourcepub fn storage_is_clean(&self) -> bool
pub fn storage_is_clean(&self) -> bool
Determine whether there are any un-commit()
-ed storage-setting operations.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if account has zero nonce, balance, no code and no storage.
NOTE: Will panic if !self.storage_is_clean()
sourcepub fn storage_root(&self) -> Option<H256>
pub fn storage_root(&self) -> Option<H256>
Return the storage root associated with this account or None if it has been altered via the overlay.
sourcepub fn original_storage_root(&self) -> H256
pub fn original_storage_root(&self) -> H256
Return the original storage root of this account.
sourcepub fn is_base_storage_root_unchanged(&self) -> bool
pub fn is_base_storage_root_unchanged(&self) -> bool
Whether the base storage root of this account is unchanged.
sourcepub fn base_storage_root(&self) -> H256
pub fn base_storage_root(&self) -> H256
Storage root where the account changes are based upon.
sourcepub fn storage_changes(&self) -> &HashMap<H256, H256>
pub fn storage_changes(&self) -> &HashMap<H256, H256>
Return the storage overlay.
sourcepub fn add_balance(&mut self, x: &U256)
pub fn add_balance(&mut self, x: &U256)
Increase account balance.
sourcepub fn sub_balance(&mut self, x: &U256)
pub fn sub_balance(&mut self, x: &U256)
Decrease account balance.
Panics if balance is less than x
sourcepub fn commit_storage(
&mut self,
trie_factory: &TrieFactory,
db: &mut dyn HashDB<KeccakHasher, DBValue>
) -> TrieResult<()>
pub fn commit_storage(
&mut self,
trie_factory: &TrieFactory,
db: &mut dyn HashDB<KeccakHasher, DBValue>
) -> TrieResult<()>
Commit the storage_changes
to the backing DB and update storage_root
.
sourcepub fn commit_code(&mut self, db: &mut dyn HashDB<KeccakHasher, DBValue>)
pub fn commit_code(&mut self, db: &mut dyn HashDB<KeccakHasher, DBValue>)
Commit any unsaved code. code_hash
will always return the hash of the code_cache
after this.
sourcepub fn clone_basic(&self) -> Account
pub fn clone_basic(&self) -> Account
Clone basic account data
sourcepub fn clone_dirty(&self) -> Account
pub fn clone_dirty(&self) -> Account
Clone account data and dirty storage keys
sourcepub fn clone_all(&self) -> Account
pub fn clone_all(&self) -> Account
Clone account data, dirty storage keys and cached storage keys.
sourcepub fn overwrite_with(&mut self, other: Account)
pub fn overwrite_with(&mut self, other: Account)
Replace self with the data from other account merging storage cache. Basic account data and all modifications are overwritten with new values.
sourceimpl Account
impl Account
sourcepub fn prove_storage(
&self,
db: &dyn HashDB<KeccakHasher, DBValue>,
storage_key: H256
) -> TrieResult<(Vec<Bytes>, H256)>
pub fn prove_storage(
&self,
db: &dyn HashDB<KeccakHasher, DBValue>,
storage_key: H256
) -> TrieResult<(Vec<Bytes>, H256)>
Prove a storage key’s existence or nonexistence in the account’s storage
trie.
storage_key
is the hash of the desired storage key, meaning
this will only work correctly under a secure trie.
Trait Implementations
sourceimpl From<BasicAccount> for Account
impl From<BasicAccount> for Account
sourcefn from(basic: BasicAccount) -> Self
fn from(basic: BasicAccount) -> Self
Performs the conversion.
Auto Trait Implementations
impl !RefUnwindSafe for Account
impl Send for Account
impl !Sync for Account
impl Unpin for Account
impl UnwindSafe for Account
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more