Fabcoin Core  0.16.2
P2P Digital Currency
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
dev::eth::Account Class Reference

Models the state of a single Ethereum account. More...

#include <Account.h>

Collaboration diagram for dev::eth::Account:
[legend]

Public Types

enum  Changedness { Changed, Unchanged }
 Changedness of account to create. More...
 

Public Member Functions

 Account ()
 Construct a dead Account. More...
 
 Account (u256 _nonce, u256 _balance, Changedness _c=Changed)
 Construct an alive Account, with given endowment, for either a normal (non-contract) account or for a contract account in the conception phase, where the code is not yet known. More...
 
 Account (u256 _nonce, u256 _balance, h256 _contractRoot, h256 _codeHash, Changedness _c)
 Explicit constructor for wierd cases of construction or a contract account. More...
 
void kill ()
 Kill this account. Useful for the suicide opcode. Following this call, isAlive() returns false. More...
 
bool isAlive () const
 
bool isDirty () const
 
void untouch ()
 
bool isEmpty () const
 
u256 const & balance () const
 
void addBalance (u256 _value)
 Increments the balance of this account by the given amount. More...
 
u256 nonce () const
 
void incNonce ()
 Increment the nonce of the account by one. More...
 
void setNonce (u256 const &_nonce)
 Set nonce to a new value. More...
 
h256 baseRoot () const
 
std::unordered_map< u256, u256 > const & storageOverlay () const
 
void setStorage (u256 _p, u256 _v)
 Set a key/value pair in the account's storage. More...
 
void setStorageCache (u256 _p, u256 _v) const
 Set a key/value pair in the account's storage to a value that is already present inside the database. More...
 
h256 codeHash () const
 
bool hasNewCode () const
 
void setNewCode (bytes &&_code)
 Sets the code of the account. Used by "create" messages. More...
 
void resetCode ()
 Reset the code set by previous CREATE message. More...
 
void noteCode (bytesConstRef _code)
 Specify to the object what the actual code is for the account. More...
 
bytes const & code () const
 

Private Member Functions

void changed ()
 Note that we've altered the account. More...
 

Private Attributes

bool m_isAlive = false
 Is this account existant? If not, it represents a deleted account. More...
 
bool m_isUnchanged = false
 True if we've not made any alteration to the account having been given it's properties directly. More...
 
bool m_hasNewCode = false
 True if new code was deployed to the account. More...
 
u256 m_nonce
 Account's nonce. More...
 
u256 m_balance = 0
 Account's balance. More...
 
h256 m_storageRoot = EmptyTrie
 The base storage root. More...
 
h256 m_codeHash = EmptySHA3
 If c_contractConceptionCodeHash then we're in the limbo where we're running the initialisation code. More...
 
std::unordered_map< u256, u256m_storageOverlay
 The map with is overlaid onto whatever storage is implied by the m_storageRoot in the trie. More...
 
bytes m_codeCache
 The associated code for this account. More...
 

Static Private Attributes

static const h256 c_contractConceptionCodeHash
 Value for m_codeHash when this account is having its code determined. More...
 

Detailed Description

Models the state of a single Ethereum account.

Used to cache a portion of the full Ethereum state. State keeps a mapping of Address's to Accounts.

Aside from storing the nonce and balance, the account may also be "dead" (where isAlive() returns false). This allows State to explicitly store the notion of a deleted account in it's cache. kill() can be used for this.

For the account's storage, the class operates a cache. baseRoot() specifies the base state of the storage given as the Trie root to be looked up in the state database. Alterations beyond this base are specified in the overlay, stored in this class and retrieved with storageOverlay(). setStorage allows the overlay to be altered.

The code handling explicitly supports a two-stage commit model needed for contract-creation. When creating a contract (running the initialisation code), the code of the account is considered empty. The attribute of emptiness can be retrieved with codeBearing(). After initialisation one must set the code accordingly; the code of the Account can be set with setCode(). To validate a setCode() call, this class records the state of being in contract-creation (and thus in a state where setCode may validly be called). It can be determined through isFreshCode().

The code can be retrieved through code(), and its hash through codeHash(). codeHash() is only valid when the account is not in the contract-creation phase (i.e. when isFreshCode() returns false). This class supports populating code on-demand from the state database. To determine if the code has been prepopulated call codeCacheValid(). To populate the code, look it up with codeHash() and populate with noteCode().

Todo:
: need to make a noteCodeCommitted().

The constructor allows you to create an one of a number of "types" of accounts. The default constructor makes a dead account (this is ignored by State when writing out the Trie). Another three allow a basic or contract account to be specified along with an initial balance. The fina two allow either a basic or a contract account to be created with arbitrary values.

Definition at line 67 of file Account.h.

Member Enumeration Documentation

Changedness of account to create.

Enumerator
Changed 

Account starts as though it has been changed.

Unchanged 

Account starts as though it has not been changed.

Definition at line 71 of file Account.h.

Constructor & Destructor Documentation

dev::eth::Account::Account ( )
inline

Construct a dead Account.

Definition at line 80 of file Account.h.

dev::eth::Account::Account ( u256  _nonce,
u256  _balance,
Changedness  _c = Changed 
)
inline

Construct an alive Account, with given endowment, for either a normal (non-contract) account or for a contract account in the conception phase, where the code is not yet known.

Definition at line 85 of file Account.h.

dev::eth::Account::Account ( u256  _nonce,
u256  _balance,
h256  _contractRoot,
h256  _codeHash,
Changedness  _c 
)
inline

Explicit constructor for wierd cases of construction or a contract account.

Definition at line 88 of file Account.h.

Here is the call graph for this function:

Member Function Documentation

void dev::eth::Account::addBalance ( u256  _value)
inline

Increments the balance of this account by the given amount.

Definition at line 112 of file Account.h.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 const& dev::eth::Account::balance ( ) const
inline
Returns
the balance of this account.

Definition at line 109 of file Account.h.

Here is the caller graph for this function:

h256 dev::eth::Account::baseRoot ( ) const
inline
Returns
the root of the trie (whose nodes are stored in the state db externally to this class) which encodes the base-state of the account's storage (upon which the storage is overlaid).

Definition at line 127 of file Account.h.

Here is the call graph for this function:

void dev::eth::Account::changed ( )
inlineprivate

Note that we've altered the account.

Definition at line 160 of file Account.h.

Here is the caller graph for this function:

bytes const& dev::eth::Account::code ( ) const
inline
Returns
the account's code.

Definition at line 156 of file Account.h.

Here is the caller graph for this function:

h256 dev::eth::Account::codeHash ( ) const
inline
Returns
the hash of the account's code.

Definition at line 141 of file Account.h.

Here is the caller graph for this function:

bool dev::eth::Account::hasNewCode ( ) const
inline

Definition at line 143 of file Account.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::Account::incNonce ( )
inline

Increment the nonce of the account by one.

Definition at line 118 of file Account.h.

Here is the call graph for this function:

bool dev::eth::Account::isAlive ( ) const
inline
Returns
true iff this object represents an account in the state. Returns false if this object represents an account that should no longer exist in the trie (an account that never existed or was suicided).

Definition at line 97 of file Account.h.

Here is the caller graph for this function:

bool dev::eth::Account::isDirty ( ) const
inline
Returns
true if the account is unchanged from creation.

Definition at line 100 of file Account.h.

bool dev::eth::Account::isEmpty ( ) const
inline
Returns
true if the nonce, balance and code is zero / empty. Code is considered empty during creation phase.

Definition at line 106 of file Account.h.

Here is the call graph for this function:

void dev::eth::Account::kill ( )
inline

Kill this account. Useful for the suicide opcode. Following this call, isAlive() returns false.

Definition at line 92 of file Account.h.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 dev::eth::Account::nonce ( ) const
inline
Returns
the nonce of the account.

Definition at line 115 of file Account.h.

Here is the caller graph for this function:

void dev::eth::Account::noteCode ( bytesConstRef  _code)
inline

Specify to the object what the actual code is for the account.

_code must have a SHA3 equal to codeHash() and must only be called when isFreshCode() returns false.

Definition at line 153 of file Account.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::Account::resetCode ( )
inline

Reset the code set by previous CREATE message.

Definition at line 149 of file Account.h.

Here is the caller graph for this function:

void Account::setNewCode ( bytes &&  _code)

Sets the code of the account. Used by "create" messages.

Definition at line 31 of file Account.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::Account::setNonce ( u256 const &  _nonce)
inline

Set nonce to a new value.

This is used when reverting changes made to the account.

Definition at line 122 of file Account.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::Account::setStorage ( u256  _p,
u256  _v 
)
inline

Set a key/value pair in the account's storage.

This actually goes into the overlay, for committing to the trie later.

Definition at line 134 of file Account.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::Account::setStorageCache ( u256  _p,
u256  _v 
) const
inline

Set a key/value pair in the account's storage to a value that is already present inside the database.

Definition at line 138 of file Account.h.

std::unordered_map<u256, u256> const& dev::eth::Account::storageOverlay ( ) const
inline
Returns
the storage overlay as a simple hash map.

Definition at line 130 of file Account.h.

Here is the caller graph for this function:

void dev::eth::Account::untouch ( )
inline

Definition at line 102 of file Account.h.

Here is the caller graph for this function:

Member Data Documentation

const h256 dev::eth::Account::c_contractConceptionCodeHash
staticprivate

Value for m_codeHash when this account is having its code determined.

Definition at line 197 of file Account.h.

u256 dev::eth::Account::m_balance = 0
private

Account's balance.

Definition at line 175 of file Account.h.

bytes dev::eth::Account::m_codeCache
private

The associated code for this account.

The SHA3 of this should be equal to m_codeHash unless m_codeHash equals c_contractConceptionCodeHash.

Definition at line 194 of file Account.h.

h256 dev::eth::Account::m_codeHash = EmptySHA3
private

If c_contractConceptionCodeHash then we're in the limbo where we're running the initialisation code.

We expect a setCode() at some point later. If EmptySHA3, then m_code, which should be empty, is valid. If anything else, then m_code is valid iff it's not empty, otherwise, State::ensureCached() needs to be called with the correct args.

Definition at line 187 of file Account.h.

bool dev::eth::Account::m_hasNewCode = false
private

True if new code was deployed to the account.

Definition at line 169 of file Account.h.

bool dev::eth::Account::m_isAlive = false
private

Is this account existant? If not, it represents a deleted account.

Definition at line 163 of file Account.h.

bool dev::eth::Account::m_isUnchanged = false
private

True if we've not made any alteration to the account having been given it's properties directly.

Definition at line 166 of file Account.h.

u256 dev::eth::Account::m_nonce
private

Account's nonce.

Definition at line 172 of file Account.h.

std::unordered_map<u256, u256> dev::eth::Account::m_storageOverlay
private

The map with is overlaid onto whatever storage is implied by the m_storageRoot in the trie.

Definition at line 190 of file Account.h.

h256 dev::eth::Account::m_storageRoot = EmptyTrie
private

The base storage root.

Used with the state DB to give a base to the storage. m_storageOverlay is overlaid on this and takes precedence for all values set.

Definition at line 179 of file Account.h.


The documentation for this class was generated from the following files: