diff --git a/abi/main.cpp b/abi/main.cpp index 22233f1f0..e895152cc 100644 --- a/abi/main.cpp +++ b/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(_data)); + else if (base == Base::Int) + return toString((s256)fromBigEndian(_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> const& _params) const { + // ALL WRONG!!!! + // INARITIES SHOULD BE HEIRARCHICAL! + bytes ret = name.empty() ? bytes() : id().asBytes(); unsigned pi = 0; vector 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 souts; + vector 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(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)> putDim = [&](vector 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()); + if (_index == -1) + out << ", "; + } (void)_data; if (_index == -1) out << "]"; diff --git a/libethereum/Client.h b/libethereum/Client.h index 013f797b4..5fb30b8f0 100644 --- a/libethereum/Client.h +++ b/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. diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index de3249991..df30595b6 100644 --- a/libethereum/ClientBase.cpp +++ b/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(); diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index ba4f9e0c4..557b08818 100644 --- a/libethereum/ClientBase.h +++ b/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; diff --git a/libtestutils/FixedClient.h b/libtestutils/FixedClient.h index daca444fb..95acc3edb 100644 --- a/libtestutils/FixedClient.h +++ b/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: