![]() |
Fabcoin Core
0.16.2
P2P Digital Currency
|
Models the state of a single Ethereum account. More...
#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) | |
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, u256 > | m_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... | |
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().
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.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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.
|
inline |
void Account::setNewCode | ( | bytes && | _code | ) |
Sets the code of the account. Used by "create" messages.
Definition at line 31 of file Account.cpp.
|
inline |
|
inline |
|
staticprivate |
|
private |
|
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.
|
private |
|
private |
|
private |