25 #include <unordered_map> 43 namespace test {
class ImportTest;
class StateLoader; }
54 using errinfo_now = boost::error_info<struct tag_now, unsigned>;
136 kind(_kind), address(_addr), value(_value)
141 kind(Storage), address(_addr), value(_value), key(_key)
165 friend class dev::test::StateLoader;
204 std::unordered_map<Address, u256> addresses()
const;
211 bool addressInUse(
Address const& _address)
const;
215 bool accountNonemptyAndExisting(
Address const& _address)
const;
218 bool addressHasCode(
Address const& _address)
const;
227 virtual void addBalance(
Address const& _id,
u256 const& _amount);
232 void subBalance(
Address const& _addr,
u256 const& _value);
250 void setStorage(
Address const& _contract,
u256 const& _location,
u256 const& _value);
253 void createContract(
Address const& _address);
256 void setNewCode(
Address const& _address,
bytes&& _code);
264 std::map<h256, std::pair<u256, u256>> storage(
Address const& _contract)
const;
278 size_t codeSize(
Address const& _contract)
const;
281 void incNonce(
Address const& _id);
295 void setRoot(
h256 const& _root);
299 u256 const& requireAccountStartNonce()
const;
300 void noteAccountStartNonce(
u256 const& _actual);
304 size_t savepoint()
const;
307 void rollback(
size_t _savepoint);
314 void removeEmptyAccounts();
325 void clearCacheIfTooLarge()
const;
327 void createAccount(
Address const& _address,
Account const&& _account);
331 mutable std::unordered_map<Address, Account>
m_cache;
348 for (
auto const& i: _cache)
349 if (i.second.isDirty())
351 if (!i.second.isAlive())
356 s << i.second.nonce() << i.second.balance();
358 if (i.second.storageOverlay().empty())
360 assert(i.second.baseRoot());
361 s.
append(i.second.baseRoot());
366 for (
auto const& j: i.second.storageOverlay())
368 storageDB.
insert(j.first,
rlp(j.second));
370 storageDB.remove(j.first);
372 s.
append(storageDB.root());
375 if (i.second.hasNewCode())
377 h256 ch = i.second.codeHash();
379 CodeSizeCache::instance().store(ch, i.second.code().
size());
380 _state.db()->
insert(ch, &i.second.code());
384 s << i.second.codeHash();
State(u256 const &_accountStartNonce)
Default constructor; creates with a blank database prepopulated with the genesis block.
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
boost::error_info< struct tag_block, bytes > errinfo_block
boost::error_info< struct tag_unclesExcluded, h256Hash > errinfo_unclesExcluded
std::function< void(uint64_t, uint64_t, dev::eth::Instruction, dev::bigint, dev::bigint, dev::bigint, dev::eth::VM *, dev::eth::ExtVMFace const *)> OnOpFunc
A queue of Transactions, each stored as RLP.
boost::error_info< struct tag_receipts, std::vector< bytes >> errinfo_receipts
std::unordered_map< Address, Account > AccountMap
struct evm_uint256be balance(struct evm_env *env, struct evm_uint160be address)
boost::error_info< struct tag_uncleIndex, unsigned > errinfo_uncleIndex
Implements the blockchain database.
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
RLPStream & append(unsigned _s)
Append given datum to the byte stream.
Models the state of a single Ethereum account.
bytes const & out() const
Read the byte stream.
u256 key
Storage key. Last because used only in one case.
boost::error_info< struct tag_transaction, bytes > errinfo_transaction
boost::error_info< struct tag_currentNumber, u256 > errinfo_currentNumber
u256 const & accountStartNonce() const
Get the account start nonce. May be required.
Change(Address const &_addr, u256 const &_key, u256 const &_value)
Helper constructor especially for storage change log.
assert(len-trim+(2 *lenIndices)<=WIDTH)
Different view on a GenericTrieDB that can use different key types.
AddressHash m_touched
Tracks all addresses touched so far.
Model of an Ethereum state, essentially a facade for the trie.
OverlayDB const & db() const
u256 value
Change value, e.g. balance, storage.
boost::error_info< struct tag_phase, unsigned > errinfo_phase
New code was added to an account (by "create" message execution).
Account nonce was increased by 1.
Kind kind
The kind of the change.
Change(Kind _kind, Address const &_addr, u256 const &_value=0)
Helper constructor to make change log update more readable.
void insert(KeyType _k, bytesConstRef _value)
std::vector< detail::Change > m_changeLog
std::vector< byte > bytes
boost::error_info< struct tag_vmtrace, std::string > errinfo_vmtrace
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VM *, ExtVMFace const *)> OnOpFunc
Account storage was modified.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
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 chan...
boost::error_info< struct tag_required_LogBloom, LogBloom > errinfo_required_LogBloom
Encodes a transaction, ready to be exported to or freshly imported from RLP.
h256 rootHash() const
The hash of the root of our state tree.
DEV_SIMPLE_EXCEPTION(BadHexCharacter)
SecureTrieDB< Address, OverlayDB > m_state
Our state tree, as an OverlayDB DB.
std::vector< Address > m_unchangedCacheEntries
Tracks entries in m_cache that can potentially be purged if it grows too large.
Verified block info, does not hold block data, but a reference instead.
virtual void transferBalance(Address const &_from, Address const &_to, u256 const &_value)
Transfers "the balance _value between two accounts.
boost::error_info< struct tag_now, unsigned > errinfo_now
OverlayDB m_db
Our overlay for the state tree.
Externality interface for the Virtual Machine providing access to world state.
The default logging channels.
boost::error_info< struct tag_transactionIndex, unsigned > errinfo_transactionIndex
AddressHash commit(AccountMap const &_cache, SecureTrieDB< Address, DB > &_state)
An atomic state changelog entry.
boost::error_info< struct tag_uncleNumber, u256 > errinfo_uncleNumber
uint32_t ch(uint32_t x, uint32_t y, uint32_t z)
Class for writing to an RLP bytestream.
std::set< Address > m_nonExistingAccountsCache
Tracks addresses that are known to not exist.
std::ostream & operator<<(std::ostream &out, Stats::clock::duration const &d)
boost::error_info< struct tag_get_LogBloom, LogBloom > errinfo_got_LogBloom
Account was created (it was not existing before).
Address address
Changed account address.
boost::tuple< errinfo_required_LogBloom, errinfo_got_LogBloom > LogBloomRequirementError
std::unordered_set< h160 > AddressHash
A hash set of Ethereum addresses.