Ethereum  PoC-8
The C++ Implementation of Ethereum
dev::eth::Account Class Reference

#include <Account.h>

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)
 
 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 ()
 
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)
 
h256 baseRoot () const
 
u256 storageValue (u256 const &_key, OverlayDB const &_db) const
 
u256 originalStorageValue (u256 const &_key, OverlayDB const &_db) const
 
std::unordered_map< u256, u256 > const & storageOverlay () const
 
void setStorage (u256 _p, u256 _v)
 
void clearStorage ()
 Empty the storage. Used when a contract is overwritten. More...
 
void setStorageRoot (h256 const &_root)
 Set the storage root. Used when clearStorage() is reverted. More...
 
h256 codeHash () const
 
bool hasNewCode () const
 
void setCode (bytes &&_code)
 Sets the code of the account. Used by "create" messages. More...
 
void noteCode (bytesConstRef _code)
 
bytes const & code () const
 

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 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 56 of file Account.h.

Member Enumeration Documentation

◆ Changedness

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 60 of file Account.h.

Constructor & Destructor Documentation

◆ Account() [1/3]

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

Construct a dead Account.

Definition at line 69 of file Account.h.

◆ Account() [2/3]

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 74 of file Account.h.

◆ Account() [3/3]

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 77 of file Account.h.

Member Function Documentation

◆ addBalance()

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.

◆ balance()

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

Definition at line 109 of file Account.h.

◆ baseRoot()

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 126 of file Account.h.

◆ clearStorage()

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

Empty the storage. Used when a contract is overwritten.

Definition at line 151 of file Account.h.

◆ code()

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

Definition at line 181 of file Account.h.

◆ codeHash()

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

Definition at line 169 of file Account.h.

◆ hasNewCode()

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

Definition at line 171 of file Account.h.

◆ incNonce()

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

Increment the nonce of the account by one.

Definition at line 118 of file Account.h.

◆ isAlive()

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.

◆ isDirty()

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

Definition at line 100 of file Account.h.

◆ isEmpty()

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.

◆ kill()

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

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

Definition at line 82 of file Account.h.

◆ nonce()

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

Definition at line 115 of file Account.h.

◆ noteCode()

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().

Definition at line 178 of file Account.h.

◆ originalStorageValue()

u256 Account::originalStorageValue ( u256 const &  _key,
OverlayDB const &  _db 
) const
Returns
account's original storage value corresponding to the @_key not taking into account overlayed modifications

Definition at line 44 of file Account.cpp.

◆ setCode()

void Account::setCode ( bytes &&  _code)

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

Definition at line 37 of file Account.cpp.

◆ setNonce()

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.

◆ setStorage()

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 148 of file Account.h.

◆ setStorageRoot()

void dev::eth::Account::setStorageRoot ( h256 const &  _root)
inline

Set the storage root. Used when clearStorage() is reverted.

Definition at line 160 of file Account.h.

◆ storageOverlay()

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

Definition at line 144 of file Account.h.

◆ storageValue()

u256 dev::eth::Account::storageValue ( u256 const &  _key,
OverlayDB const &  _db 
) const
inline
Returns
account's storage value corresponding to the @_key taking into account overlayed modifications

Definition at line 130 of file Account.h.

◆ untouch()

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

Definition at line 102 of file Account.h.


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