Browse Source

Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop

cl-refactor
Gav Wood 10 years ago
parent
commit
e56a00d01c
  1. 10
      alethzero/Debugger.cpp
  2. 4
      libdevcore/CommonData.h
  3. 2
      mix/ContractCallDataEncoder.cpp

10
alethzero/Debugger.cpp

@ -246,8 +246,10 @@ void Debugger::update()
ss << dec << "STEP: " << ws.steps << " | PC: 0x" << hex << ws.curPC << " : " << instructionInfo(ws.inst).name << " | ADDMEM: " << dec << ws.newMemSize << " words | COST: " << dec << ws.gasCost << " | GAS: " << dec << ws.gas;
ui->debugStateInfo->setText(QString::fromStdString(ss.str()));
stringstream s;
for (auto const& i: ws.storage)
s << "@" << m_context->prettyU256(i.first) << "&nbsp;&nbsp;&nbsp;&nbsp;" << m_context->prettyU256(i.second) << "<br/>";
auto keys = dev::keysOf(ws.storage);
sort(keys.begin(), keys.end());
for (auto const& key: keys)
s << "@" << m_context->prettyU256(key) << "&nbsp;&nbsp;&nbsp;&nbsp;" << m_context->prettyU256(ws.storage.at(key)) << "<br/>";
ui->debugStorage->setHtml(QString::fromStdString(s.str()));
}
}
@ -346,7 +348,7 @@ void Debugger::on_dump_clicked()
ofstream f(fn.toStdString());
if (f.is_open())
for (WorldState const& ws: m_session.history)
f << ws.cur << " " << hex << toHex(dev::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)ws.inst, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl;
f << ws.cur << " " << hex << toHex(dev::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(dev::toCompactBigEndian((unsigned)(byte)ws.inst, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl;
}
void Debugger::on_dumpPretty_clicked()
@ -377,6 +379,6 @@ void Debugger::on_dumpStorage_clicked()
if (ws.inst == Instruction::STOP || ws.inst == Instruction::RETURN || ws.inst == Instruction::SUICIDE)
for (auto i: ws.storage)
f << toHex(dev::toCompactBigEndian(i.first, 1)) << " " << toHex(dev::toCompactBigEndian(i.second, 1)) << endl;
f << ws.cur << " " << hex << toHex(dev::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)ws.inst, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl;
f << ws.cur << " " << hex << toHex(dev::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(dev::toCompactBigEndian((unsigned)(byte)ws.inst, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl;
}
}

4
libdevcore/CommonData.h

@ -104,6 +104,7 @@ bytes asNibbles(bytesConstRef const& _s);
template <class T, class Out>
inline void toBigEndian(T _val, Out& o_out)
{
static_assert(std::is_same<bigint, T>::value || !std::numeric_limits<T>::is_signed, "only unsigned types or bigint supported"); //bigint does not carry sign bit on shift
for (auto i = o_out.size(); i != 0; _val >>= 8, i--)
{
T v = _val & (T)0xff;
@ -134,6 +135,7 @@ inline bytes toBigEndian(u160 _val) { bytes ret(20); toBigEndian(_val, ret); ret
template <class T>
inline bytes toCompactBigEndian(T _val, unsigned _min = 0)
{
static_assert(std::is_same<bigint, T>::value || !std::numeric_limits<T>::is_signed, "only unsigned types or bigint supported"); //bigint does not carry sign bit on shift
int i = 0;
for (T v = _val; v; ++i, v >>= 8) {}
bytes ret(std::max<unsigned>(_min, i), 0);
@ -150,6 +152,7 @@ inline bytes toCompactBigEndian(byte _val, unsigned _min = 0)
template <class T>
inline std::string toCompactBigEndianString(T _val, unsigned _min = 0)
{
static_assert(std::is_same<bigint, T>::value || !std::numeric_limits<T>::is_signed, "only unsigned types or bigint supported"); //bigint does not carry sign bit on shift
int i = 0;
for (T v = _val; v; ++i, v >>= 8) {}
std::string ret(std::max<unsigned>(_min, i), '\0');
@ -199,6 +202,7 @@ std::string randomWord();
template <class T>
inline unsigned bytesRequired(T _i)
{
static_assert(std::is_same<bigint, T>::value || !std::numeric_limits<T>::is_signed, "only unsigned types or bigint supported"); //bigint does not carry sign bit on shift
unsigned i = 0;
for (; _i != 0; ++i, _i >>= 8) {}
return i;

2
mix/ContractCallDataEncoder.cpp

@ -104,7 +104,7 @@ void ContractCallDataEncoder::encode(QVariant const& _data, SolidityType const&
m_dynamicData += empty; //reserve space for count
encodeSingleItem(_data.toString(), _type, m_dynamicData);
vector_ref<byte> sizeRef(m_dynamicData.data() + sizePos, 32);
toBigEndian(_data.toString().size(), sizeRef);
toBigEndian(static_cast<unsigned>(_data.toString().size()), sizeRef);
m_staticOffsetMap.push_back(std::make_pair(m_encodedData.size(), sizePos));
m_encodedData += empty; //reserve space for offset
}

Loading…
Cancel
Save