Browse Source

Finally! Remove two horrible, nasty, lingering, confusing, hacky calls

in State.
cl-refactor
Gav Wood 10 years ago
parent
commit
a4bf3c645c
  1. 36
      libethereum/ExtVM.cpp
  2. 12
      libethereum/ExtVM.h
  3. 26
      libethereum/State.cpp
  4. 11
      libethereum/State.h

36
libethereum/ExtVM.cpp

@ -21,5 +21,37 @@
#include "ExtVM.h" #include "ExtVM.h"
#pragma GCC diagnostic ignored "-Wunused-variable" #include "Executive.h"
namespace { char dummy; }; using namespace std;
using namespace dev;
using namespace dev::eth;
bool ExtVM::call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256& io_gas, bytesRef _out, OnOpFunc const& _onOp, Address _myAddressOverride, Address _codeAddressOverride)
{
Executive e(m_s, depth + 1);
if (!e.call(_receiveAddress, _codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _txValue, gasPrice, _txData, io_gas, origin))
{
e.go(_onOp);
sub += e.ext().sub;
}
io_gas = e.endGas();
e.out().copyTo(_out);
return !e.excepted();
}
h160 ExtVM::create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc const& _onOp)
{
// Increment associated nonce for sender.
m_s.noteSending(myAddress);
Executive e(m_s, depth + 1);
if (!e.create(myAddress, _endowment, gasPrice, io_gas, _code, origin))
{
e.go(_onOp);
sub += e.ext().sub;
}
io_gas = e.endGas();
return e.newAddress();
}

12
libethereum/ExtVM.h

@ -55,18 +55,10 @@ public:
virtual bytes const& codeAt(Address _a) override final { return m_s.code(_a); } virtual bytes const& codeAt(Address _a) override final { return m_s.code(_a); }
/// Create a new contract. /// Create a new contract.
virtual h160 create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc const& _onOp = {}) override final virtual h160 create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc const& _onOp = {}) override final;
{
// Increment associated nonce for sender.
m_s.noteSending(myAddress);
return m_s.create(myAddress, _endowment, gasPrice, io_gas, _code, origin, sub, _onOp, depth + 1);
}
/// Create a new message call. Leave _myAddressOverride as the default to use the present address as caller. /// Create a new message call. Leave _myAddressOverride as the default to use the present address as caller.
virtual bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256& io_gas, bytesRef _out, OnOpFunc const& _onOp = {}, Address _myAddressOverride = {}, Address _codeAddressOverride = {}) override final virtual bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256& io_gas, bytesRef _out, OnOpFunc const& _onOp = {}, Address _myAddressOverride = {}, Address _codeAddressOverride = {}) override final;
{
return m_s.call(_receiveAddress, _codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _txValue, gasPrice, _txData, io_gas, _out, origin, sub, _onOp, depth + 1);
}
/// Read address's balance. /// Read address's balance.
virtual u256 balance(Address _a) override final { return m_s.balance(_a); } virtual u256 balance(Address _a) override final { return m_s.balance(_a); }

26
libethereum/State.cpp

@ -1174,32 +1174,6 @@ u256 State::execute(bytesConstRef _rlp, bytes* o_output, bool _commit)
return e.gasUsed(); return e.gasUsed();
} }
bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderAddress, u256 _value, u256 _gasPrice, bytesConstRef _data, u256& io_gas, bytesRef _out, Address _originAddress, SubState& io_sub, OnOpFunc const& _onOp, unsigned _level)
{
Executive e(*this, _level);
if (!e.call(_receiveAddress, _codeAddress, _senderAddress, _value, _gasPrice, _data, io_gas, _originAddress))
{
e.go(_onOp);
io_sub += e.ext().sub;
}
io_gas = e.endGas();
e.out().copyTo(_out);
return !e.excepted();
}
h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256& io_gas, bytesConstRef _code, Address _origin, SubState& io_sub, OnOpFunc const& _onOp, unsigned _level)
{
Executive e(*this, _level);
if (!e.create(_sender, _endowment, _gasPrice, io_gas, _code, _origin))
{
e.go(_onOp);
io_sub += e.ext().sub;
}
io_gas = e.endGas();
return e.newAddress();
}
State State::fromPending(unsigned _i) const State State::fromPending(unsigned _i) const
{ {
State ret = *this; State ret = *this;

11
libethereum/State.h

@ -272,17 +272,6 @@ private:
/// Throws on failure. /// Throws on failure.
u256 enact(bytesConstRef _block, BlockChain const* _bc = nullptr, bool _checkNonce = true); u256 enact(bytesConstRef _block, BlockChain const* _bc = nullptr, bool _checkNonce = true);
// Two priviledged entry points for the VM (these don't get added to the Transaction lists):
// We assume all instrinsic fees are paid up before this point.
/// Execute a contract-creation transaction.
h160 create(Address _txSender, u256 _endowment, u256 _gasPrice, u256& io_gas, bytesConstRef _code, Address _originAddress, SubState& io_sub, OnOpFunc const& _onOp, unsigned _level);
/// Execute a call.
/// @a _gas points to the amount of gas to use for the call, and will lower it accordingly.
/// @returns false if the call ran out of gas before completion. true otherwise.
bool call(Address _myAddress, Address _codeAddress, Address _txSender, u256 _txValue, u256 _gasPrice, bytesConstRef _txData, u256& io_gas, bytesRef _out, Address _originAddress, SubState& io_sub, OnOpFunc const& _onOp, unsigned _level);
/// Sets m_currentBlock to a clean state, (i.e. no change from m_previousBlock). /// Sets m_currentBlock to a clean state, (i.e. no change from m_previousBlock).
void resetCurrent(); void resetCurrent();

Loading…
Cancel
Save