Browse Source

setAdress fix for mining.

cl-refactor
Gav Wood 10 years ago
parent
commit
090c892906
  1. 66
      abi/main.cpp
  2. 2
      libethereum/Client.h
  3. 5
      libethereum/ClientBase.cpp
  4. 2
      libethereum/ClientBase.h
  5. 1
      libtestutils/FixedClient.h

66
abi/main.cpp

@ -202,6 +202,20 @@ struct ABIType
return ret;
}
bool isBytes() const { return base == Base::Bytes && !size; }
string render(bytes const& _data) const
{
if (base == Base::Uint)
return toString(fromBigEndian<u256>(_data));
else if (base == Base::Int)
return toString((s256)fromBigEndian<u256>(_data));
else if (base == Base::Address)
return toString(Address(h256(_data)));
else
return toHex(_data);
}
void noteHexInput(unsigned _nibbles) { if (base == Base::Unknown) { if (_nibbles == 40) base = Base::Address; else { base = Base::Bytes; size = _nibbles / 2; } } }
void noteBinaryInput() { if (base == Base::Unknown) { base = Base::Bytes; size = 32; } }
void noteDecimalInput() { if (base == Base::Unknown) { base = Base::Uint; size = 32; } }
@ -341,6 +355,9 @@ struct ABIMethod
bytes encode(vector<pair<bytes, Format>> const& _params) const
{
// ALL WRONG!!!!
// INARITIES SHOULD BE HEIRARCHICAL!
bytes ret = name.empty() ? bytes() : id().asBytes();
unsigned pi = 0;
vector<unsigned> inArity;
@ -356,6 +373,9 @@ struct ABIMethod
}
else
arity *= j;
if (i.isBytes())
for (unsigned i = 0; i < arity; ++i)
inArity.push_back(arity);
}
unsigned ii = 0;
@ -382,6 +402,52 @@ struct ABIMethod
stringstream out;
if (_index == -1)
out << "[";
unsigned di = 0;
vector<ABIType> souts;
vector<unsigned> catDims;
for (ABIType a: outs)
{
unsigned q = 1;
for (auto& i: a.dims)
{
for (unsigned j = 0; j < q; ++j)
if (i == -1)
{
catDims.push_back(fromBigEndian<unsigned>(bytesConstRef(&_data).cropped(di, 32)));
di += 32;
}
q *= i;
}
if (a.isBytes())
souts.push_back(a);
}
for (ABIType const& a: souts)
{
auto put = [&]() {
out << a.render(bytesConstRef(&_data).cropped(di, 32).toBytes()) << ", ";
di += 32;
};
function<void(vector<int>)> putDim = [&](vector<int> addr) {
if (addr.size() == a.dims.size())
put();
else
{
out << "[";
auto d = addr;
addr.push_back(0);
for (addr.back() = 0; addr.back() < a.dims[addr.size() - 1]; ++addr.back())
{
if (addr.back())
out << ", ";
putDim(addr);
}
out << "]";
}
};
putDim(vector<int>());
if (_index == -1)
out << ", ";
}
(void)_data;
if (_index == -1)
out << "]";

2
libethereum/Client.h

@ -171,6 +171,8 @@ public:
// Mining stuff:
void setAddress(Address _us) { WriteGuard l(x_stateDB); m_preMine.setAddress(_us); }
/// Check block validity prior to mining.
bool miningParanoia() const { return m_paranoia; }
/// Change whether we check block validity prior to mining.

5
libethereum/ClientBase.cpp

@ -393,11 +393,6 @@ u256 ClientBase::gasLimitRemaining() const
return postMine().gasLimitRemaining();
}
void ClientBase::setAddress(Address _us)
{
preMine().setAddress(_us);
}
Address ClientBase::address() const
{
return preMine().address();

2
libethereum/ClientBase.h

@ -131,7 +131,7 @@ public:
virtual u256 gasLimitRemaining() const override;
/// Set the coinbase address
virtual void setAddress(Address _us) override;
virtual void setAddress(Address _us) = 0;
/// Get the coinbase address
virtual Address address() const override;

1
libtestutils/FixedClient.h

@ -47,6 +47,7 @@ public:
virtual eth::State asOf(h256 const& _h) const override;
virtual eth::State preMine() const override { ReadGuard l(x_stateDB); return m_state; }
virtual eth::State postMine() const override { ReadGuard l(x_stateDB); return m_state; }
virtual void setAddress(Address _us) { WriteGuard l(x_stateDB); m_state.setAddress(_us); }
virtual void prepareForTransaction() override {}
private:

Loading…
Cancel
Save