diff --git a/libethereum/AddressState.cpp b/libethereum/Account.cpp
similarity index 94%
rename from libethereum/AddressState.cpp
rename to libethereum/Account.cpp
index 268440314..dcd97f037 100644
--- a/libethereum/AddressState.cpp
+++ b/libethereum/Account.cpp
@@ -14,12 +14,12 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see .
*/
-/** @file AddressState.cpp
+/** @file Account.cpp
* @author Gav Wood
* @date 2014
*/
-#include "AddressState.h"
+#include "Account.h"
#include
using namespace std;
using namespace dev;
diff --git a/libethereum/AddressState.h b/libethereum/Account.h
similarity index 81%
rename from libethereum/AddressState.h
rename to libethereum/Account.h
index 8b4505909..00344a9e6 100644
--- a/libethereum/AddressState.h
+++ b/libethereum/Account.h
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see .
*/
-/** @file AddressState.h
+/** @file Account.h
* @author Gav Wood
* @date 2014
*/
@@ -33,20 +33,20 @@ namespace eth
// TODO: Document fully.
-class AddressState
+class Account
{
public:
enum NewAccountType { NormalCreation, ContractConception };
- /// Construct a dead AddressState.
- AddressState() {}
- /// Construct an alive AddressState, with given endowment, for either a normal (non-contract) account or for a contract account in the
+ /// Construct a dead Account.
+ Account() {}
+ /// 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.
- AddressState(u256 _balance, NewAccountType _t): m_isAlive(true), m_balance(_balance), m_codeHash(_t == NormalCreation ? h256() : EmptySHA3) {}
+ Account(u256 _balance, NewAccountType _t): m_isAlive(true), m_balance(_balance), m_codeHash(_t == NormalCreation ? h256() : EmptySHA3) {}
/// Explicit constructor for wierd cases of construction of a normal account.
- AddressState(u256 _nonce, u256 _balance): m_isAlive(true), m_nonce(_nonce), m_balance(_balance) {}
+ Account(u256 _nonce, u256 _balance): m_isAlive(true), m_nonce(_nonce), m_balance(_balance) {}
/// Explicit constructor for wierd cases of construction or a contract account.
- AddressState(u256 _nonce, u256 _balance, h256 _contractRoot, h256 _codeHash): m_isAlive(true), m_nonce(_nonce), m_balance(_balance), m_storageRoot(_contractRoot), m_codeHash(_codeHash) {}
+ Account(u256 _nonce, u256 _balance, h256 _contractRoot, h256 _codeHash): m_isAlive(true), m_nonce(_nonce), m_balance(_balance), m_storageRoot(_contractRoot), m_codeHash(_codeHash) { assert(_contractRoot); }
void kill() { m_isAlive = false; m_storageOverlay.clear(); m_codeHash = EmptySHA3; m_storageRoot = EmptyTrie; m_balance = 0; m_nonce = 0; }
bool isAlive() const { return m_isAlive; }
@@ -59,7 +59,7 @@ public:
u256 const& nonce() const { return m_nonce; }
void incNonce() { m_nonce++; }
- h256 baseRoot() const { return m_storageRoot; }
+ h256 baseRoot() const { assert(m_storageRoot); return m_storageRoot; }
std::map const& storage() const { return m_storageOverlay; }
void setStorage(u256 _p, u256 _v) { m_storageOverlay[_p] = _v; }
diff --git a/libethereum/All.h b/libethereum/All.h
index ba22640e7..11e0d55f3 100644
--- a/libethereum/All.h
+++ b/libethereum/All.h
@@ -1,6 +1,6 @@
#pragma once
-#include "AddressState.h"
+#include "Account.h"
#include "BlockChain.h"
#include "Client.h"
#include "Defaults.h"
diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp
index 9672f722c..710f17214 100644
--- a/libethereum/BlockChain.cpp
+++ b/libethereum/BlockChain.cpp
@@ -52,9 +52,9 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, BlockChain const& _bc)
return _out;
}
-std::map const& dev::eth::genesisState()
+std::map const& dev::eth::genesisState()
{
- static std::map s_ret;
+ static std::map s_ret;
if (s_ret.empty())
// Initialise.
for (auto i: vector({
@@ -67,7 +67,7 @@ std::map const& dev::eth::genesisState()
"6c386a4b26f73c802f34673f7248bb118f97424a",
"e4157b34ea9615cfbde6b4fda419828124b70c78"
}))
- s_ret[Address(fromHex(i))] = AddressState(u256(1) << 200, AddressState::NormalCreation);
+ s_ret[Address(fromHex(i))] = Account(u256(1) << 200, Account::NormalCreation);
return s_ret;
}
diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h
index 6c96082a5..30f5633c1 100644
--- a/libethereum/BlockChain.h
+++ b/libethereum/BlockChain.h
@@ -33,7 +33,7 @@
#include
#include
#include "BlockDetails.h"
-#include "AddressState.h"
+#include "Account.h"
#include "BlockQueue.h"
namespace ldb = leveldb;
@@ -57,7 +57,7 @@ struct BlockChainChat: public LogChannel { static const char* name() { return "-
struct BlockChainNote: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 4; };
// TODO: Move all this Genesis stuff into Genesis.h/.cpp
-std::map const& genesisState();
+std::map const& genesisState();
ldb::Slice toSlice(h256 _h, unsigned _sub = 0);
diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp
index 5a983b66e..885ab5535 100644
--- a/libethereum/Executive.cpp
+++ b/libethereum/Executive.cpp
@@ -138,7 +138,7 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g
m_newAddress = right160(sha3(rlpList(_sender, m_s.transactionsFrom(_sender) - 1)));
// Set up new account...
- m_s.m_cache[m_newAddress] = AddressState(0, m_s.balance(m_newAddress) + _endowment, h256(), h256());
+ m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress) + _endowment, Account::ContractConception);
// Execute _init.
m_vm = new VM(_gas);
diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h
index 59b6eb2ab..cf80b2352 100644
--- a/libethereum/ExtVM.h
+++ b/libethereum/ExtVM.h
@@ -102,7 +102,7 @@ public:
private:
State& m_s; ///< A reference to the base state.
- std::map m_origCache; ///< The cache of the address states (i.e. the externalities) as-was prior to the execution.
+ std::map m_origCache; ///< The cache of the address states (i.e. the externalities) as-was prior to the execution.
Manifest* m_ms;
};
diff --git a/libethereum/State.cpp b/libethereum/State.cpp
index 183b2b8de..a438622fa 100644
--- a/libethereum/State.cpp
+++ b/libethereum/State.cpp
@@ -224,7 +224,7 @@ Address State::nextActiveAddress(Address _a) const
// TODO: repot
struct CachedAddressState
{
- CachedAddressState(std::string const& _rlp, AddressState const* _s, OverlayDB const* _o): rS(_rlp), r(rS), s(_s), o(_o) {}
+ CachedAddressState(std::string const& _rlp, Account const* _s, OverlayDB const* _o): rS(_rlp), r(rS), s(_s), o(_o) {}
bool exists() const
{
@@ -300,7 +300,7 @@ struct CachedAddressState
std::string rS;
RLP r;
- AddressState const* s;
+ Account const* s;
OverlayDB const* o;
};
@@ -346,7 +346,7 @@ void State::ensureCached(Address _a, bool _requireCode, bool _forceCreate) const
ensureCached(m_cache, _a, _requireCode, _forceCreate);
}
-void State::ensureCached(std::map& _cache, Address _a, bool _requireCode, bool _forceCreate) const
+void State::ensureCached(std::map& _cache, Address _a, bool _requireCode, bool _forceCreate) const
{
auto it = _cache.find(_a);
if (it == _cache.end())
@@ -356,11 +356,11 @@ void State::ensureCached(std::map& _cache, Address _a, bo
if (stateBack.empty() && !_forceCreate)
return;
RLP state(stateBack);
- AddressState s;
+ Account s;
if (state.isNull())
- s = AddressState(0, AddressState::NormalCreation);
+ s = Account(0, Account::NormalCreation);
else
- s = AddressState(state[0].toInt(), state[1].toInt(), state[2].toHash(), state[3].toHash());
+ s = Account(state[0].toInt(), state[1].toInt(), state[2].toHash(), state[3].toHash());
bool ok;
tie(it, ok) = _cache.insert(make_pair(_a, s));
}
@@ -965,7 +965,7 @@ void State::noteSending(Address _id)
{
cwarn << "Sending from non-existant account. How did it pay!?!";
// this is impossible. but we'll continue regardless...
- m_cache[_id] = AddressState(1, 0);
+ m_cache[_id] = Account(1, 0);
}
else
it->second.incNonce();
@@ -976,7 +976,7 @@ void State::addBalance(Address _id, u256 _amount)
ensureCached(_id, false, false);
auto it = m_cache.find(_id);
if (it == m_cache.end())
- m_cache[_id] = AddressState(_amount, AddressState::NormalCreation);
+ m_cache[_id] = Account(_amount, Account::NormalCreation);
else
it->second.addBalance(_amount);
}
@@ -1057,7 +1057,7 @@ h256 State::storageRoot(Address _id) const
RLP r(s);
return r[2].toHash();
}
- return h256();
+ return EmptyTrie;
}
bytes const& State::code(Address _contract) const
@@ -1267,7 +1267,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
Address newAddress = right160(sha3(rlpList(_sender, transactionsFrom(_sender) - 1)));
// Set up new account...
- m_cache[newAddress] = AddressState(balance(newAddress) + _endowment, AddressState::ContractConception);
+ m_cache[newAddress] = Account(balance(newAddress) + _endowment, Account::ContractConception);
// Execute init code.
VM vm(*_gas);
@@ -1366,7 +1366,7 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s)
for (auto i: d)
{
auto it = _s.m_cache.find(i);
- AddressState* cache = it != _s.m_cache.end() ? &it->second : nullptr;
+ Account* cache = it != _s.m_cache.end() ? &it->second : nullptr;
string rlpString = dtr.count(i) ? trie.at(i) : "";
RLP r(rlpString);
assert(cache || r);
diff --git a/libethereum/State.h b/libethereum/State.h
index a90812880..a8c23de84 100644
--- a/libethereum/State.h
+++ b/libethereum/State.h
@@ -33,7 +33,7 @@
#include
#include
#include "TransactionQueue.h"
-#include "AddressState.h"
+#include "Account.h"
#include "Transaction.h"
#include "Executive.h"
#include "AccountDiff.h"
@@ -299,7 +299,7 @@ private:
void ensureCached(Address _a, bool _requireCode, bool _forceCreate) const;
/// Retrieve all information about a given address into a cache.
- void ensureCached(std::map& _cache, Address _a, bool _requireCode, bool _forceCreate) const;
+ void ensureCached(std::map& _cache, Address _a, bool _requireCode, bool _forceCreate) const;
/// Commit all changes waiting in the address cache to the DB.
void commit();
@@ -340,7 +340,7 @@ private:
std::set m_transactionSet; ///< The set of transaction hashes that we've included in the state.
OverlayDB m_lastTx;
- mutable std::map m_cache; ///< Our address cache. This stores the states of each address that has (or at least might have) been changed.
+ mutable std::map m_cache; ///< Our address cache. This stores the states of each address that has (or at least might have) been changed.
BlockInfo m_previousBlock; ///< The previous block's information.
BlockInfo m_currentBlock; ///< The current block's information.
@@ -365,7 +365,7 @@ private:
std::ostream& operator<<(std::ostream& _out, State const& _s);
template
-void commit(std::map const& _cache, DB& _db, TrieDB& _state)
+void commit(std::map const& _cache, DB& _db, TrieDB& _state)
{
for (auto const& i: _cache)
if (!i.second.isAlive())
diff --git a/test/vm.cpp b/test/vm.cpp
index 76ed41a44..617cb95c7 100644
--- a/test/vm.cpp
+++ b/test/vm.cpp
@@ -471,7 +471,7 @@ h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _end
}
// Set up new account...
- m_cache[_newAddress] = AddressState(0, balance(_newAddress) + _endowment, h256(), h256());
+ m_cache[_newAddress] = Account(0, balance(_newAddress) + _endowment, h256(), h256());
// Execute init code.
VM vm(*_gas);