/* This file is part of cpp-ethereum. cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Foobar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Foobar. If not, see . */ /** @file AddressState.h * @author Gav Wood * @date 2014 */ #pragma once #include "Common.h" #include "RLP.h" namespace eth { enum class AddressType { Normal, Contract }; class AddressState { public: AddressState(AddressType _type = AddressType::Normal): m_type(_type), m_balance(0), m_nonce(0) {} AddressType type() const { return m_type; } u256& balance() { return m_balance; } u256 const& balance() const { return m_balance; } u256& nonce() { return m_nonce; } u256 const& nonce() const { return m_nonce; } std::map& memory() { assert(m_type == AddressType::Contract); return m_memory; } std::map const& memory() const { assert(m_type == AddressType::Contract); return m_memory; } u256 memoryHash() const; std::string toString() const { if (m_type == AddressType::Normal) return asString(rlpList(m_balance, toCompactBigEndianString(m_nonce))); if (m_type == AddressType::Contract) return asString(rlpList(m_balance, toCompactBigEndianString(m_nonce), toCompactBigEndianString(memoryHash()))); return ""; } private: AddressType m_type; u256 m_balance; u256 m_nonce; // TODO: std::hash and then move to unordered_map. // Will need to sort on hash construction. std::map m_memory; }; }