Gav Wood
10 years ago
6 changed files with 177 additions and 105 deletions
@ -0,0 +1,77 @@ |
|||||
|
/*
|
||||
|
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. |
||||
|
|
||||
|
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/** @file AccountDiff.cpp
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2014 |
||||
|
*/ |
||||
|
|
||||
|
#include "AccountDiff.h" |
||||
|
|
||||
|
#include <libethential/CommonIO.h> |
||||
|
using namespace std; |
||||
|
using namespace eth; |
||||
|
|
||||
|
AccountChange AccountDiff::changeType() const |
||||
|
{ |
||||
|
bool bn = (balance || nonce); |
||||
|
bool sc = (!storage.empty() || code); |
||||
|
return exist ? exist.from() ? AccountChange::Deletion : AccountChange::Creation : (bn && sc) ? AccountChange::All : bn ? AccountChange::Intrinsic: sc ? AccountChange::CodeStorage : AccountChange::None; |
||||
|
} |
||||
|
|
||||
|
char const* AccountDiff::lead() const |
||||
|
{ |
||||
|
bool bn = (balance || nonce); |
||||
|
bool sc = (!storage.empty() || code); |
||||
|
return exist ? exist.from() ? "XXX" : "+++" : (bn && sc) ? "***" : bn ? " * " : sc ? "* *" : " "; |
||||
|
} |
||||
|
|
||||
|
std::ostream& eth::operator<<(std::ostream& _out, AccountDiff const& _s) |
||||
|
{ |
||||
|
if (!_s.exist.to()) |
||||
|
return _out; |
||||
|
|
||||
|
if (_s.nonce) |
||||
|
{ |
||||
|
_out << std::dec << "#" << _s.nonce.to() << " "; |
||||
|
if (_s.nonce.from()) |
||||
|
_out << "(" << std::showpos << (((bigint)_s.nonce.to()) - ((bigint)_s.nonce.from())) << std::noshowpos << ") "; |
||||
|
} |
||||
|
if (_s.balance) |
||||
|
{ |
||||
|
_out << std::dec << _s.balance.to() << " "; |
||||
|
if (_s.balance.from()) |
||||
|
_out << "(" << std::showpos << (((bigint)_s.balance.to()) - ((bigint)_s.balance.from())) << std::noshowpos << ") "; |
||||
|
} |
||||
|
if (_s.code) |
||||
|
_out << "$" << std::hex << nouppercase << _s.code.to() << " (" << _s.code.from() << ") "; |
||||
|
for (pair<u256, Diff<u256>> const& i: _s.storage) |
||||
|
if (!i.second.from()) |
||||
|
_out << endl << " + " << (h256)i.first << ": " << std::hex << nouppercase << i.second.to(); |
||||
|
else if (!i.second.to()) |
||||
|
_out << endl << "XXX " << (h256)i.first << " (" << std::hex << nouppercase << i.second.from() << ")"; |
||||
|
else |
||||
|
_out << endl << " * " << (h256)i.first << ": " << std::hex << nouppercase << i.second.to() << " (" << i.second.from() << ")"; |
||||
|
return _out; |
||||
|
} |
||||
|
|
||||
|
std::ostream& eth::operator<<(std::ostream& _out, StateDiff const& _s) |
||||
|
{ |
||||
|
_out << _s.accounts.size() << " accounts changed:" << endl; |
||||
|
for (auto const& i: _s.accounts) |
||||
|
_out << i.second.lead() << " " << i.first << ": " << i.second << endl; |
||||
|
return _out; |
||||
|
} |
@ -0,0 +1,73 @@ |
|||||
|
/*
|
||||
|
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. |
||||
|
|
||||
|
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/** @file AccountDiff.h
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2014 |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <libethential/Common.h> |
||||
|
#include <libethcore/CommonEth.h> |
||||
|
|
||||
|
namespace eth |
||||
|
{ |
||||
|
|
||||
|
enum class ExistDiff { Same, New, Dead }; |
||||
|
template <class T> |
||||
|
class Diff |
||||
|
{ |
||||
|
public: |
||||
|
Diff() {} |
||||
|
Diff(T _from, T _to): m_from(_from), m_to(_to) {} |
||||
|
|
||||
|
T const& from() const { return m_from; } |
||||
|
T const& to() const { return m_to; } |
||||
|
|
||||
|
explicit operator bool() const { return m_from != m_to; } |
||||
|
|
||||
|
private: |
||||
|
T m_from; |
||||
|
T m_to; |
||||
|
}; |
||||
|
|
||||
|
enum class AccountChange { None, Creation, Deletion, Intrinsic, CodeStorage, All }; |
||||
|
|
||||
|
struct AccountDiff |
||||
|
{ |
||||
|
inline bool changed() const { return storage.size() || code || nonce || balance || exist; } |
||||
|
char const* lead() const; |
||||
|
AccountChange changeType() const; |
||||
|
|
||||
|
Diff<bool> exist; |
||||
|
Diff<u256> balance; |
||||
|
Diff<u256> nonce; |
||||
|
std::map<u256, Diff<u256>> storage; |
||||
|
Diff<bytes> code; |
||||
|
}; |
||||
|
|
||||
|
struct StateDiff |
||||
|
{ |
||||
|
std::map<Address, AccountDiff> accounts; |
||||
|
}; |
||||
|
|
||||
|
std::ostream& operator<<(std::ostream& _out, StateDiff const& _s); |
||||
|
std::ostream& operator<<(std::ostream& _out, AccountDiff const& _s); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
Loading…
Reference in new issue