![]() |
Fabcoin Core
0.16.2
P2P Digital Currency
|
Model of an Ethereum state, essentially a facade for the trie. More...
#include <State.h>
Public Types | |
enum | CommitBehaviour { CommitBehaviour::KeepEmptyAccounts, CommitBehaviour::RemoveEmptyAccounts } |
enum | NullType { Null } |
Public Member Functions | |
State (u256 const &_accountStartNonce) | |
Default constructor; creates with a blank database prepopulated with the genesis block. More... | |
State (u256 const &_accountStartNonce, OverlayDB const &_db, BaseState _bs=BaseState::PreExisting) | |
Basic state object from database. More... | |
State (NullType) | |
State (State const &_s) | |
Copy state object. More... | |
State & | operator= (State const &_s) |
Copy state object. More... | |
OverlayDB const & | db () const |
OverlayDB & | db () |
void | populateFrom (AccountMap const &_map) |
Populate the state from the given AccountMap. Just uses dev::eth::commit(). More... | |
std::unordered_map< Address, u256 > | addresses () const |
std::pair< ExecutionResult, TransactionReceipt > | execute (EnvInfo const &_envInfo, SealEngineFace const &_sealEngine, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc()) |
Execute a given transaction. More... | |
bool | addressInUse (Address const &_address) const |
Check if the address is in use. More... | |
bool | accountNonemptyAndExisting (Address const &_address) const |
Check if the account exists in the state and is non empty (nonce > 0 || balance > 0 || code nonempty). More... | |
bool | addressHasCode (Address const &_address) const |
Check if the address contains executable code. More... | |
u256 | balance (Address const &_id) const |
Get an account's balance. More... | |
virtual void | addBalance (Address const &_id, u256 const &_amount) |
Add some amount to balance. More... | |
void | subBalance (Address const &_addr, u256 const &_value) |
Subtract the _value amount from the balance of _addr account. More... | |
virtual void | transferBalance (Address const &_from, Address const &_to, u256 const &_value) |
Transfers "the balance _value between two accounts. More... | |
h256 | storageRoot (Address const &_contract) const |
Get the root of the storage of an account. More... | |
u256 | storage (Address const &_contract, u256 const &_memory) const |
Get the value of a storage position of an account. More... | |
void | setStorage (Address const &_contract, u256 const &_location, u256 const &_value) |
Set the value of a storage position of an account. More... | |
void | createContract (Address const &_address) |
Create a contract at the given address (with unset code and unchanged balance). More... | |
void | setNewCode (Address const &_address, bytes &&_code) |
Sets the code of the account. Must only be called during / after contract creation. More... | |
virtual void | kill (Address _a) |
Delete an account (used for processing suicides). More... | |
std::map< h256, std::pair< u256, u256 > > | storage (Address const &_contract) const |
Get the storage of an account. More... | |
bytes const & | code (Address const &_addr) const |
Get the code of an account. More... | |
h256 | codeHash (Address const &_contract) const |
Get the code hash of an account. More... | |
size_t | codeSize (Address const &_contract) const |
Get the byte-size of the code of an account. More... | |
void | incNonce (Address const &_id) |
Increament the account nonce. More... | |
u256 | getNonce (Address const &_addr) const |
Get the account nonce – the number of transactions it has sent. More... | |
h256 | rootHash () const |
The hash of the root of our state tree. More... | |
void | commit (CommitBehaviour _commitBehaviour) |
Commit all changes waiting in the address cache to the DB. More... | |
void | setRoot (h256 const &_root) |
Resets any uncommitted changes to the cache. More... | |
u256 const & | accountStartNonce () const |
Get the account start nonce. May be required. More... | |
u256 const & | requireAccountStartNonce () const |
void | noteAccountStartNonce (u256 const &_actual) |
size_t | savepoint () const |
Create a savepoint in the state changelog. More... | |
void | rollback (size_t _savepoint) |
Revert all recent changes up to the given _savepoint savepoint. More... | |
virtual | ~State () |
Static Public Member Functions | |
static OverlayDB | openDB (std::string const &_path, h256 const &_genesisHash, WithExisting _we=WithExisting::Trust) |
Open a DB - useful for passing into the constructor & keeping for other states that are necessary. More... | |
Protected Member Functions | |
void | removeEmptyAccounts () |
Turns all "touched" empty accounts into non-alive accounts. More... | |
Account const * | account (Address const &_addr) const |
Account * | account (Address const &_addr) |
void | clearCacheIfTooLarge () const |
Purges non-modified entries in m_cache if it grows too large. More... | |
void | createAccount (Address const &_address, Account const &&_account) |
Protected Attributes | |
OverlayDB | m_db |
Our overlay for the state tree. More... | |
SecureTrieDB< Address, OverlayDB > | m_state |
Our state tree, as an OverlayDB DB. More... | |
std::unordered_map< Address, Account > | m_cache |
Our address cache. This stores the states of each address that has (or at least might have) been changed. More... | |
std::vector< Address > | m_unchangedCacheEntries |
Tracks entries in m_cache that can potentially be purged if it grows too large. More... | |
std::set< Address > | m_nonExistingAccountsCache |
Tracks addresses that are known to not exist. More... | |
AddressHash | m_touched |
Tracks all addresses touched so far. More... | |
u256 | m_accountStartNonce |
std::vector< detail::Change > | m_changeLog |
Friends | |
class | ExtVM |
class | dev::test::ImportTest |
class | dev::test::StateLoader |
class | BlockChain |
std::ostream & | operator<< (std::ostream &_out, State const &_s) |
Model of an Ethereum state, essentially a facade for the trie.
Allows you to query the state of accounts as well as creating and modifying accounts. It has built-in caching for various aspects of the state.
Any atomic change to any account is registered and appended in the changelog. In case some changes must be reverted, the changes are popped from the changelog and undone. For possible atomic changes list
|
strong |
|
inlineexplicit |
|
explicit |
Basic state object from database.
Use the default when you already have a database and you just want to make a State object which uses it. If you have no preexisting database then set BaseState to something other than BaseState::PreExisting in order to prepopulate the Trie.
bool State::accountNonemptyAndExisting | ( | Address const & | _address | ) | const |
|
inline |
InterfaceNotSupported | if compiled without ETH_FATDB. |
Definition at line 220 of file State.cpp.
bool State::addressHasCode | ( | Address const & | _address | ) | const |
bool State::addressInUse | ( | Address const & | _address | ) | const |
|
protected |
Get the code of an account.
Definition at line 423 of file State.cpp.
size_t State::codeSize | ( | Address const & | _contract | ) | const |
void State::commit | ( | CommitBehaviour | _commitBehaviour | ) |
void State::createContract | ( | Address const & | _address | ) |
|
inline |
|
inline |
std::pair< ExecutionResult, TransactionReceipt > State::execute | ( | EnvInfo const & | _envInfo, |
SealEngineFace const & | _sealEngine, | ||
Transaction const & | _t, | ||
Permanence | _p = Permanence::Committed , |
||
OnOpFunc const & | _onOp = OnOpFunc() |
||
) |
void State::incNonce | ( | Address const & | _id | ) |
|
virtual |
void State::noteAccountStartNonce | ( | u256 const & | _actual | ) |
|
static |
void State::populateFrom | ( | AccountMap const & | _map | ) |
Populate the state from the given AccountMap. Just uses dev::eth::commit().
Definition at line 115 of file State.cpp.
|
protected |
u256 const & State::requireAccountStartNonce | ( | ) | const |
void State::rollback | ( | size_t | _savepoint | ) |
|
inline |
size_t State::savepoint | ( | ) | const |
Create a savepoint in the state changelog.
///
Definition at line 475 of file State.cpp.
void State::setRoot | ( | h256 const & | _root | ) |
Subtract the _value
amount from the balance of _addr
account.
NotEnoughCash | if the balance of the account is less than the amount to be subtrackted (also in case the account does not exist). |
Definition at line 311 of file State.cpp.
|
friend |
|
friend |
|
friend |
|
protected |
|
protected |
|
mutableprotected |
|
protected |
|
protected |
|
mutableprotected |