31 void Account::setNewCode(
bytes&& _code)
33 m_codeCache = std::move(_code);
35 m_codeHash =
sha3(m_codeCache);
52 auto u256Safe = [](std::string
const& s) ->
u256 {
54 if (ret >=
bigint(1) << 256)
55 BOOST_THROW_EXCEPTION(ValueTooLarge() <<
errinfo_comment(
"State value is equal or greater than 2**256") );
59 std::unordered_map<Address, Account> ret;
64 for (
auto const& account: o.count(
"alloc") ? o[
"alloc"].get_obj() : o.count(
"accounts") ? o[
"accounts"].get_obj() : o)
67 auto o = account.second.get_obj();
69 bool haveBalance = (o.count(
"wei") || o.count(
"finney") || o.count(
"balance"));
70 bool haveNonce = o.count(
"nonce");
71 bool haveCode = o.count(
"code");
72 bool haveStorage = o.count(
"storage");
73 bool shouldNotExists = o.count(
"shouldnotexist");
75 if (haveStorage || haveCode || haveNonce || haveBalance)
79 balance = u256Safe(o[
"wei"].
get_str());
80 else if (o.count(
"finney"))
81 balance = u256Safe(o[
"finney"].
get_str()) * finney;
82 else if (o.count(
"balance"))
83 balance = u256Safe(o[
"balance"].
get_str());
85 u256 nonce = haveNonce ? u256Safe(o[
"nonce"].
get_str()) : _defaultNonce;
92 if (o[
"code"].
get_str().find(
"0x") != 0)
93 cerr <<
"Error importing code of account " << a <<
"! Code needs to be hex bytecode prefixed by \"0x\".";
98 cerr <<
"Error importing code of account " << a <<
"! Code field needs to be a string";
104 for (pair<string, js::mValue>
const& j: o[
"storage"].get_obj())
105 ret[
a].setStorage(
u256(j.first),
u256(j.second.get_str()));
110 (*o_mask)[
a] =
AccountMask(haveBalance, haveNonce, haveCode, haveStorage, shouldNotExists);
111 if (!haveStorage && !haveCode && !haveNonce && !haveBalance && shouldNotExists)
115 if (o_precompiled && o.count(
"precompiled"))
118 auto n = p[
"name"].get_str();
119 if (!p.count(
"linear"))
121 cwarn <<
"No gas cost given for precompiled contract " << n;
126 auto l = p[
"linear"].get_obj();
127 u256 startingBlock = 0;
128 if (p.count(
"startingBlock"))
129 startingBlock =
u256(p[
"startingBlock"].
get_str());
132 o_precompiled->insert(make_pair(a,
PrecompiledContract(base, word, PrecompiledRegistrar::executor(n), startingBlock)));
134 catch (ExecutorNotFound)
137 cwarn <<
"Couldn't create a precompiled contract account. Missing an executor called:" << n;
const Object & get_obj() const
uint64_t toUnsigned(js::mValue const &_v)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::unordered_map< Address, PrecompiledContract > PrecompiledContractMap
std::unordered_map< Address, Account > AccountMap
struct evm_uint256be balance(struct evm_env *env, struct evm_uint160be address)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
Models the state of a single Ethereum account.
boost::uint64_t get_uint64() const
std::hash for asio::adress
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
bool read_string(const String_type &s, Value_type &value)
std::vector< byte > bytes
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
const String_type & get_str() const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
std::unordered_map< Address, AccountMask > AccountMaskMap
mConfig::Object_type mObject
PlatformStyle::TableColorType type
AccountMap jsonToAccountMap(std::string const &_json, u256 const &_defaultNonce=0, AccountMaskMap *o_mask=nullptr, PrecompiledContractMap *o_precompiled=nullptr)
boost::error_info< struct tag_comment, std::string > errinfo_comment
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)