Browse Source

Merge remote-tracking branch 'upstream/develop' into LOGtests

cl-refactor
Christoph Jentzsch 10 years ago
parent
commit
599bee2595
  1. 34
      alethzero/MainWin.cpp
  2. 3
      alethzero/MainWin.h
  3. 31
      libdevcore/CommonJS.cpp
  4. 11
      libdevcore/CommonJS.h
  5. 4
      libdevcore/Exceptions.h
  6. 2
      libdevcrypto/ECDHE.cpp
  7. 4
      libethereum/BlockChain.h
  8. 82
      libethereum/Client.cpp
  9. 14
      libethereum/Client.h
  10. 6
      libethereum/Executive.cpp
  11. 20
      libethereum/Interface.h
  12. 1
      libethereum/MessageFilter.h
  13. 14
      libethereum/State.cpp
  14. 2
      libethereum/State.h
  15. 2
      libevm/VM.h
  16. 1068
      libjsqrc/ethereum.js
  17. 3
      libjsqrc/js.qrc
  18. 467
      libjsqrc/main.js
  19. 49
      libjsqrc/qt.js
  20. 2
      libjsqrc/setup.js
  21. 8
      libp2p/Host.cpp
  22. 4
      libqethereum/QEthereum.h
  23. 53
      libsolidity/AST.cpp
  24. 31
      libsolidity/AST.h
  25. 2
      libsolidity/Compiler.cpp
  26. 4
      libsolidity/CompilerContext.h
  27. 190
      libsolidity/ExpressionCompiler.cpp
  28. 77
      libsolidity/ExpressionCompiler.h
  29. 34
      libsolidity/NameAndTypeResolver.cpp
  30. 11
      libsolidity/NameAndTypeResolver.h
  31. 61
      libsolidity/Types.cpp
  32. 27
      libsolidity/Types.h
  33. 2
      libweb3jsonrpc/CMakeLists.txt
  34. 257
      libweb3jsonrpc/WebThreeStubServer.cpp
  35. 8
      libweb3jsonrpc/WebThreeStubServer.h
  36. 48
      libweb3jsonrpc/abstractwebthreestubserver.h
  37. 8
      libweb3jsonrpc/spec.json
  38. 2
      libwhisper/Common.cpp
  39. 7
      libwhisper/Common.h
  40. 326
      stdserv.js
  41. 2
      test/crypto.cpp
  42. 66
      test/jsonrpc.cpp
  43. 2
      test/solidityCompiler.cpp
  44. 204
      test/solidityEndToEndTest.cpp
  45. 38
      test/solidityNameAndTypeResolution.cpp
  46. 85
      test/webthreestubclient.h
  47. 17
      third/MainWin.cpp
  48. 4
      third/MainWin.h
  49. 9
      windows/LibEthereum.vcxproj
  50. 17
      windows/LibEthereum.vcxproj.filters

34
alethzero/MainWin.cpp

@ -241,7 +241,7 @@ void Main::onKeysChanged()
installBalancesWatch();
}
unsigned Main::installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f)
unsigned Main::installWatch(dev::eth::LogFilter const& _tf, std::function<void()> const& _f)
{
auto ret = ethereum()->installWatch(_tf);
m_handlers[ret] = _f;
@ -263,8 +263,8 @@ void Main::uninstallWatch(unsigned _w)
void Main::installWatches()
{
installWatch(dev::eth::MessageFilter().altered(c_config, 0), [=](){ installNameRegWatch(); });
installWatch(dev::eth::MessageFilter().altered(c_config, 1), [=](){ installCurrenciesWatch(); });
installWatch(dev::eth::LogFilter().address(c_config), [=]() { installNameRegWatch(); });
installWatch(dev::eth::LogFilter().address(c_config), [=]() { installCurrenciesWatch(); });
installWatch(dev::eth::PendingChangedFilter, [=](){ onNewPending(); });
installWatch(dev::eth::ChainChangedFilter, [=](){ onNewBlock(); });
}
@ -272,29 +272,26 @@ void Main::installWatches()
void Main::installNameRegWatch()
{
uninstallWatch(m_nameRegFilter);
m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
m_nameRegFilter = installWatch(dev::eth::LogFilter().address((u160)ethereum()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
}
void Main::installCurrenciesWatch()
{
uninstallWatch(m_currenciesFilter);
m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
m_currenciesFilter = installWatch(dev::eth::LogFilter().address((u160)ethereum()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
}
void Main::installBalancesWatch()
{
dev::eth::MessageFilter tf;
dev::eth::LogFilter tf;
vector<Address> altCoins;
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1));
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i)
altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys)
{
tf.altered(i.address());
for (auto c: altCoins)
tf.altered(c, (u160)i.address());
}
tf.address(c).topic(h256(i.address(), h256::AlignRight));
uninstallWatch(m_balancesFilter);
m_balancesFilter = installWatch(tf, [=](){ onBalancesChange(); });
@ -353,8 +350,16 @@ void Main::on_enableOptimizer_triggered()
on_data_textChanged();
}
QString Main::contents(QString _s)
{
return QString::fromStdString(dev::asString(dev::contents(_s.toStdString())));
}
void Main::load(QString _s)
{
QString contents = QString::fromStdString(dev::asString(dev::contents(_s.toStdString())));
ui->webView->page()->currentFrame()->evaluateJavaScript(contents);
/*
QFile fin(_s);
if (!fin.open(QFile::ReadOnly))
return;
@ -375,7 +380,7 @@ void Main::load(QString _s)
//eval(line);
line.clear();
}
}
}*/
}
void Main::on_loadJS_triggered()
@ -679,7 +684,7 @@ void Main::on_importKeyFile_triggered()
try
{
js::mValue val;
json_spirit::read_string(asString(contents(s.toStdString())), val);
json_spirit::read_string(asString(dev::contents(s.toStdString())), val);
auto obj = val.get_obj();
if (obj["encseed"].type() == js::str_type)
{
@ -948,7 +953,7 @@ void Main::refreshBlockCount()
cwatch << "refreshBlockCount()";
auto d = ethereum()->blockChain().details();
auto diff = BlockInfo(ethereum()->blockChain().block()).difficulty;
ui->blockCount->setText(QString("%6 #%1 @%3 T%2 N%4 D%5").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)).arg(dev::eth::c_protocolVersion).arg(dev::eth::c_databaseVersion).arg(m_privateChain.size() ? "[" + m_privateChain + "] " : "testnet"));
ui->blockCount->setText(QString("%6 #%1 @%3 T%2 PV%4 D%5").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)).arg(dev::eth::c_protocolVersion).arg(dev::eth::c_databaseVersion).arg(m_privateChain.size() ? "[" + m_privateChain + "] " : "testnet"));
}
static bool blockMatch(string const& _f, dev::eth::BlockDetails const& _b, h256 _h, BlockChain const& _bc)
@ -1284,7 +1289,7 @@ void Main::on_blocks_currentItemChanged()
Transaction tx(block[1][txi].data());
auto ss = tx.safeSender();
h256 th = sha3(rlpList(ss, tx.nonce()));
auto receipt = ethereum()->blockChain().receipts(h).receipts[txi];
TransactionReceipt receipt = ethereum()->blockChain().receipts(h).receipts[txi];
s << "<h3>" << th << "</h3>";
s << "<h4>" << h << "[<b>" << txi << "</b>]</h4>";
s << "<br/>From: <b>" << pretty(ss).toHtmlEscaped().toStdString() << "</b> " << ss;
@ -1300,6 +1305,7 @@ void Main::on_blocks_currentItemChanged()
s << "<br/>R: <b>" << hex << nouppercase << tx.signature().r << "</b>";
s << "<br/>S: <b>" << hex << nouppercase << tx.signature().s << "</b>";
s << "<br/>Msg: <b>" << tx.sha3(eth::WithoutSignature) << "</b>";
s << "<div>Log Bloom: " << receipt.bloom() << "</div>";
s << "<div>Hex: <span style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">" << toHex(block[1][txi].data()) << "</span></div>";
auto r = receipt.rlp();
s << "<div>Receipt: " << toString(RLP(r)) << "</div>";

3
alethzero/MainWin.h

@ -85,6 +85,7 @@ public slots:
void note(QString _entry);
void debug(QString _entry);
void warn(QString _entry);
QString contents(QString _file);
void onKeysChanged();
@ -188,7 +189,7 @@ private:
dev::u256 value() const;
dev::u256 gasPrice() const;
unsigned installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f);
unsigned installWatch(dev::eth::LogFilter const& _tf, std::function<void()> const& _f);
unsigned installWatch(dev::h256 _tf, std::function<void()> const& _f);
void uninstallWatch(unsigned _w);

31
libdevcore/CommonJS.cpp

@ -38,31 +38,20 @@ bytes jsToBytes(std::string const& _s)
return bytes();
}
std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r)
bytes padded(bytes _b, unsigned _l)
{
bytes b = jsToBytes(_s);
while (b.size() < _l)
b.insert(b.begin(), 0);
while (b.size() < _r)
b.push_back(0);
return asString(b).substr(b.size() - std::max(_l, _r));
while (_b.size() < _l)
_b.insert(_b.begin(), 0);
while (_b.size() < _l)
_b.push_back(0);
return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l)));
}
std::string jsPadded(std::string const& _s, unsigned _l)
bytes unpadded(bytes _b)
{
if (_s.substr(0, 2) == "0x" || _s.find_first_not_of("0123456789") == std::string::npos)
// Numeric: pad to right
return jsPadded(_s, _l, _l);
else
// Text: pad to the left
return jsPadded(_s, 0, _l);
}
std::string jsUnpadded(std::string _s)
{
auto p = _s.find_last_not_of((char)0);
_s.resize(p == std::string::npos ? 0 : (p + 1));
return _s;
auto p = asString(_b).find_last_not_of((char)0);
_b.resize(p == std::string::npos ? 0 : (p + 1));
return _b;
}
}

11
libdevcore/CommonJS.h

@ -47,9 +47,8 @@ inline std::string toJS(dev::bytes const& _n)
}
bytes jsToBytes(std::string const& _s);
std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r);
std::string jsPadded(std::string const& _s, unsigned _l);
std::string jsUnpadded(std::string _s);
bytes padded(bytes _b, unsigned _l);
bytes unpadded(bytes _s);
template <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)
{
@ -61,7 +60,7 @@ template <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)
return (typename FixedHash<N>::Arith)(_s);
else
// Binary
return FixedHash<N>(asBytes(jsPadded(_s, N)));
return FixedHash<N>(); // FAIL
}
inline std::string jsToFixed(double _s)
@ -79,7 +78,7 @@ template <unsigned N> boost::multiprecision::number<boost::multiprecision::cpp_i
return boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>(_s);
else
// Binary
return fromBigEndian<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>>(asBytes(jsPadded(_s, N)));
return 0; // FAIL
}
inline Address jsToAddress(std::string const& _s) { return jsToFixed<sizeof(dev::Address)>(_s); }
@ -89,7 +88,7 @@ inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); }
inline std::string jsToBinary(std::string const& _s)
{
return jsUnpadded(dev::toString(jsToBytes(_s)));
return dev::toString(unpadded(jsToBytes(_s)));
}
inline std::string jsToDecimal(std::string const& _s)

4
libdevcore/Exceptions.h

@ -45,7 +45,7 @@ struct FileError: virtual Exception {};
typedef boost::error_info<struct tag_invalidSymbol, char> errinfo_invalidSymbol;
typedef boost::error_info<struct tag_address, std::string> errinfo_wrongAddress;
typedef boost::error_info<struct tag_comment, std::string> errinfo_comment;
typedef boost::error_info<struct tag_required, size_t> errinfo_required;
typedef boost::error_info<struct tag_got, size_t> errinfo_got;
typedef boost::error_info<struct tag_required, bigint> errinfo_required;
typedef boost::error_info<struct tag_got, bigint> errinfo_got;
typedef boost::tuple<errinfo_required, errinfo_got> RequirementError;
}

2
libdevcrypto/ECDHE.cpp

@ -76,7 +76,7 @@ void ECDHEKeyExchange::exchange(bytes& o_exchange)
memcpy(&exchange[exchange.size() - sizeof(p)], p.data(), sizeof(p));
// protocol parameters; should be fixed size
bytes v({0x80});
bytes v(1, 0x80);
exchange.resize(exchange.size() + v.size());
memcpy(&exchange[exchange.size() - v.size()], v.data(), v.size());

4
libethereum/BlockChain.h

@ -93,6 +93,10 @@ public:
/// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 _hash) const;
/// Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
BlockInfo info(h256 _hash) const { return BlockInfo(block(_hash)); }
BlockInfo info() const { return BlockInfo(block()); }
/// Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
BlockDetails details(h256 _hash) const { return queryExtras<BlockDetails, 0>(_hash, m_details, x_details, NullBlockDetails); }
BlockDetails details() const { return details(currentHash()); }

82
libethereum/Client.cpp

@ -159,7 +159,7 @@ void Client::clearPending()
if (!m_postMine.pending().size())
return;
for (unsigned i = 0; i < m_postMine.pending().size(); ++i)
appendFromNewPending(m_postMine.oldBloom(i), changeds);
appendFromNewPending(m_postMine.logBloom(i), changeds);
changeds.insert(PendingChangedFilter);
m_postMine = m_preMine;
}
@ -181,7 +181,7 @@ unsigned Client::installWatch(h256 _h)
return ret;
}
unsigned Client::installWatch(MessageFilter const& _f)
unsigned Client::installWatch(LogFilter const& _f)
{
lock_guard<mutex> l(m_filterLock);
@ -222,8 +222,9 @@ void Client::noteChanged(h256Set const& _filters)
}
}
void Client::appendFromNewPending(h256 _bloom, h256Set& o_changed) const
void Client::appendFromNewPending(LogBloom _bloom, h256Set& o_changed) const
{
// TODO: more precise check on whether the txs match.
lock_guard<mutex> l(m_filterLock);
for (pair<h256, InstalledFilter> const& i: m_filters)
if ((unsigned)i.second.filter.latest() > m_bc.number() && i.second.filter.matches(_bloom))
@ -232,11 +233,12 @@ void Client::appendFromNewPending(h256 _bloom, h256Set& o_changed) const
void Client::appendFromNewBlock(h256 _block, h256Set& o_changed) const
{
auto d = m_bc.details(_block);
// TODO: more precise check on whether the txs match.
auto d = m_bc.info(_block);
lock_guard<mutex> l(m_filterLock);
for (pair<h256, InstalledFilter> const& i: m_filters)
if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.bloom))
if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.logBloom))
o_changed.insert(i.first);
}
@ -341,7 +343,7 @@ bytes Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _dat
n = temp.transactionsFrom(toAddress(_secret));
}
Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret);
u256 gasUsed = temp.execute(t.data(), &out, false);
u256 gasUsed = temp.execute(t.rlp(), &out, false);
(void)gasUsed; // TODO: do something with gasused which it returns.
}
catch (...)
@ -440,7 +442,7 @@ void Client::doWork()
// returns h256s as blooms, once for each transaction.
cwork << "postSTATE <== TQ";
h256s newPendingBlooms = m_postMine.sync(m_tq);
h512s newPendingBlooms = m_postMine.sync(m_tq);
if (newPendingBlooms.size())
{
for (auto i: newPendingBlooms)
@ -564,9 +566,9 @@ BlockInfo Client::uncle(h256 _blockHash, unsigned _i) const
return BlockInfo::fromHeader(b[2][_i].data());
}
PastMessages Client::messages(MessageFilter const& _f) const
LogEntries Client::logs(LogFilter const& _f) const
{
PastMessages ret;
LogEntries ret;
unsigned begin = min<unsigned>(m_bc.number(), (unsigned)_f.latest());
unsigned end = min(begin, (unsigned)_f.earliest());
unsigned m = _f.max();
@ -578,23 +580,22 @@ PastMessages Client::messages(MessageFilter const& _f) const
ReadGuard l(x_stateDB);
for (unsigned i = 0; i < m_postMine.pending().size(); ++i)
{
// Might have a transaction that contains a matching message.
Manifest const& ms = m_postMine.changesFromPending(i);
PastMessages pm = _f.matches(ms, i);
if (pm.size())
// Might have a transaction that contains a matching log.
TransactionReceipt const& tr = m_postMine.receipt(i);
LogEntries le = _f.matches(tr);
if (le.size())
{
auto ts = time(0);
for (unsigned j = 0; j < pm.size() && ret.size() != m; ++j)
for (unsigned j = 0; j < le.size() && ret.size() != m; ++j)
if (s)
s--;
else
// Have a transaction that contains a matching message.
ret.insert(ret.begin(), pm[j].polish(h256(), ts, m_bc.number() + 1, m_postMine.address()));
ret.insert(ret.begin(), le[j]);
}
}
}
#if ETH_DEBUG
// fill these params
unsigned skipped = 0;
unsigned falsePos = 0;
#endif
@ -602,55 +603,40 @@ PastMessages Client::messages(MessageFilter const& _f) const
unsigned n = begin;
for (; ret.size() != m && n != end; n--, h = m_bc.details(h).parent)
{
auto d = m_bc.details(h);
#if ETH_DEBUG
int total = 0;
#endif
if (_f.matches(d.bloom))
{
// Might have a block that contains a transaction that contains a matching message.
auto bs = m_bc.blooms(h).blooms;
Manifests ms;
BlockInfo bi;
for (unsigned i = 0; i < bs.size(); ++i)
if (_f.matches(bs[i]))
// check block bloom
if (_f.matches(m_bc.info(h).logBloom))
for (TransactionReceipt receipt: m_bc.receipts(h).receipts)
{
if (_f.matches(receipt.bloom()))
{
// Might have a transaction that contains a matching message.
if (ms.empty())
ms = m_bc.traces(h).traces;
Manifest const& changes = ms[i];
PastMessages pm = _f.matches(changes, i);
if (pm.size())
LogEntries le = _f.matches(receipt);
if (le.size())
{
#if ETH_DEBUG
total += pm.size();
total += le.size();
#endif
if (!bi)
bi.populate(m_bc.block(h));
auto ts = bi.timestamp;
auto cb = bi.coinbaseAddress;
for (unsigned j = 0; j < pm.size() && ret.size() != m; ++j)
for (unsigned j = 0; j < le.size() && ret.size() != m; ++j)
{
if (s)
s--;
else
// Have a transaction that contains a matching message.
ret.push_back(pm[j].polish(h, ts, n, cb));
ret.insert(ret.begin(), le[j]);
}
}
}
#if ETH_DEBUG
if (!total)
falsePos++;
}
if (!total)
falsePos++;
}
else
skipped++;
#else
}
#endif
if (n == end)
break;
}
#if ETH_DEBUG
// cdebug << (begin - n) << "searched; " << skipped << "skipped; " << falsePos << "false +ves";
cdebug << (begin - n) << "searched; " << skipped << "skipped; " << falsePos << "false +ves";
#endif
return ret;
}

14
libethereum/Client.h

@ -79,9 +79,11 @@ static const int GenesisBlock = INT_MIN;
struct InstalledFilter
{
InstalledFilter(MessageFilter const& _f): filter(_f) {}
// InstalledFilter(MessageFilter const& _f): filter(_f) {}
// MessageFilter filter;
InstalledFilter(LogFilter const& _f): filter(_f) {}
MessageFilter filter;
LogFilter filter;
unsigned refCount = 1;
};
@ -152,14 +154,14 @@ public:
virtual bytes codeAt(Address _a, int _block) const;
virtual std::map<u256, u256> storageAt(Address _a, int _block) const;
virtual unsigned installWatch(MessageFilter const& _filter);
virtual unsigned installWatch(LogFilter const& _filter);
virtual unsigned installWatch(h256 _filterId);
virtual void uninstallWatch(unsigned _watchId);
virtual bool peekWatch(unsigned _watchId) const { std::lock_guard<std::mutex> l(m_filterLock); try { return m_watches.at(_watchId).changes != 0; } catch (...) { return false; } }
virtual bool checkWatch(unsigned _watchId) { std::lock_guard<std::mutex> l(m_filterLock); bool ret = false; try { ret = m_watches.at(_watchId).changes != 0; m_watches.at(_watchId).changes = 0; } catch (...) {} return ret; }
virtual PastMessages messages(unsigned _watchId) const { try { std::lock_guard<std::mutex> l(m_filterLock); return messages(m_filters.at(m_watches.at(_watchId).id).filter); } catch (...) { return PastMessages(); } }
virtual PastMessages messages(MessageFilter const& _filter) const;
virtual LogEntries logs(unsigned _watchId) const { try { std::lock_guard<std::mutex> l(m_filterLock); return logs(m_filters.at(m_watches.at(_watchId).id).filter); } catch (...) { return LogEntries(); } }
virtual LogEntries logs(LogFilter const& _filter) const;
// [EXTRA API]:
@ -259,7 +261,7 @@ private:
/// Collate the changed filters for the bloom filter of the given pending transaction.
/// Insert any filters that are activated into @a o_changed.
void appendFromNewPending(h256 _pendingTransactionBloom, h256Set& o_changed) const;
void appendFromNewPending(LogBloom _pendingTransactionBloom, h256Set& o_changed) const;
/// Collate the changed filters for the hash of the given block.
/// Insert any filters that are activated into @a o_changed.

6
libethereum/Executive.cpp

@ -71,7 +71,7 @@ bool Executive::setup(bytesConstRef _rlp)
if (m_t.gas() < gasCost)
{
clog(StateDetail) << "Not enough gas to pay for the transaction: Require >" << gasCost << " Got" << m_t.gas();
BOOST_THROW_EXCEPTION(OutOfGas());
BOOST_THROW_EXCEPTION(OutOfGas() << RequirementError((bigint)gasCost, (bigint)m_t.gas()));
}
u256 cost = m_t.value() + m_t.gas() * m_t.gasPrice();
@ -80,14 +80,14 @@ bool Executive::setup(bytesConstRef _rlp)
if (m_s.balance(m_sender) < cost)
{
clog(StateDetail) << "Not enough cash: Require >" << cost << " Got" << m_s.balance(m_sender);
BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError((int)cost, (int)m_s.balance(m_sender)));
BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError((bigint)cost, (bigint)m_s.balance(m_sender)));
}
u256 startGasUsed = m_s.gasUsed();
if (startGasUsed + m_t.gas() > m_s.m_currentBlock.gasLimit)
{
clog(StateDetail) << "Too much gas used in this block: Require <" << (m_s.m_currentBlock.gasLimit - startGasUsed) << " Got" << m_t.gas();
BOOST_THROW_EXCEPTION(BlockGasLimitReached() << RequirementError((int)(m_s.m_currentBlock.gasLimit - startGasUsed), (int)m_t.gas()));
BOOST_THROW_EXCEPTION(BlockGasLimitReached() << RequirementError((bigint)(m_s.m_currentBlock.gasLimit - startGasUsed), (bigint)m_t.gas()));
}
// Increment associated nonce for sender.

20
libethereum/Interface.h

@ -84,13 +84,18 @@ public:
virtual bytes codeAt(Address _a, int _block) const = 0;
virtual std::map<u256, u256> storageAt(Address _a, int _block) const = 0;
// [MESSAGE API]
virtual PastMessages messages(unsigned _watchId) const = 0;
virtual PastMessages messages(MessageFilter const& _filter) const = 0;
// // [MESSAGE API]
//
// virtual PastMessages messages(unsigned _watchId) const = 0;
// virtual PastMessages messages(MessageFilter const& _filter) const = 0;
// [LOGS API]
virtual LogEntries logs(unsigned _watchId) const = 0;
virtual LogEntries logs(LogFilter const& _filter) const = 0;
/// Install, uninstall and query watches.
virtual unsigned installWatch(MessageFilter const& _filter) = 0;
virtual unsigned installWatch(LogFilter const& _filter) = 0;
virtual unsigned installWatch(h256 _filterId) = 0;
virtual void uninstallWatch(unsigned _watchId) = 0;
virtual bool peekWatch(unsigned _watchId) const = 0;
@ -175,12 +180,13 @@ class Watch: public boost::noncopyable
public:
Watch() {}
Watch(Interface& _c, h256 _f): m_c(&_c), m_id(_c.installWatch(_f)) {}
Watch(Interface& _c, MessageFilter const& _tf): m_c(&_c), m_id(_c.installWatch(_tf)) {}
Watch(Interface& _c, LogFilter const& _tf): m_c(&_c), m_id(_c.installWatch(_tf)) {}
~Watch() { if (m_c) m_c->uninstallWatch(m_id); }
bool check() { return m_c ? m_c->checkWatch(m_id) : false; }
bool peek() { return m_c ? m_c->peekWatch(m_id) : false; }
PastMessages messages() const { return m_c->messages(m_id); }
// PastMessages messages() const { return m_c->messages(m_id); }
LogEntries logs() const { return m_c->logs(m_id); }
private:
Interface* m_c = nullptr;

1
libethereum/MessageFilter.h

@ -90,7 +90,6 @@ public:
LogEntries matches(TransactionReceipt const& _r) const;
LogFilter address(Address _a) { m_addresses.insert(_a); return *this; }
LogFilter from(Address _a) { return topic(u256((u160)_a) + 1); }
LogFilter topic(h256 const& _t) { m_topics.insert(_t); return *this; }
LogFilter withMax(unsigned _m) { m_max = _m; return *this; }
LogFilter withSkip(unsigned _m) { m_skip = _m; return *this; }

14
libethereum/State.cpp

@ -326,8 +326,8 @@ StateDiff State::diff(State const& _c) const
for (auto i: _c.m_cache)
ads.insert(i.first);
cnote << *this;
cnote << _c;
// cnote << *this;
// cnote << _c;
for (auto i: ads)
{
@ -538,10 +538,10 @@ bool State::cull(TransactionQueue& _tq) const
return ret;
}
h256s State::sync(TransactionQueue& _tq, bool* o_transactionQueueChanged)
h512s State::sync(TransactionQueue& _tq, bool* o_transactionQueueChanged)
{
// TRANSACTIONS
h256s ret;
h512s ret;
auto ts = _tq.transactions();
for (int goodTxs = 1; goodTxs;)
@ -556,7 +556,7 @@ h256s State::sync(TransactionQueue& _tq, bool* o_transactionQueueChanged)
uncommitToMine();
// boost::timer t;
execute(i.second);
ret.push_back(m_receipts.back().changes().bloom());
ret.push_back(m_receipts.back().bloom());
_tq.noteGood(i);
++goodTxs;
// cnote << "TX took:" << t.elapsed() * 1000;
@ -806,7 +806,7 @@ void State::commitToMine(BlockChain const& _bc)
{
uncommitToMine();
cnote << "Committing to mine on block" << m_previousBlock.hash.abridged();
// cnote << "Committing to mine on block" << m_previousBlock.hash.abridged();
#ifdef ETH_PARANOIA
commit();
cnote << "Pre-reward stateRoot:" << m_state.root();
@ -881,7 +881,7 @@ void State::commitToMine(BlockChain const& _bc)
// Commit any and all changes to the trie that are in the cache, then update the state root accordingly.
commit();
cnote << "Post-reward stateRoot:" << m_state.root().abridged();
// cnote << "Post-reward stateRoot:" << m_state.root().abridged();
// cnote << m_state;
// cnote << *this;

2
libethereum/State.h

@ -147,7 +147,7 @@ public:
/// @returns a list of bloom filters one for each transaction placed from the queue into the state.
/// @a o_transactionQueueChanged boolean pointer, the value of which will be set to true if the transaction queue
/// changed and the pointer is non-null
h256s sync(TransactionQueue& _tq, bool* o_transactionQueueChanged = nullptr);
h512s sync(TransactionQueue& _tq, bool* o_transactionQueueChanged = nullptr);
/// Like sync but only operate on _tq, killing the invalid/old ones.
bool cull(TransactionQueue& _tq) const;

2
libevm/VM.h

@ -71,7 +71,7 @@ public:
template <class Ext>
bytesConstRef go(Ext& _ext, OnOpFunc const& _onOp = OnOpFunc(), uint64_t _steps = (uint64_t)-1);
void require(u256 _n) { if (m_stack.size() < _n) BOOST_THROW_EXCEPTION(StackTooSmall() << RequirementError(int(_n), m_stack.size())); }
void require(u256 _n) { if (m_stack.size() < _n) BOOST_THROW_EXCEPTION(StackTooSmall() << RequirementError((bigint)_n, (bigint)m_stack.size())); }
void requireMem(unsigned _n) { if (m_temp.size() < _n) { m_temp.resize(_n); } }
u256 gas() const { return m_gas; }
u256 curPC() const { return m_curPC; }

1068
libjsqrc/ethereum.js

File diff suppressed because it is too large

3
libjsqrc/js.qrc

@ -2,7 +2,6 @@
<qresource prefix="/js">
<file>es6-promise-2.0.0.js</file>
<file>setup.js</file>
<file>main.js</file>
<file>qt.js</file>
<file>ethereum.js</file>
</qresource>
</RCC>

467
libjsqrc/main.js

@ -1,467 +0,0 @@
/*
This file is part of ethereum.js.
ethereum.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ethereum.js 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file main.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2014
*/
(function(window) {
function isPromise(o) {
return o instanceof Promise
}
function flattenPromise (obj) {
if (obj instanceof Promise) {
return Promise.resolve(obj);
}
if (obj instanceof Array) {
return new Promise(function (resolve) {
var promises = obj.map(function (o) {
return flattenPromise(o);
});
return Promise.all(promises).then(function (res) {
for (var i = 0; i < obj.length; i++) {
obj[i] = res[i];
}
resolve(obj);
});
});
}
if (obj instanceof Object) {
return new Promise(function (resolve) {
var keys = Object.keys(obj);
var promises = keys.map(function (key) {
return flattenPromise(obj[key]);
});
return Promise.all(promises).then(function (res) {
for (var i = 0; i < keys.length; i++) {
obj[keys[i]] = res[i];
}
resolve(obj);
});
});
}
return Promise.resolve(obj);
};
var ethMethods = function () {
var blockCall = function (args) {
return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber";
};
var transactionCall = function (args) {
return typeof args[0] === "string" ? 'eth_transactionByHash' : 'eth_transactionByNumber';
};
var uncleCall = function (args) {
return typeof args[0] === "string" ? 'eth_uncleByHash' : 'eth_uncleByNumber';
};
var methods = [
{ name: 'balanceAt', call: 'eth_balanceAt' },
{ name: 'stateAt', call: 'eth_stateAt' },
{ name: 'countAt', call: 'eth_countAt'},
{ name: 'codeAt', call: 'eth_codeAt' },
{ name: 'transact', call: 'eth_transact' },
{ name: 'call', call: 'eth_call' },
{ name: 'block', call: blockCall },
{ name: 'transaction', call: transactionCall },
{ name: 'uncle', call: uncleCall },
{ name: 'compile', call: 'eth_compile' },
{ name: 'lll', call: 'eth_lll' }
];
return methods;
};
var ethProperties = function () {
return [
{ name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },
{ name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },
{ name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },
{ name: 'gasPrice', getter: 'eth_gasPrice' },
{ name: 'account', getter: 'eth_account' },
{ name: 'accounts', getter: 'eth_accounts' },
{ name: 'peerCount', getter: 'eth_peerCount' },
{ name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },
{ name: 'number', getter: 'eth_number'}
];
};
var dbMethods = function () {
return [
{ name: 'put', call: 'db_put' },
{ name: 'get', call: 'db_get' },
{ name: 'putString', call: 'db_putString' },
{ name: 'getString', call: 'db_getString' }
];
};
var shhMethods = function () {
return [
{ name: 'post', call: 'shh_post' },
{ name: 'newIdentity', call: 'shh_newIdentity' },
{ name: 'haveIdentity', call: 'shh_haveIdentity' },
{ name: 'newGroup', call: 'shh_newGroup' },
{ name: 'addToGroup', call: 'shh_addToGroup' }
];
};
var ethWatchMethods = function () {
var newFilter = function (args) {
return typeof args[0] === 'string' ? 'eth_newFilterString' : 'eth_newFilter';
};
return [
{ name: 'newFilter', call: newFilter },
{ name: 'uninstallFilter', call: 'eth_uninstallFilter' },
{ name: 'getMessages', call: 'eth_getMessages' }
];
};
var shhWatchMethods = function () {
return [
{ name: 'newFilter', call: 'shh_newFilter' },
{ name: 'uninstallFilter', call: 'shh_uninstallFilter' },
{ name: 'getMessage', call: 'shh_getMessages' }
];
};
var setupMethods = function (obj, methods) {
methods.forEach(function (method) {
obj[method.name] = function () {
return flattenPromise(Array.prototype.slice.call(arguments)).then(function (args) {
var call = typeof method.call === "function" ? method.call(args) : method.call;
return {call: call, args: args};
}).then(function (request) {
return new Promise(function (resolve, reject) {
web3.provider.send(request, function (err, result) {
if (!err) {
resolve(result);
return;
}
reject(err);
});
});
}).catch(function(err) {
console.error(err);
});
};
});
};
var setupProperties = function (obj, properties) {
properties.forEach(function (property) {
var proto = {};
proto.get = function () {
return new Promise(function(resolve, reject) {
web3.provider.send({call: property.getter}, function(err, result) {
if (!err) {
resolve(result);
return;
}
reject(err);
});
});
};
if (property.setter) {
proto.set = function (val) {
return flattenPromise([val]).then(function (args) {
return new Promise(function (resolve) {
web3.provider.send({call: property.setter, args: args}, function (err, result) {
if (!err) {
resolve(result);
return;
}
reject(err);
});
});
}).catch(function (err) {
console.error(err);
});
}
}
Object.defineProperty(obj, property.name, proto);
});
};
var web3 = {
_callbacks: {},
_events: {},
providers: {},
toHex: function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
},
toAscii: function(hex) {
// Find termination
var str = "";
var i = 0, l = hex.length;
if (hex.substring(0, 2) == '0x')
i = 2;
for(; i < l; i+=2) {
var code = hex.charCodeAt(i)
if(code == 0) {
break;
}
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return str;
},
toDecimal: function (val) {
return parseInt(val, 16);
},
fromAscii: function(str, pad) {
pad = pad === undefined ? 32 : pad;
var hex = this.toHex(str);
while(hex.length < pad*2)
hex += "00";
return "0x" + hex;
},
eth: {
prototype: Object(),
watch: function (params) {
return new Filter(params, ethWatch);
},
},
db: {
prototype: Object()
},
shh: {
prototype: Object(),
watch: function (params) {
return new Filter(params, shhWatch);
}
},
on: function(event, id, cb) {
if(web3._events[event] === undefined) {
web3._events[event] = {};
}
web3._events[event][id] = cb;
return this
},
off: function(event, id) {
if(web3._events[event] !== undefined) {
delete web3._events[event][id];
}
return this
},
trigger: function(event, id, data) {
var callbacks = web3._events[event];
if (!callbacks || !callbacks[id]) {
return;
}
var cb = callbacks[id];
cb(data);
},
};
var eth = web3.eth;
setupMethods(eth, ethMethods());
setupProperties(eth, ethProperties());
setupMethods(web3.db, dbMethods());
setupMethods(web3.shh, shhMethods());
var ethWatch = {
changed: 'eth_changed'
};
setupMethods(ethWatch, ethWatchMethods());
var shhWatch = {
changed: 'shh_changed'
};
setupMethods(shhWatch, shhWatchMethods());
var ProviderManager = function() {
this.queued = [];
this.polls = [];
this.ready = false;
this.provider = undefined;
this.id = 1;
var self = this;
var poll = function () {
if (self.provider && self.provider.poll) {
self.polls.forEach(function (data) {
data.data._id = self.id;
self.id++;
self.provider.poll(data.data, data.id);
});
}
setTimeout(poll, 12000);
};
poll();
};
ProviderManager.prototype.send = function(data, cb) {
data._id = this.id;
if (cb) {
web3._callbacks[data._id] = cb;
}
data.args = data.args || [];
this.id++;
if(this.provider !== undefined) {
this.provider.send(data);
} else {
console.warn("provider is not set");
this.queued.push(data);
}
};
ProviderManager.prototype.set = function(provider) {
if(this.provider !== undefined && this.provider.unload !== undefined) {
this.provider.unload();
}
this.provider = provider;
this.ready = true;
};
ProviderManager.prototype.sendQueued = function() {
for(var i = 0; this.queued.length; i++) {
// Resend
this.send(this.queued[i]);
}
};
ProviderManager.prototype.installed = function() {
return this.provider !== undefined;
};
ProviderManager.prototype.startPolling = function (data, pollId) {
if (!this.provider || !this.provider.poll) {
return;
}
this.polls.push({data: data, id: pollId});
};
ProviderManager.prototype.stopPolling = function (pollId) {
for (var i = this.polls.length; i--;) {
var poll = this.polls[i];
if (poll.id === pollId) {
this.polls.splice(i, 1);
}
}
};
web3.provider = new ProviderManager();
web3.setProvider = function(provider) {
provider.onmessage = messageHandler;
web3.provider.set(provider);
web3.provider.sendQueued();
};
var Filter = function(options, impl) {
this.impl = impl;
this.callbacks = [];
var self = this;
this.promise = impl.newFilter(options);
this.promise.then(function (id) {
self.id = id;
web3.on(impl.changed, id, self.trigger.bind(self));
web3.provider.startPolling({call: impl.changed, args: [id]}, id);
});
};
Filter.prototype.arrived = function(callback) {
this.changed(callback);
}
Filter.prototype.changed = function(callback) {
var self = this;
this.promise.then(function(id) {
self.callbacks.push(callback);
});
};
Filter.prototype.trigger = function(messages) {
if (!(messages instanceof Array) || messages.length) {
for(var i = 0; i < this.callbacks.length; i++) {
this.callbacks[i].call(this, messages);
}
}
};
Filter.prototype.uninstall = function() {
var self = this;
this.promise.then(function (id) {
self.impl.uninstallFilter(id);
web3.provider.stopPolling(id);
web3.off(impl.changed, id);
});
};
Filter.prototype.messages = function() {
var self = this;
return this.promise.then(function (id) {
return self.impl.getMessages(id);
});
};
function messageHandler(data) {
if(data._event !== undefined) {
web3.trigger(data._event, data._id, data.data);
return;
}
if(data._id) {
var cb = web3._callbacks[data._id];
if (cb) {
cb.call(this, data.error, data.data);
delete web3._callbacks[data._id];
}
}
}
/*
// Install default provider
if(!web3.provider.installed()) {
var sock = new web3.WebSocket("ws://localhost:40404/eth");
web3.setProvider(sock);
}
*/
window.web3 = web3;
})(this);

49
libjsqrc/qt.js

@ -1,49 +0,0 @@
/*
This file is part of ethereum.js.
ethereum.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ethereum.js 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file qt.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2014
*/
(function() {
var QtProvider = function() {
this.handlers = [];
var self = this;
navigator.qt.onmessage = function (message) {
self.handlers.forEach(function (handler) {
handler.call(self, JSON.parse(message.data));
});
}
};
QtProvider.prototype.send = function(payload) {
navigator.qt.postMessage(JSON.stringify(payload));
};
Object.defineProperty(QtProvider.prototype, "onmessage", {
set: function(handler) {
this.handlers.push(handler);
},
});
if(typeof(web3) !== "undefined" && web3.providers !== undefined) {
web3.providers.QtProvider = QtProvider;
}
})();

2
libjsqrc/setup.js

@ -41,4 +41,6 @@ if (window.Promise === undefined) {
window.Promise = ES6Promise.Promise;
}
var web3 = require('web3');
web3.setProvider(new web3.providers.QtProvider());

8
libp2p/Host.cpp

@ -385,7 +385,7 @@ void Host::populateAddresses()
shared_ptr<Node> Host::noteNode(NodeId _id, bi::tcp::endpoint _a, Origin _o, bool _ready, NodeId _oldId)
{
RecursiveGuard l(x_peers);
if (_a.port() < 30300 || _a.port() > 30303)
if (_a.port() < 30300 || _a.port() > 30305)
cwarn << "Weird port being recorded: " << _a.port();
if (_a.port() >= /*49152*/32768)
@ -778,7 +778,7 @@ bytes Host::saveNodes() const
{
Node const& n = *(i.second);
// TODO: PoC-7: Figure out why it ever shares these ports.//n.address.port() >= 30300 && n.address.port() <= 30305 &&
if (!n.dead && n.address.port() > 0 && n.address.port() < /*49152*/32768 && n.id != id() && !isPrivateAddress(n.address.address()))
if (!n.dead && chrono::system_clock::now() - n.lastConnected < chrono::seconds(3600 * 48) && n.address.port() > 0 && n.address.port() < /*49152*/32768 && n.id != id() && !isPrivateAddress(n.address.address()))
{
nodes.appendList(10);
if (n.address.address().is_v4())
@ -786,8 +786,8 @@ bytes Host::saveNodes() const
else
nodes << n.address.address().to_v6().to_bytes();
nodes << n.address.port() << n.id << (int)n.idOrigin
<< std::chrono::duration_cast<std::chrono::seconds>(n.lastConnected.time_since_epoch()).count()
<< std::chrono::duration_cast<std::chrono::seconds>(n.lastAttempted.time_since_epoch()).count()
<< chrono::duration_cast<chrono::seconds>(n.lastConnected.time_since_epoch()).count()
<< chrono::duration_cast<chrono::seconds>(n.lastAttempted.time_since_epoch()).count()
<< n.failedAttempts << (unsigned)n.lastDisconnect << n.score << n.rating;
count++;
}

4
libqethereum/QEthereum.h

@ -83,9 +83,9 @@ private:
{ \
_frame->disconnect(); \
_frame->addToJavaScriptWindowObject("_web3", qweb, QWebFrame::ScriptOwnership); \
_frame->addToJavaScriptWindowObject("env", _env, QWebFrame::QtOwnership); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/es6-promise-2.0.0.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/main.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/qt.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/ethereum.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); \
}

53
libsolidity/AST.cpp

@ -278,6 +278,15 @@ vector<FunctionDefinition const*> ContractDefinition::getInterfaceFunctions() co
return exportedFunctions;
}
void FunctionDefinition::checkTypeRequirements()
{
for (ASTPointer<VariableDeclaration> const& var: getParameters() + getReturnParameters())
if (!var->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
m_body->checkTypeRequirements();
}
void Block::checkTypeRequirements()
{
for (shared_ptr<Statement> const& statement: m_statements)
@ -315,7 +324,7 @@ void Return::checkTypeRequirements()
void VariableDefinition::checkTypeRequirements()
{
// Variables can be declared without type (with "var"), in which case the first assignment
// setsthe type.
// sets the type.
// Note that assignments before the first declaration are legal because of the special scoping
// rules inherited from JavaScript.
if (m_value)
@ -329,13 +338,14 @@ void VariableDefinition::checkTypeRequirements()
m_variable->setType(m_value->getType());
}
}
if (m_variable->getType() && !m_variable->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(m_variable->createTypeError("Type is required to live outside storage."));
}
void Assignment::checkTypeRequirements()
{
m_leftHandSide->checkTypeRequirements();
if (!m_leftHandSide->isLvalue())
BOOST_THROW_EXCEPTION(createTypeError("Expression has to be an lvalue."));
m_leftHandSide->requireLValue();
m_rightHandSide->expectType(*m_leftHandSide->getType());
m_type = m_leftHandSide->getType();
if (m_assigmentOperator != Token::ASSIGN)
@ -359,13 +369,19 @@ void Expression::expectType(Type const& _expectedType)
+ _expectedType.toString() + "."));
}
void Expression::requireLValue()
{
if (!isLvalue())
BOOST_THROW_EXCEPTION(createTypeError("Expression has to be an lvalue."));
m_lvalueRequested = true;
}
void UnaryOperation::checkTypeRequirements()
{
// INC, DEC, ADD, SUB, NOT, BIT_NOT, DELETE
m_subExpression->checkTypeRequirements();
if (m_operator == Token::Value::INC || m_operator == Token::Value::DEC || m_operator == Token::Value::DELETE)
if (!m_subExpression->isLvalue())
BOOST_THROW_EXCEPTION(createTypeError("Expression has to be an lvalue."));
m_subExpression->requireLValue();
m_type = m_subExpression->getType();
if (!m_type->acceptsUnaryOperator(m_operator))
BOOST_THROW_EXCEPTION(createTypeError("Unary operator not compatible with type."));
@ -416,6 +432,8 @@ void FunctionCall::checkTypeRequirements()
}
else
{
m_expression->requireLValue();
//@todo would be nice to create a struct type from the arguments
// and then ask if that is implicitly convertible to the struct represented by the
// function parameters
@ -442,14 +460,30 @@ bool FunctionCall::isTypeConversion() const
void MemberAccess::checkTypeRequirements()
{
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Member access not yet implemented."));
// m_type = ;
m_expression->checkTypeRequirements();
m_expression->requireLValue();
if (m_expression->getType()->getCategory() != Type::Category::STRUCT)
BOOST_THROW_EXCEPTION(createTypeError("Member access to a non-struct (is " +
m_expression->getType()->toString() + ")"));
StructType const& type = dynamic_cast<StructType const&>(*m_expression->getType());
unsigned memberIndex = type.memberNameToIndex(*m_memberName);
if (memberIndex >= type.getMemberCount())
BOOST_THROW_EXCEPTION(createTypeError("Member \"" + *m_memberName + "\" not found in " + type.toString()));
m_type = type.getMemberByIndex(memberIndex).getType();
m_isLvalue = true;
}
void IndexAccess::checkTypeRequirements()
{
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Index access not yet implemented."));
// m_type = ;
m_base->checkTypeRequirements();
m_base->requireLValue();
if (m_base->getType()->getCategory() != Type::Category::MAPPING)
BOOST_THROW_EXCEPTION(m_base->createTypeError("Indexed expression has to be a mapping (is " +
m_base->getType()->toString() + ")"));
MappingType const& type = dynamic_cast<MappingType const&>(*m_base->getType());
m_index->expectType(*type.getKeyType());
m_type = type.getValueType();
m_isLvalue = true;
}
void Identifier::checkTypeRequirements()
@ -481,6 +515,7 @@ void Identifier::checkTypeRequirements()
// Calling a function (e.g. function(12), otherContract.function(34)) does not do a type
// conversion.
m_type = make_shared<FunctionType>(*functionDef);
m_isLvalue = true;
return;
}
ContractDefinition* contractDef = dynamic_cast<ContractDefinition*>(m_referencedDeclaration);

31
libsolidity/AST.h

@ -146,7 +146,7 @@ private:
/**
* Parameter list, used as function parameter list and return list.
* None of the parameters is allowed to contain mappings (not even recursively
* inside structs), but (@todo) this is not yet enforced.
* inside structs).
*/
class ParameterList: public ASTNode
{
@ -186,6 +186,8 @@ public:
void addLocalVariable(VariableDeclaration const& _localVariable) { m_localVariables.push_back(&_localVariable); }
std::vector<VariableDeclaration const*> const& getLocalVariables() const { return m_localVariables; }
/// Checks that all parameters have allowed types and calls checkTypeRequirements on the body.
void checkTypeRequirements();
private:
bool m_isPublic;
ASTPointer<ParameterList> m_parameters;
@ -236,7 +238,7 @@ public:
/// Retrieve the element of the type hierarchy this node refers to. Can return an empty shared
/// pointer until the types have been resolved using the @ref NameAndTypeResolver.
virtual std::shared_ptr<Type> toType() = 0;
virtual std::shared_ptr<Type> toType() const = 0;
};
/**
@ -252,7 +254,7 @@ public:
if (asserts(Token::isElementaryTypeName(_type))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
virtual std::shared_ptr<Type> toType() override { return Type::fromElementaryTypeName(m_type); }
virtual std::shared_ptr<Type> toType() const override { return Type::fromElementaryTypeName(m_type); }
Token::Value getTypeName() const { return m_type; }
@ -270,7 +272,7 @@ public:
UserDefinedTypeName(Location const& _location, ASTPointer<ASTString> const& _name):
TypeName(_location), m_name(_name) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual std::shared_ptr<Type> toType() override { return Type::fromUserDefinedTypeName(*this); }
virtual std::shared_ptr<Type> toType() const override { return Type::fromUserDefinedTypeName(*this); }
ASTString const& getName() const { return *m_name; }
void setReferencedStruct(StructDefinition& _referencedStruct) { m_referencedStruct = &_referencedStruct; }
@ -292,7 +294,10 @@ public:
ASTPointer<TypeName> const& _valueType):
TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual std::shared_ptr<Type> toType() override { return Type::fromMapping(*this); }
virtual std::shared_ptr<Type> toType() const override { return Type::fromMapping(*this); }
ElementaryTypeName const& getKeyType() const { return *m_keyType; }
TypeName const& getValueType() const { return *m_valueType; }
private:
ASTPointer<ElementaryTypeName> m_keyType;
@ -363,7 +368,6 @@ private:
/**
* Statement in which a break statement is legal.
* @todo actually check this requirement.
*/
class BreakableStatement: public Statement
{
@ -481,7 +485,7 @@ private:
class Expression: public ASTNode
{
public:
Expression(Location const& _location): ASTNode(_location), m_isLvalue(false) {}
Expression(Location const& _location): ASTNode(_location), m_isLvalue(false), m_lvalueRequested(false) {}
virtual void checkTypeRequirements() = 0;
std::shared_ptr<Type const> const& getType() const { return m_type; }
@ -490,6 +494,12 @@ public:
/// Helper function, infer the type via @ref checkTypeRequirements and then check that it
/// is implicitly convertible to @a _expectedType. If not, throw exception.
void expectType(Type const& _expectedType);
/// Checks that this expression is an lvalue and also registers that an address and
/// not a value is generated during compilation. Can be called after checkTypeRequirements()
/// by an enclosing expression.
void requireLValue();
/// Returns true if @a requireLValue was previously called on this expression.
bool lvalueRequested() const { return m_lvalueRequested; }
protected:
//! Inferred type of the expression, only filled after a call to checkTypeRequirements().
@ -497,6 +507,8 @@ protected:
//! Whether or not this expression is an lvalue, i.e. something that can be assigned to.
//! This is set during calls to @a checkTypeRequirements()
bool m_isLvalue;
//! Whether the outer expression requested the address (true) or the value (false) of this expression.
bool m_lvalueRequested;
};
/// Assignment, can also be a compound assignment.
@ -543,6 +555,7 @@ public:
Token::Value getOperator() const { return m_operator; }
bool isPrefixOperation() const { return m_isPrefix; }
Expression& getSubExpression() const { return *m_subExpression; }
private:
Token::Value m_operator;
@ -615,6 +628,7 @@ public:
ASTPointer<ASTString> const& _memberName):
Expression(_location), m_expression(_expression), m_memberName(_memberName) {}
virtual void accept(ASTVisitor& _visitor) override;
Expression& getExpression() const { return *m_expression; }
ASTString const& getMemberName() const { return *m_memberName; }
virtual void checkTypeRequirements() override;
@ -635,6 +649,9 @@ public:
virtual void accept(ASTVisitor& _visitor) override;
virtual void checkTypeRequirements() override;
Expression& getBaseExpression() const { return *m_base; }
Expression& getIndexExpression() const { return *m_index; }
private:
ASTPointer<Expression> m_base;
ASTPointer<Expression> m_index;

2
libsolidity/Compiler.cpp

@ -225,7 +225,7 @@ bool Compiler::visit(IfStatement& _ifStatement)
eth::AssemblyItem trueTag = m_context.appendConditionalJump();
if (_ifStatement.getFalseStatement())
_ifStatement.getFalseStatement()->accept(*this);
eth::AssemblyItem endTag = m_context.appendJump();
eth::AssemblyItem endTag = m_context.appendJumpToNew();
m_context << trueTag;
_ifStatement.getTrueStatement().accept(*this);
m_context << endTag;

4
libsolidity/CompilerContext.h

@ -65,7 +65,9 @@ public:
/// Appends a JUMPI instruction to @a _tag
CompilerContext& appendConditionalJumpTo(eth::AssemblyItem const& _tag) { m_asm.appendJumpI(_tag); return *this; }
/// Appends a JUMP to a new tag and @returns the tag
eth::AssemblyItem appendJump() { return m_asm.appendJump().tag(); }
eth::AssemblyItem appendJumpToNew() { return m_asm.appendJump().tag(); }
/// Appends a JUMP to a tag already on the stack
CompilerContext& appendJump() { return *this << eth::Instruction::JUMP; }
/// Appends a JUMP to a specific tag
CompilerContext& appendJumpTo(eth::AssemblyItem const& _tag) { m_asm.appendJump(_tag); return *this; }
/// Appends pushing of a new tag and @returns the new tag.

190
libsolidity/ExpressionCompiler.cpp

@ -22,6 +22,7 @@
#include <utility>
#include <numeric>
#include <libdevcore/Common.h>
#include <libsolidity/AST.h>
#include <libsolidity/ExpressionCompiler.h>
#include <libsolidity/CompilerContext.h>
@ -48,16 +49,21 @@ bool ExpressionCompiler::visit(Assignment& _assignment)
{
_assignment.getRightHandSide().accept(*this);
appendTypeConversion(*_assignment.getRightHandSide().getType(), *_assignment.getType());
m_currentLValue.reset();
_assignment.getLeftHandSide().accept(*this);
if (asserts(m_currentLValue.isValid()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("LValue not retrieved."));
Token::Value op = _assignment.getAssignmentOperator();
if (op != Token::ASSIGN) // compound assignment
{
if (m_currentLValue.storesReferenceOnStack())
m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2;
m_currentLValue.retrieveValue(_assignment, true);
appendOrdinaryBinaryOperatorCode(Token::AssignmentToBinaryOp(op), *_assignment.getType());
else
m_context << eth::Instruction::POP;
}
m_currentLValue.storeValue(_assignment);
m_currentLValue.reset();
storeInLValue(_assignment);
return false;
}
@ -76,23 +82,39 @@ void ExpressionCompiler::endVisit(UnaryOperation& _unaryOperation)
m_context << eth::Instruction::NOT;
break;
case Token::DELETE: // delete
{
// a -> a xor a (= 0).
// @todo semantics change for complex types
m_context << eth::Instruction::DUP1 << eth::Instruction::XOR;
storeInLValue(_unaryOperation);
if (asserts(m_currentLValue.isValid()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("LValue not retrieved."));
m_context << u256(0);
if (m_currentLValue.storesReferenceOnStack())
m_context << eth::Instruction::SWAP1;
m_currentLValue.storeValue(_unaryOperation);
m_currentLValue.reset();
break;
}
case Token::INC: // ++ (pre- or postfix)
case Token::DEC: // -- (pre- or postfix)
if (asserts(m_currentLValue.isValid()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("LValue not retrieved."));
m_currentLValue.retrieveValue(_unaryOperation);
if (!_unaryOperation.isPrefixOperation())
m_context << eth::Instruction::DUP1;
{
if (m_currentLValue.storesReferenceOnStack())
m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2;
else
m_context << eth::Instruction::DUP1;
}
m_context << u256(1);
if (_unaryOperation.getOperator() == Token::INC)
m_context << eth::Instruction::ADD;
else
m_context << eth::Instruction::SWAP1 << eth::Instruction::SUB; // @todo avoid the swap
storeInLValue(_unaryOperation, !_unaryOperation.isPrefixOperation());
// Stack for prefix: [ref] (*ref)+-1
// Stack for postfix: *ref [ref] (*ref)+-1
if (m_currentLValue.storesReferenceOnStack())
m_context << eth::Instruction::SWAP1;
m_currentLValue.storeValue(_unaryOperation, !_unaryOperation.isPrefixOperation());
m_currentLValue.reset();
break;
case Token::ADD: // +
// unary add, so basically no-op
@ -151,12 +173,6 @@ bool ExpressionCompiler::visit(FunctionCall& _functionCall)
{
// Calling convention: Caller pushes return address and arguments
// Callee removes them and pushes return values
m_currentLValue.reset();
_functionCall.getExpression().accept(*this);
if (asserts(m_currentLValue.isInCode()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Code reference expected."));
eth::AssemblyItem functionTag(eth::PushTag, m_currentLValue.location);
FunctionDefinition const& function = dynamic_cast<FunctionType const&>(*_functionCall.getExpression().getType()).getFunction();
eth::AssemblyItem returnLabel = m_context.pushNewTag();
@ -168,8 +184,12 @@ bool ExpressionCompiler::visit(FunctionCall& _functionCall)
arguments[i]->accept(*this);
appendTypeConversion(*arguments[i]->getType(), *function.getParameters()[i]->getType());
}
_functionCall.getExpression().accept(*this);
if (asserts(m_currentLValue.isInCode()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Code reference expected."));
m_currentLValue.reset();
m_context.appendJumpTo(functionTag);
m_context.appendJump();
m_context << returnLabel;
// callee adds return parameters, but removes arguments and return label
@ -183,32 +203,42 @@ bool ExpressionCompiler::visit(FunctionCall& _functionCall)
return false;
}
void ExpressionCompiler::endVisit(MemberAccess&)
void ExpressionCompiler::endVisit(MemberAccess& _memberAccess)
{
if (asserts(m_currentLValue.isInStorage()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Member access to a non-storage value."));
StructType const& type = dynamic_cast<StructType const&>(*_memberAccess.getExpression().getType());
unsigned memberIndex = type.memberNameToIndex(_memberAccess.getMemberName());
if (asserts(memberIndex <= type.getMemberCount()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Member not found in struct during compilation."));
m_context << type.getStorageOffsetOfMember(memberIndex) << eth::Instruction::ADD;
m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess);
}
void ExpressionCompiler::endVisit(IndexAccess&)
bool ExpressionCompiler::visit(IndexAccess& _indexAccess)
{
m_currentLValue.reset();
_indexAccess.getBaseExpression().accept(*this);
if (asserts(m_currentLValue.isInStorage()))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Index access to a non-storage value."));
_indexAccess.getIndexExpression().accept(*this);
appendTypeConversion(*_indexAccess.getIndexExpression().getType(),
*dynamic_cast<MappingType const&>(*_indexAccess.getBaseExpression().getType()).getKeyType(),
true);
// @todo move this once we actually use memory
m_context << u256(32) << eth::Instruction::MSTORE << u256(0) << eth::Instruction::MSTORE;
m_context << u256(64) << u256(0) << eth::Instruction::SHA3;
m_currentLValue = LValue(m_context, LValue::STORAGE);
m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess);
return false;
}
void ExpressionCompiler::endVisit(Identifier& _identifier)
{
Declaration const* declaration = _identifier.getReferencedDeclaration();
if (m_context.isLocalVariable(declaration))
m_currentLValue = LValueLocation(LValueLocation::STACK,
m_context.getBaseStackOffsetOfVariable(*declaration));
else if (m_context.isStateVariable(declaration))
m_currentLValue = LValueLocation(LValueLocation::STORAGE,
m_context.getStorageLocationOfVariable(*declaration));
else if (m_context.isFunctionDefinition(declaration))
m_currentLValue = LValueLocation(LValueLocation::CODE,
m_context.getFunctionEntryLabel(dynamic_cast<FunctionDefinition const&>(*declaration)).data());
else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Identifier type not supported or identifier not found."));
retrieveLValueValue(_identifier);
m_currentLValue.fromDeclaration(_identifier, *_identifier.getReferencedDeclaration());
m_currentLValue.retrieveValueIfLValueNotRequested(_identifier);
}
void ExpressionCompiler::endVisit(Literal& _literal)
@ -371,66 +401,104 @@ void ExpressionCompiler::appendHighBitsCleanup(IntegerType const& _typeOnStack)
m_context << ((u256(1) << _typeOnStack.getNumBits()) - 1) << eth::Instruction::AND;
}
void ExpressionCompiler::retrieveLValueValue(Expression const& _expression)
void ExpressionCompiler::LValue::retrieveValue(Expression const& _expression, bool _remove) const
{
switch (m_currentLValue.locationType)
switch (m_type)
{
case LValueLocation::CODE:
// not stored on the stack
case CODE:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Tried to retrieve value of a function."));
break;
case LValueLocation::STACK:
case STACK:
{
unsigned stackPos = m_context.baseToCurrentStackOffset(unsigned(m_currentLValue.location));
unsigned stackPos = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset));
if (stackPos >= 15) //@todo correct this by fetching earlier or moving to memory
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Stack too deep."));
m_context << eth::dupInstruction(stackPos + 1);
*m_context << eth::dupInstruction(stackPos + 1);
break;
}
case LValueLocation::STORAGE:
m_context << m_currentLValue.location << eth::Instruction::SLOAD;
case STORAGE:
if (!_remove)
*m_context << eth::Instruction::DUP1;
*m_context << eth::Instruction::SLOAD;
break;
case LValueLocation::MEMORY:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Location type not yet implemented."));
case MEMORY:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Location type not yet implemented."));
break;
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unsupported location type."));
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Unsupported location type."));
break;
}
}
void ExpressionCompiler::storeInLValue(Expression const& _expression, bool _move)
void ExpressionCompiler::LValue::storeValue(Expression const& _expression, bool _move) const
{
switch (m_currentLValue.locationType)
switch (m_type)
{
case LValueLocation::STACK:
case STACK:
{
unsigned stackPos = m_context.baseToCurrentStackOffset(unsigned(m_currentLValue.location));
unsigned stackPos = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset));
if (stackPos > 16)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Stack too deep."));
else if (stackPos > 0)
m_context << eth::swapInstruction(stackPos) << eth::Instruction::POP;
*m_context << eth::swapInstruction(stackPos) << eth::Instruction::POP;
if (!_move)
retrieveLValueValue(_expression);
retrieveValue(_expression);
break;
}
case LValueLocation::STORAGE:
case LValue::STORAGE:
if (!_move)
m_context << eth::Instruction::DUP1;
m_context << m_currentLValue.location << eth::Instruction::SSTORE;
*m_context << eth::Instruction::DUP2 << eth::Instruction::SWAP1;
*m_context << eth::Instruction::SSTORE;
break;
case LValueLocation::CODE:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Location type does not support assignment."));
case LValue::CODE:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Location type does not support assignment."));
break;
case LValueLocation::MEMORY:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Location type not yet implemented."));
case LValue::MEMORY:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Location type not yet implemented."));
break;
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unsupported location type."));
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Unsupported location type."));
break;
}
}
void ExpressionCompiler::LValue::retrieveValueIfLValueNotRequested(const Expression& _expression)
{
if (!_expression.lvalueRequested())
{
retrieveValue(_expression, true);
reset();
}
}
void ExpressionCompiler::LValue::fromDeclaration( Expression const& _expression, Declaration const& _declaration)
{
if (m_context->isLocalVariable(&_declaration))
{
m_type = STACK;
m_baseStackOffset = m_context->getBaseStackOffsetOfVariable(_declaration);
}
else if (m_context->isStateVariable(&_declaration))
{
m_type = STORAGE;
*m_context << m_context->getStorageLocationOfVariable(_declaration);
}
else if (m_context->isFunctionDefinition(&_declaration))
{
m_type = CODE;
*m_context << m_context->getFunctionEntryLabel(dynamic_cast<FunctionDefinition const&>(_declaration)).pushTag();
}
else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Identifier type not supported or identifier not found."));
}
}
}

77
libsolidity/ExpressionCompiler.h

@ -20,6 +20,7 @@
* Solidity AST to EVM bytecode compiler for expressions.
*/
#include <boost/noncopyable.hpp>
#include <libdevcore/Common.h>
#include <libsolidity/ASTVisitor.h>
@ -49,14 +50,15 @@ public:
static void appendTypeConversion(CompilerContext& _context, Type const& _typeOnStack, Type const& _targetType);
private:
ExpressionCompiler(CompilerContext& _compilerContext): m_context(_compilerContext) {}
ExpressionCompiler(CompilerContext& _compilerContext):
m_context(_compilerContext), m_currentLValue(m_context) {}
virtual bool visit(Assignment& _assignment) override;
virtual void endVisit(UnaryOperation& _unaryOperation) override;
virtual bool visit(BinaryOperation& _binaryOperation) override;
virtual bool visit(FunctionCall& _functionCall) override;
virtual void endVisit(MemberAccess& _memberAccess) override;
virtual void endVisit(IndexAccess& _indexAccess) override;
virtual bool visit(IndexAccess& _indexAccess) override;
virtual void endVisit(Identifier& _identifier) override;
virtual void endVisit(Literal& _literal) override;
@ -79,37 +81,58 @@ private:
//// Appends code that cleans higher-order bits for integer types.
void appendHighBitsCleanup(IntegerType const& _typeOnStack);
/// Copies the value of the current lvalue to the top of the stack.
void retrieveLValueValue(Expression const& _expression);
/// Stores the value on top of the stack in the current lvalue. Removes it from the stack if
/// @a _move is true.
void storeInLValue(Expression const& _expression, bool _move = false);
/**
* Location of an lvalue, either in code (for a function) on the stack, in the storage or memory.
* Helper class to store and retrieve lvalues to and from various locations.
* All types except STACK store a reference in a slot on the stack, STACK just stores the
* base stack offset of the variable in @a m_baseStackOffset.
*/
struct LValueLocation
class LValue
{
enum LocationType { INVALID, CODE, STACK, MEMORY, STORAGE };
LValueLocation() { reset(); }
LValueLocation(LocationType _type, u256 const& _location): locationType(_type), location(_location) {}
void reset() { locationType = INVALID; location = 0; }
bool isValid() const { return locationType != INVALID; }
bool isInCode() const { return locationType == CODE; }
bool isInOnStack() const { return locationType == STACK; }
bool isInMemory() const { return locationType == MEMORY; }
bool isInStorage() const { return locationType == STORAGE; }
LocationType locationType;
/// Depending on the type, this is the id of a tag (code), the base offset of a stack
/// variable (@see CompilerContext::getBaseStackOffsetOfVariable) or the offset in
/// storage or memory.
u256 location;
public:
enum LValueType { NONE, CODE, STACK, MEMORY, STORAGE };
explicit LValue(CompilerContext& _compilerContext): m_context(&_compilerContext) { reset(); }
LValue(CompilerContext& _compilerContext, LValueType _type, unsigned _baseStackOffset = 0):
m_context(&_compilerContext), m_type(_type), m_baseStackOffset(_baseStackOffset) {}
/// Set type according to the declaration and retrieve the reference.
/// @a _expression is the current expression, used for error reporting.
void fromDeclaration(Expression const& _expression, Declaration const& _declaration);
void reset() { m_type = NONE; m_baseStackOffset = 0; }
bool isValid() const { return m_type != NONE; }
bool isInCode() const { return m_type == CODE; }
bool isInOnStack() const { return m_type == STACK; }
bool isInMemory() const { return m_type == MEMORY; }
bool isInStorage() const { return m_type == STORAGE; }
/// @returns true if this lvalue reference type occupies a slot on the stack.
bool storesReferenceOnStack() const { return m_type == STORAGE || m_type == MEMORY || m_type == CODE; }
/// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true,
/// also removes the reference from the stack (note that is does not reset the type to @a NONE).
/// @a _expression is the current expression, used for error reporting.
void retrieveValue(Expression const& _expression, bool _remove = false) const;
/// Stores a value (from the stack directly beneath the reference, which is assumed to
/// be on the top of the stack, if any) in the lvalue and removes the reference.
/// Also removes the stored value from the stack if @a _move is
/// true. @a _expression is the current expression, used for error reporting.
void storeValue(Expression const& _expression, bool _move = false) const;
/// Convenience function to convert the stored reference to a value and reset type to NONE if
/// the reference was not requested by @a _expression.
void retrieveValueIfLValueNotRequested(Expression const& _expression);
private:
CompilerContext* m_context;
LValueType m_type;
/// If m_type is STACK, this is base stack offset (@see
/// CompilerContext::getBaseStackOffsetOfVariable) of a local variable.
unsigned m_baseStackOffset;
};
LValueLocation m_currentLValue;
CompilerContext& m_context;
LValue m_currentLValue;
};

34
libsolidity/NameAndTypeResolver.cpp

@ -37,7 +37,10 @@ void NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
reset();
DeclarationRegistrationHelper registrar(m_scopes, _contract);
m_currentScope = &m_scopes[&_contract];
//@todo structs
for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs())
ReferencesResolver resolver(*structDef, *this, nullptr);
for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs())
checkForRecursion(*structDef);
for (ASTPointer<VariableDeclaration> const& variable: _contract.getStateVariables())
ReferencesResolver resolver(*variable, *this, nullptr);
for (ASTPointer<FunctionDefinition> const& function: _contract.getDefinedFunctions())
@ -52,7 +55,7 @@ void NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
for (ASTPointer<FunctionDefinition> const& function: _contract.getDefinedFunctions())
{
m_currentScope = &m_scopes[function.get()];
function->getBody().checkTypeRequirements();
function->checkTypeRequirements();
}
m_currentScope = &m_scopes[nullptr];
}
@ -70,6 +73,24 @@ Declaration* NameAndTypeResolver::getNameFromCurrentScope(ASTString const& _name
return m_currentScope->resolveName(_name, _recursive);
}
void NameAndTypeResolver::checkForRecursion(StructDefinition const& _struct)
{
set<StructDefinition const*> definitionsSeen;
vector<StructDefinition const*> queue = {&_struct};
while (!queue.empty())
{
StructDefinition const* def = queue.back();
queue.pop_back();
if (definitionsSeen.count(def))
BOOST_THROW_EXCEPTION(ParserError() << errinfo_sourceLocation(def->getLocation())
<< errinfo_comment("Recursive struct definition."));
definitionsSeen.insert(def);
for (ASTPointer<VariableDeclaration> const& member: def->getMembers())
if (member->getType()->getCategory() == Type::Category::STRUCT)
queue.push_back(dynamic_cast<UserDefinedTypeName&>(*member->getTypeName()).getReferencedStruct());
}
}
void NameAndTypeResolver::reset()
{
m_scopes.clear();
@ -163,8 +184,8 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio
}
ReferencesResolver::ReferencesResolver(ASTNode& _root, NameAndTypeResolver& _resolver,
ParameterList* _returnParameters):
m_resolver(_resolver), m_returnParameters(_returnParameters)
ParameterList* _returnParameters, bool _allowLazyTypes):
m_resolver(_resolver), m_returnParameters(_returnParameters), m_allowLazyTypes(_allowLazyTypes)
{
_root.accept(*this);
}
@ -175,6 +196,8 @@ void ReferencesResolver::endVisit(VariableDeclaration& _variable)
// or mapping
if (_variable.getTypeName())
_variable.setType(_variable.getTypeName()->toType());
else if (!m_allowLazyTypes)
BOOST_THROW_EXCEPTION(_variable.createTypeError("Explicit type needed."));
// otherwise we have a "var"-declaration whose type is resolved by the first assignment
}
@ -186,9 +209,8 @@ bool ReferencesResolver::visit(Return& _return)
return true;
}
bool ReferencesResolver::visit(Mapping&)
bool ReferencesResolver::visit(Mapping& _mapping)
{
// @todo
return true;
}

11
libsolidity/NameAndTypeResolver.h

@ -55,10 +55,13 @@ public:
Declaration* getNameFromCurrentScope(ASTString const& _name, bool _recursive = true);
private:
/// Throws if @a _struct contains a recursive loop. Note that recursion via mappings is fine.
void checkForRecursion(StructDefinition const& _struct);
void reset();
/// Maps nodes declaring a scope to scopes, i.e. ContractDefinition, FunctionDeclaration and
/// StructDefinition (@todo not yet implemented), where nullptr denotes the global scope.
/// Maps nodes declaring a scope to scopes, i.e. ContractDefinition and FunctionDeclaration,
/// where nullptr denotes the global scope. Note that structs are not scope since they do
/// not contain code.
std::map<ASTNode const*, Scope> m_scopes;
Scope* m_currentScope;
@ -99,7 +102,8 @@ private:
class ReferencesResolver: private ASTVisitor
{
public:
ReferencesResolver(ASTNode& _root, NameAndTypeResolver& _resolver, ParameterList* _returnParameters);
ReferencesResolver(ASTNode& _root, NameAndTypeResolver& _resolver,
ParameterList* _returnParameters, bool _allowLazyTypes = true);
private:
virtual void endVisit(VariableDeclaration& _variable) override;
@ -110,6 +114,7 @@ private:
NameAndTypeResolver& m_resolver;
ParameterList* m_returnParameters;
bool m_allowLazyTypes;
};
}

61
libsolidity/Types.cpp

@ -63,9 +63,11 @@ shared_ptr<Type> Type::fromUserDefinedTypeName(UserDefinedTypeName const& _typeN
return make_shared<StructType>(*_typeName.getReferencedStruct());
}
shared_ptr<Type> Type::fromMapping(Mapping const&)
shared_ptr<Type> Type::fromMapping(Mapping const& _typeName)
{
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Mapping types not yet implemented."));
shared_ptr<Type const> keyType = _typeName.getKeyType().toType();
shared_ptr<Type const> valueType = _typeName.getValueType().toType();
return make_shared<MappingType>(keyType, valueType);
}
shared_ptr<Type> Type::forLiteral(Literal const& _literal)
@ -78,7 +80,7 @@ shared_ptr<Type> Type::forLiteral(Literal const& _literal)
case Token::NUMBER:
return IntegerType::smallestTypeForLiteral(_literal.getValue());
case Token::STRING_LITERAL:
return shared_ptr<Type>(); // @todo
return shared_ptr<Type>(); // @todo add string literals
default:
return shared_ptr<Type>();
}
@ -229,6 +231,48 @@ u256 StructType::getStorageSize() const
return max<u256>(1, size);
}
bool StructType::canLiveOutsideStorage() const
{
for (unsigned i = 0; i < getMemberCount(); ++i)
if (!getMemberByIndex(i).getType()->canLiveOutsideStorage())
return false;
return true;
}
string StructType::toString() const
{
return string("struct ") + m_struct.getName();
}
unsigned StructType::getMemberCount() const
{
return m_struct.getMembers().size();
}
unsigned StructType::memberNameToIndex(string const& _name) const
{
vector<ASTPointer<VariableDeclaration>> const& members = m_struct.getMembers();
for (unsigned index = 0; index < members.size(); ++index)
if (members[index]->getName() == _name)
return index;
return unsigned(-1);
}
VariableDeclaration const& StructType::getMemberByIndex(unsigned _index) const
{
return *m_struct.getMembers()[_index];
}
u256 StructType::getStorageOffsetOfMember(unsigned _index) const
{
//@todo cache member offset?
u256 offset;
vector<ASTPointer<VariableDeclaration>> const& members = m_struct.getMembers();
for (unsigned index = 0; index < _index; ++index)
offset += getMemberByIndex(index).getType()->getStorageSize();
return offset;
}
bool FunctionType::operator==(Type const& _other) const
{
if (_other.getCategory() != getCategory())
@ -237,6 +281,12 @@ bool FunctionType::operator==(Type const& _other) const
return other.m_function == m_function;
}
string FunctionType::toString() const
{
//@todo nice string for function types
return "function(...)returns(...)";
}
bool MappingType::operator==(Type const& _other) const
{
if (_other.getCategory() != getCategory())
@ -245,6 +295,11 @@ bool MappingType::operator==(Type const& _other) const
return *other.m_keyType == *m_keyType && *other.m_valueType == *m_valueType;
}
string MappingType::toString() const
{
return "mapping(" + getKeyType()->toString() + " => " + getValueType()->toString() + ")";
}
bool TypeType::operator==(Type const& _other) const
{
if (_other.getCategory() != getCategory())

27
libsolidity/Types.h

@ -35,7 +35,7 @@ namespace dev
namespace solidity
{
// @todo realMxN, string<N>, mapping
// @todo realMxN, string<N>
/**
* Abstract base class that forms the root of the type hierarchy.
@ -78,6 +78,8 @@ public:
/// @returns number of bytes required to hold this value in storage.
/// For dynamically "allocated" types, it returns the size of the statically allocated head,
virtual u256 getStorageSize() const { return 1; }
/// Returns false if the type cannot live outside the storage, i.e. if it includes some mapping.
virtual bool canLiveOutsideStorage() const { return true; }
virtual std::string toString() const = 0;
virtual u256 literalValue(Literal const&) const
@ -182,7 +184,14 @@ public:
virtual bool operator==(Type const& _other) const override;
virtual u256 getStorageSize() const;
virtual std::string toString() const override { return "struct{...}"; }
virtual bool canLiveOutsideStorage() const;
virtual std::string toString() const override;
unsigned getMemberCount() const;
/// Returns the index of the member with name @a _name or unsigned(-1) if it does not exist.
unsigned memberNameToIndex(std::string const& _name) const;
VariableDeclaration const& getMemberByIndex(unsigned _index) const;
u256 getStorageOffsetOfMember(unsigned _index) const;
private:
StructDefinition const& m_struct;
@ -200,8 +209,9 @@ public:
FunctionDefinition const& getFunction() const { return m_function; }
virtual bool operator==(Type const& _other) const override;
virtual std::string toString() const override { return "function(...)returns(...)"; }
virtual std::string toString() const override;
virtual u256 getStorageSize() const { BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Storage size of non-storable function type requested.")); }
virtual bool canLiveOutsideStorage() const { return false; }
private:
FunctionDefinition const& m_function;
@ -214,10 +224,15 @@ class MappingType: public Type
{
public:
virtual Category getCategory() const override { return Category::MAPPING; }
MappingType() {}
MappingType(std::shared_ptr<Type const> _keyType, std::shared_ptr<Type const> _valueType):
m_keyType(_keyType), m_valueType(_valueType) {}
virtual bool operator==(Type const& _other) const override;
virtual std::string toString() const override { return "mapping(...=>...)"; }
virtual std::string toString() const override;
virtual bool canLiveOutsideStorage() const { return false; }
std::shared_ptr<Type const> getKeyType() const { return m_keyType; }
std::shared_ptr<Type const> getValueType() const { return m_valueType; }
private:
std::shared_ptr<Type const> m_keyType;
@ -236,6 +251,7 @@ public:
virtual std::string toString() const override { return "void"; }
virtual u256 getStorageSize() const { BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Storage size of non-storable void type requested.")); }
virtual bool canLiveOutsideStorage() const { return false; }
};
/**
@ -252,6 +268,7 @@ public:
virtual bool operator==(Type const& _other) const override;
virtual u256 getStorageSize() const { BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Storage size of non-storable type type requested.")); }
virtual bool canLiveOutsideStorage() const { return false; }
virtual std::string toString() const override { return "type(" + m_actualType->toString() + ")"; }
private:

2
libweb3jsonrpc/CMakeLists.txt

@ -18,6 +18,8 @@ endif()
target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} secp256k1)
target_link_libraries(${EXECUTABLE} gmp)
target_link_libraries(${EXECUTABLE} solidity)
target_link_libraries(${EXECUTABLE} serpent)
if(MINIUPNPC_LS)
target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS})
endif()

257
libweb3jsonrpc/WebThreeStubServer.cpp

@ -31,6 +31,10 @@
#include <libdevcrypto/FileSystem.h>
#include <libwhisper/Message.h>
#include <libwhisper/WhisperHost.h>
#include <libsolidity/CompilerStack.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/SourceReferenceFormatter.h>
#include <libserpent/funcs.h>
using namespace std;
using namespace dev;
@ -55,34 +59,6 @@ static Json::Value toJson(dev::eth::BlockInfo const& _bi)
return res;
}
static Json::Value toJson(dev::eth::PastMessage const& _t)
{
Json::Value res;
res["input"] = jsFromBinary(_t.input);
res["output"] = jsFromBinary(_t.output);
res["to"] = toJS(_t.to);
res["from"] = toJS(_t.from);
res["value"] = jsToDecimal(toJS(_t.value));
res["origin"] = toJS(_t.origin);
res["timestamp"] = toJS(_t.timestamp);
res["coinbase"] = toJS(_t.coinbase);
res["block"] = toJS(_t.block);
Json::Value path;
for (int i: _t.path)
path.append(i);
res["path"] = path;
res["number"] = (int)_t.number;
return res;
}
static Json::Value toJson(dev::eth::PastMessages const& _pms)
{
Json::Value res;
for (dev::eth::PastMessage const& t: _pms)
res.append(toJson(t));
return res;
}
static Json::Value toJson(dev::eth::Transaction const& _t)
{
Json::Value res;
@ -107,7 +83,7 @@ static Json::Value toJson(dev::eth::LogEntry const& _e)
return res;
}
/*static*/ Json::Value toJson(dev::eth::LogEntries const& _es) // commented to avoid warning. Uncomment once in use @ poC-7.
static Json::Value toJson(dev::eth::LogEntries const& _es) // commented to avoid warning. Uncomment once in use @ poC-7.
{
Json::Value res;
for (dev::eth::LogEntry const& e: _es)
@ -115,81 +91,38 @@ static Json::Value toJson(dev::eth::LogEntry const& _e)
return res;
}
static dev::eth::MessageFilter toMessageFilter(Json::Value const& _json)
static Json::Value toJson(std::map<u256, u256> const& _storage)
{
dev::eth::MessageFilter filter;
if (!_json.isObject() || _json.empty())
return filter;
if (!_json["earliest"].empty())
filter.withEarliest(_json["earliest"].asInt());
if (!_json["latest"].empty())
filter.withLatest(_json["lastest"].asInt());
if (!_json["max"].empty())
filter.withMax(_json["max"].asInt());
if (!_json["skip"].empty())
filter.withSkip(_json["skip"].asInt());
if (!_json["from"].empty())
{
if (_json["from"].isArray())
for (auto i : _json["from"])
filter.from(jsToAddress(i.asString()));
else
filter.from(jsToAddress(_json["from"].asString()));
}
if (!_json["to"].empty())
{
if (_json["to"].isArray())
for (auto i : _json["to"])
filter.to(jsToAddress(i.asString()));
else
filter.to(jsToAddress(_json["to"].asString()));
}
if (!_json["altered"].empty())
{
if (_json["altered"].isArray())
for (auto i: _json["altered"])
if (i.isObject())
filter.altered(jsToAddress(i["id"].asString()), jsToU256(i["at"].asString()));
else
filter.altered((jsToAddress(i.asString())));
else if (_json["altered"].isObject())
filter.altered(jsToAddress(_json["altered"]["id"].asString()), jsToU256(_json["altered"]["at"].asString()));
else
filter.altered(jsToAddress(_json["altered"].asString()));
}
return filter;
Json::Value res(Json::objectValue);
for (auto i: _storage)
res[toJS(i.first)] = toJS(i.second);
return res;
}
/*static*/ dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to avoid warning. Uncomment once in use @ PoC-7.
static dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to avoid warning. Uncomment once in use @ PoC-7.
{
dev::eth::LogFilter filter;
if (!_json.isObject() || _json.empty())
return filter;
if (!_json["earliest"].empty())
if (_json["earliest"].isInt())
filter.withEarliest(_json["earliest"].asInt());
if (!_json["latest"].empty())
if (_json["latest"].isInt())
filter.withLatest(_json["lastest"].asInt());
if (!_json["max"].empty())
if (_json["max"].isInt())
filter.withMax(_json["max"].asInt());
if (!_json["skip"].empty())
if (_json["skip"].isInt())
filter.withSkip(_json["skip"].asInt());
if (!_json["from"].empty())
{
if (_json["from"].isArray())
for (auto i : _json["from"])
filter.from(jsToAddress(i.asString()));
else
filter.from(jsToAddress(_json["from"].asString()));
}
if (!_json["address"].empty())
{
if (_json["address"].isArray())
{
for (auto i : _json["address"])
filter.address(jsToAddress(i.asString()));
else
filter.from(jsToAddress(_json["address"].asString()));
if (i.isString())
filter.address(jsToAddress(i.asString()));
}
else if (_json["address"].isString())
filter.address(jsToAddress(_json["address"].asString()));
}
if (!_json["topics"].empty())
{
@ -208,11 +141,11 @@ static dev::eth::MessageFilter toMessageFilter(Json::Value const& _json)
static shh::Message toMessage(Json::Value const& _json)
{
shh::Message ret;
if (!_json["from"].empty())
if (_json["from"].isString())
ret.setFrom(jsToPublic(_json["from"].asString()));
if (!_json["to"].empty())
if (_json["to"].isString())
ret.setTo(jsToPublic(_json["to"].asString()));
if (!_json["payload"].empty())
if (_json["payload"].isString())
ret.setPayload(jsToBytes(_json["payload"].asString()));
return ret;
}
@ -223,9 +156,9 @@ static shh::Envelope toSealed(Json::Value const& _json, shh::Message const& _m,
unsigned workToProve = 50;
shh::BuildTopic bt;
if (!_json["ttl"].empty())
if (_json["ttl"].isInt())
ttl = _json["ttl"].asInt();
if (!_json["workToProve"].empty())
if (_json["workToProve"].isInt())
workToProve = _json["workToProve"].asInt();
if (!_json["topic"].empty())
{
@ -233,17 +166,18 @@ static shh::Envelope toSealed(Json::Value const& _json, shh::Message const& _m,
bt.shift(jsToBytes(_json["topic"].asString()));
else if (_json["topic"].isArray())
for (auto i: _json["topic"])
bt.shift(jsToBytes(i.asString()));
if (i.isString())
bt.shift(jsToBytes(i.asString()));
}
return _m.seal(_from, bt, ttl, workToProve);
}
static pair<shh::TopicMask, Public> toWatch(Json::Value const& _json)
{
shh::BuildTopicMask bt(shh::BuildTopicMask::Empty);
shh::BuildTopicMask bt;
Public to;
if (!_json["to"].empty())
if (_json["to"].isString())
to = jsToPublic(_json["to"].asString());
if (!_json["topic"].empty())
@ -252,12 +186,8 @@ static pair<shh::TopicMask, Public> toWatch(Json::Value const& _json)
bt.shift(jsToBytes(_json["topic"].asString()));
else if (_json["topic"].isArray())
for (auto i: _json["topic"])
{
if (i.isString())
bt.shift(jsToBytes(i.asString()));
else
bt.shift();
}
}
return make_pair(bt.toTopicMask(), to);
}
@ -355,33 +285,42 @@ static TransactionSkeleton toTransaction(Json::Value const& _json)
if (!_json.isObject() || _json.empty())
return ret;
if (!_json["from"].empty())
if (_json["from"].isString())
ret.from = jsToAddress(_json["from"].asString());
if (!_json["to"].empty())
if (_json["to"].isString())
ret.to = jsToAddress(_json["to"].asString());
if (!_json["value"].empty())
ret.value = jsToU256(_json["value"].asString());
{
if (_json["value"].isString())
ret.value = jsToU256(_json["value"].asString());
else if (_json["value"].isInt())
ret.value = u256(_json["value"].asInt());
}
if (!_json["gas"].empty())
ret.gas = jsToU256(_json["gas"].asString());
{
if (_json["gas"].isString())
ret.gas = jsToU256(_json["gas"].asString());
else if (_json["gas"].isInt())
ret.gas = u256(_json["gas"].asInt());
}
if (!_json["gasPrice"].empty())
ret.gasPrice = jsToU256(_json["gasPrice"].asString());
if (!_json["data"].empty() || _json["code"].empty() || _json["dataclose"].empty())
{
if (_json["data"].isString())
if (_json["gasPrice"].isString())
ret.gasPrice = jsToU256(_json["gasPrice"].asString());
else if (_json["gasPrice"].isInt())
ret.gas = u256(_json["gas"].asInt());
}
if (!_json["data"].empty())
{
if (_json["data"].isString()) // ethereum.js has preconstructed the data array
ret.data = jsToBytes(_json["data"].asString());
else if (_json["code"].isString())
ret.data = jsToBytes(_json["code"].asString());
else if (_json["data"].isArray())
else if (_json["data"].isArray()) // old style: array of 32-byte-padded values. TODO: remove PoC-8
for (auto i: _json["data"])
dev::operator +=(ret.data, jsToBytes(jsPadded(i.asString(), 32)));
else if (_json["code"].isArray())
for (auto i: _json["code"])
dev::operator +=(ret.data, jsToBytes(jsPadded(i.asString(), 32)));
else if (_json["dataclose"].isArray())
for (auto i: _json["dataclose"])
dev::operator +=(ret.data, jsToBytes(i.asString()));
dev::operator +=(ret.data, padded(jsToBytes(i.asString()), 32));
}
if (_json["code"].isString())
ret.data = jsToBytes(_json["code"].asString());
return ret;
}
@ -451,11 +390,18 @@ std::string WebThreeStubServer::db_get(std::string const& _name, std::string con
return toJS(dev::asBytes(ret));
}
Json::Value WebThreeStubServer::eth_getMessages(int const& _id)
Json::Value WebThreeStubServer::eth_filterLogs(int const& _id)
{
if (!client())
return Json::Value(Json::arrayValue);
return toJson(client()->logs(_id));
}
Json::Value WebThreeStubServer::eth_logs(Json::Value const& _json)
{
if (!client())
return Json::Value();
return toJson(client()->messages(_id));
return Json::Value(Json::arrayValue);
return toJson(client()->logs(toLogFilter(_json)));
}
std::string WebThreeStubServer::db_getString(std::string const& _name, std::string const& _key)
@ -486,7 +432,8 @@ int WebThreeStubServer::eth_newFilter(Json::Value const& _json)
unsigned ret = -1;
if (!client())
return ret;
ret = client()->installWatch(toMessageFilter(_json));
// ret = client()->installWatch(toMessageFilter(_json));
ret = client()->installWatch(toLogFilter(_json));
return ret;
}
@ -511,20 +458,67 @@ std::string WebThreeStubServer::shh_newGroup(std::string const& _id, std::string
std::string WebThreeStubServer::shh_newIdentity()
{
cnote << this << m_ids;
// cnote << this << m_ids;
KeyPair kp = KeyPair::create();
m_ids[kp.pub()] = kp.secret();
return toJS(kp.pub());
}
std::string WebThreeStubServer::eth_compile(string const& _s)
Json::Value WebThreeStubServer::eth_compilers()
{
Json::Value ret(Json::arrayValue);
ret.append("lll");
ret.append("solidity");
ret.append("serpent");
return ret;
}
std::string WebThreeStubServer::eth_lll(std::string const& _code)
{
string res;
vector<string> errors;
res = toJS(dev::eth::compileLLL(_code, true, &errors));
cwarn << "LLL compilation errors: " << errors;
return res;
}
std::string WebThreeStubServer::eth_serpent(std::string const& _code)
{
return toJS(dev::eth::compileLLL(_s));
string res;
try
{
res = toJS(dev::asBytes(::compile(_code)));
}
catch (string err)
{
cwarn << "Solidity compilation error: " << err;
}
catch (...)
{
cwarn << "Uncought serpent compilation exception";
}
return res;
}
std::string WebThreeStubServer::eth_lll(string const& _s)
std::string WebThreeStubServer::eth_solidity(std::string const& _code)
{
return toJS(dev::eth::compileLLL(_s));
string res;
dev::solidity::CompilerStack compiler;
try
{
res = toJS(compiler.compile(_code, true));
}
catch (dev::Exception const& exception)
{
ostringstream error;
solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", compiler.getScanner());
cwarn << "Solidity compilation error: " << error.str();
}
catch (...)
{
cwarn << "Uncought solidity compilation exception";
}
return res;
}
int WebThreeStubServer::eth_number()
@ -539,7 +533,7 @@ int WebThreeStubServer::eth_peerCount()
bool WebThreeStubServer::shh_post(Json::Value const& _json)
{
cnote << this << m_ids;
// cnote << this << m_ids;
shh::Message m = toMessage(_json);
Secret from;
@ -651,6 +645,13 @@ std::string WebThreeStubServer::eth_stateAt(string const& _address, string const
return client() ? toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), block)) : "";
}
Json::Value WebThreeStubServer::eth_storageAt(string const& _address)
{
if (!client())
return Json::Value(Json::objectValue);
return toJson(client()->storageAt(jsToAddress(_address)));
}
std::string WebThreeStubServer::eth_transact(Json::Value const& _json)
{
std::string ret;

8
libweb3jsonrpc/WebThreeStubServer.h

@ -72,11 +72,12 @@ public:
virtual bool eth_changed(int const& _id);
virtual std::string eth_codeAt(std::string const& _address);
virtual std::string eth_coinbase();
virtual std::string eth_compile(std::string const& _s);
virtual Json::Value eth_compilers();
virtual double eth_countAt(std::string const& _address);
virtual int eth_defaultBlock();
virtual std::string eth_gasPrice();
virtual Json::Value eth_getMessages(int const& _id);
virtual Json::Value eth_filterLogs(int const& _id);
virtual Json::Value eth_logs(Json::Value const& _json);
virtual bool eth_listening();
virtual bool eth_mining();
virtual int eth_newFilter(Json::Value const& _json);
@ -87,8 +88,11 @@ public:
virtual bool eth_setDefaultBlock(int const& _block);
virtual bool eth_setListening(bool const& _listening);
virtual std::string eth_lll(std::string const& _s);
virtual std::string eth_serpent(std::string const& _s);
virtual bool eth_setMining(bool const& _mining);
virtual std::string eth_solidity(std::string const& _code);
virtual std::string eth_stateAt(std::string const& _address, std::string const& _storage);
virtual Json::Value eth_storageAt(std::string const& _address);
virtual std::string eth_transact(Json::Value const& _json);
virtual Json::Value eth_transactionByHash(std::string const& _hash, int const& _i);
virtual Json::Value eth_transactionByNumber(int const& _number, int const& _i);

48
libweb3jsonrpc/abstractwebthreestubserver.h

@ -25,23 +25,27 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("eth_changed", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_changedI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_coinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_compile", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_compilers", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_compilersI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_defaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_filterLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_filterLogsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_getMessages", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_getMessagesI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_lll", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_lllI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_logs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_logsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_newFilterString", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_newFilterStringI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_number", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_numberI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_peerCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_peerCountI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_serpent", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_serpentI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_setCoinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_setCoinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_setDefaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_setDefaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_setListening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_setListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_setMining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_solidity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_solidityI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_stateAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_storageAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_storageAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_transact", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_transactI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_transactionByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_transactionByHashI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_transactionByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_transactionByNumberI);
@ -119,9 +123,9 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_coinbase();
}
inline virtual void eth_compileI(const Json::Value& request, Json::Value& response)
inline virtual void eth_compilersI(const Json::Value& request, Json::Value& response)
{
response = this->eth_compile(request[0u].asString());
response = this->eth_compilers();
}
inline virtual void eth_countAtI(const Json::Value& request, Json::Value& response)
@ -134,14 +138,14 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_defaultBlock();
}
inline virtual void eth_gasPriceI(const Json::Value& request, Json::Value& response)
inline virtual void eth_filterLogsI(const Json::Value& request, Json::Value& response)
{
response = this->eth_gasPrice();
response = this->eth_filterLogs(request[0u].asInt());
}
inline virtual void eth_getMessagesI(const Json::Value& request, Json::Value& response)
inline virtual void eth_gasPriceI(const Json::Value& request, Json::Value& response)
{
response = this->eth_getMessages(request[0u].asInt());
response = this->eth_gasPrice();
}
inline virtual void eth_listeningI(const Json::Value& request, Json::Value& response)
@ -154,6 +158,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_lll(request[0u].asString());
}
inline virtual void eth_logsI(const Json::Value& request, Json::Value& response)
{
response = this->eth_logs(request[0u]);
}
inline virtual void eth_miningI(const Json::Value& request, Json::Value& response)
{
response = this->eth_mining();
@ -179,6 +188,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_peerCount();
}
inline virtual void eth_serpentI(const Json::Value& request, Json::Value& response)
{
response = this->eth_serpent(request[0u].asString());
}
inline virtual void eth_setCoinbaseI(const Json::Value& request, Json::Value& response)
{
response = this->eth_setCoinbase(request[0u].asString());
@ -199,11 +213,21 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_setMining(request[0u].asBool());
}
inline virtual void eth_solidityI(const Json::Value& request, Json::Value& response)
{
response = this->eth_solidity(request[0u].asString());
}
inline virtual void eth_stateAtI(const Json::Value& request, Json::Value& response)
{
response = this->eth_stateAt(request[0u].asString(), request[1u].asString());
}
inline virtual void eth_storageAtI(const Json::Value& request, Json::Value& response)
{
response = this->eth_storageAt(request[0u].asString());
}
inline virtual void eth_transactI(const Json::Value& request, Json::Value& response)
{
response = this->eth_transact(request[0u]);
@ -287,23 +311,27 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual bool eth_changed(const int& param1) = 0;
virtual std::string eth_codeAt(const std::string& param1) = 0;
virtual std::string eth_coinbase() = 0;
virtual std::string eth_compile(const std::string& param1) = 0;
virtual Json::Value eth_compilers() = 0;
virtual double eth_countAt(const std::string& param1) = 0;
virtual int eth_defaultBlock() = 0;
virtual Json::Value eth_filterLogs(const int& param1) = 0;
virtual std::string eth_gasPrice() = 0;
virtual Json::Value eth_getMessages(const int& param1) = 0;
virtual bool eth_listening() = 0;
virtual std::string eth_lll(const std::string& param1) = 0;
virtual Json::Value eth_logs(const Json::Value& param1) = 0;
virtual bool eth_mining() = 0;
virtual int eth_newFilter(const Json::Value& param1) = 0;
virtual int eth_newFilterString(const std::string& param1) = 0;
virtual int eth_number() = 0;
virtual int eth_peerCount() = 0;
virtual std::string eth_serpent(const std::string& param1) = 0;
virtual bool eth_setCoinbase(const std::string& param1) = 0;
virtual bool eth_setDefaultBlock(const int& param1) = 0;
virtual bool eth_setListening(const bool& param1) = 0;
virtual bool eth_setMining(const bool& param1) = 0;
virtual std::string eth_solidity(const std::string& param1) = 0;
virtual std::string eth_stateAt(const std::string& param1, const std::string& param2) = 0;
virtual Json::Value eth_storageAt(const std::string& param1) = 0;
virtual std::string eth_transact(const Json::Value& param1) = 0;
virtual Json::Value eth_transactionByHash(const std::string& param1, const int& param2) = 0;
virtual Json::Value eth_transactionByNumber(const int& param1, const int& param2) = 0;

8
libweb3jsonrpc/spec.json

@ -16,6 +16,7 @@
{ "method": "eth_stateAt", "params": ["", ""], "order": [], "returns": ""},
{ "method": "eth_countAt", "params": [""], "order": [], "returns" : 0.0},
{ "method": "eth_codeAt", "params": [""], "order": [], "returns": ""},
{ "method": "eth_storageAt", "params": [""], "order": [], "returns": {}},
{ "method": "eth_transact", "params": [{}], "order": [], "returns": ""},
{ "method": "eth_call", "params": [{}], "order": [], "returns": ""},
@ -27,14 +28,17 @@
{ "method": "eth_uncleByHash", "params": ["", 0], "order": [], "returns": {}},
{ "method": "eth_uncleByNumber", "params": [0, 0], "order": [], "returns": {}},
{ "method": "eth_compilers", "params": [], "order": [], "returns": []},
{ "method": "eth_lll", "params": [""], "order": [], "returns": ""},
{ "method": "eth_compile", "params": [""], "order": [], "returns": ""},
{ "method": "eth_solidity", "params": [""], "order": [], "returns": ""},
{ "method": "eth_serpent", "params": [""], "order": [], "returns": ""},
{ "method": "eth_newFilter", "params": [{}], "order": [], "returns": 0},
{ "method": "eth_newFilterString", "params": [""], "order": [], "returns": 0},
{ "method": "eth_uninstallFilter", "params": [0], "order": [], "returns": true},
{ "method": "eth_changed", "params": [0], "order": [], "returns": false},
{ "method": "eth_getMessages", "params": [0], "order": [], "returns": []},
{ "method": "eth_filterLogs", "params": [0], "order": [], "returns": []},
{ "method": "eth_logs", "params": [{}], "order": [], "returns": []},
{ "method": "db_put", "params": ["", "", ""], "order": [], "returns": true},
{ "method": "db_get", "params": ["", ""], "order": [], "returns": ""},

2
libwhisper/Common.cpp

@ -69,7 +69,7 @@ TopicMask BuildTopicMask::toTopicMask() const
TopicMask ret;
ret.reserve(m_parts.size());
for (auto const& h: m_parts)
ret.push_back(make_pair(TopicPart(h), h ? ~TopicPart() : TopicPart()));
ret.push_back(make_pair(TopicPart(h), ~TopicPart()));
return ret;
}

7
libwhisper/Common.h

@ -114,17 +114,12 @@ private:
class BuildTopicMask: BuildTopic
{
public:
enum EmptyType { Empty };
BuildTopicMask() { shift(); }
BuildTopicMask(EmptyType) {}
BuildTopicMask() {}
template <class T> BuildTopicMask(T const& _t) { shift(_t); }
template <class T> BuildTopicMask& shift(T const& _r) { BuildTopic::shift(_r); return *this; }
BuildTopicMask& shiftRaw(h256 const& _h) { BuildTopic::shiftRaw(_h); return *this; }
BuildTopic& shift() { m_parts.push_back(h256()); return *this; }
BuildTopicMask& operator()() { shift(); return *this; }
template <class T> BuildTopicMask& operator()(T const& _t) { shift(_t); return *this; }
operator TopicMask() const { return toTopicMask(); }

326
stdserv.js

@ -1,67 +1,41 @@
eth = web3.eth;
env.note('Creating Config...')
var configCode = eth.lll("
{
[[69]] (caller)
(returnlll {
(when (&& (= (calldatasize) 64) (= (caller) @@69))
(for {} (< @i (calldatasize)) [i](+ @i 64)
[[ (calldataload @i) ]] (calldataload (+ @i 32))
)
)
(return @@ $0)
})
}
")
env.note('Config code: ' + configCode)
var config;
eth.transact({ 'code': configCode }, function(a) { config = a; });
env.note('Config at address ' + config)
var nameRegCode = eth.lll("
{
[[(address)]] 'NameReg
[['NameReg]] (address)
[[config]] 'Config
[['Config]] config
[[69]] (caller)
(returnlll {
(when (= $0 'register) {
(when @@ $32 (stop))
(when @@(caller) [[@@(caller)]] 0)
[[$32]] (caller)
[[(caller)]] $32
(stop)
})
(when (&& (= $0 'unregister) @@(caller)) {
[[@@(caller)]] 0
[[(caller)]] 0
(stop)
})
(when (&& (= $0 'kill) (= (caller) @@69)) (suicide (caller)))
(return @@ $0)
})
}
");
env.note('NameReg code: ' + nameRegCode)
var nameReg;
env.note('Create NameReg...')
eth.transact({ 'code': nameRegCode }, function(a) { nameReg = a; });
env.note('Register NameReg...')
eth.transact({ 'to': config, 'data': ['0', nameReg] });
var compile = function(name) { return web3.eth.lll(env.contents("../../dapp-bin/" + name + "/" + name + ".lll")); };
var create = function(code) { return web3.eth.transact({ 'code': code }); };
var send = function(from, val, to) { return web3.eth.transact({ 'from': from, 'value': val, 'to': to }); };
var initService = function(name, index, dep) { return dep.then(function(){ var ret = compile(name).then(create); register(ret, index); return ret; }); };
var config = compile("config").then(create);
var register = function(address, index) { return web3.eth.transact({ 'to': config, 'gas': '10000', 'data': [index + '', address] }); };
var nameReg = initService("namereg", 0, config);
var regName = function(account, name) { return web3.eth.transact({ 'from': account, 'to': nameReg, 'gas': '10000', 'data': [ web3.fromAscii('register'), web3.fromAscii(name) ] }); };
var coins = initService("coins", 1, nameReg);
var coin = initService("coin", 2, coins);
var approve = function(account, approvedAddress) { web3.eth.transact({ 'from': account, 'to': coin, 'gas': '10000', 'data': [ web3.fromAscii('approve'), approvedAddress ] }); };
var exchange = initService("exchange", 3, coin);
var offer = function(account, haveCoin, haveVal, wantCoin, wantVal) { web3.eth.transact({ 'from': account, 'to': exchange, 'gas': '10000', 'data': [web3.fromAscii('new'), haveCoin, haveVal, wantCoin, wantVal] }); };
config.then(function() {
web3.eth.accounts.then(function(accounts)
{
var funded = send(accounts[0], '100000000000000000000', accounts[1]);
funded.then(function(){ regName(accounts[1], 'Gav Would'); approve(accounts[1], exchange); });
regName(accounts[0], 'Gav');
approve(accounts[0], exchange).then(function(){ offer(accounts[0], coin, '5000', '0', '5000000000000000000'); });
// TODO: once we have a new implementation of DNSReg.
// env.note('Register gav.eth...')
// eth.transact({ 'to': dnsReg, 'data': [web3.fromAscii('register'), web3.fromAscii('gav'), web3.fromAscii('opensecrecy.com')] });
});
});
// TODO
/*
var nameRegJeff;
env.note('Create NameRegJeff...')
eth.transact({ 'code': nameRegCode }, function(a) { nameRegJeff = a; });
env.note('Register NameRegJeff...')
eth.transact({ 'to': config, 'data': ['4', nameReg] });
eth.transact({ 'to': config, 'data': ['4', nameRegJeff] });
var dnsRegCode = '0x60006000546000600053602001546000600053604001546020604060206020600073661005d2720d855f1d9976f88bb10c1a3398c77f6103e8f17f7265676973746572000000000000000000000000000000000000000000000000600053606001600060200201547f446e735265670000000000000000000000000000000000000000000000000000600053606001600160200201546000600060006000604060606000600053604001536103e8f1327f6f776e65720000000000000000000000000000000000000000000000000000005761011663000000e46000396101166000f20060006000547f72656769737465720000000000000000000000000000000000000000000000006000602002350e0f630000006d596000600160200235560e0f630000006c59600032560e0f0f6300000057596000325657600260200235600160200235576001602002353257007f64657265676973746572000000000000000000000000000000000000000000006000602002350e0f63000000b95960016020023532560e0f63000000b959600032576000600160200235577f6b696c6c000000000000000000000000000000000000000000000000000000006000602002350e0f630000011559327f6f776e6572000000000000000000000000000000000000000000000000000000560e0f63000001155932ff00';
@ -73,240 +47,6 @@ env.note('DnsReg at address ' + dnsReg)
env.note('Register DnsReg...')
eth.transact({ 'to': config, 'data': ['4', dnsReg] });
var coinRegCode = eth.lll("
{
(regname 'CoinReg)
(returnlll {
(def 'name $0)
(def 'denom $32)
(def 'address (caller))
(when (|| (& 0xffffffffffffffffffffffffff name) @@name) (stop))
(set 'n (+ @@0 1))
[[0]] @n
[[@n]] name
[[name]] address
[[(sha3 name)]] denom
})
}
");
var coinReg;
env.note('Create CoinReg...')
eth.transact({ 'code': coinRegCode }, function(a) { coinReg = a; });
env.note('Register CoinReg...')
eth.transact({ 'to': config, 'data': ['1', coinReg] });
var gavCoinCode = eth.lll("
{
[[ (caller) ]] 0x1000000
[[ 0x69 ]] (caller)
[[ 0x42 ]] (number)
(regname 'GavCoin)
(regcoin 'GAV 1000)
(returnlll {
(when (&& (= $0 'kill) (= (caller) @@0x69)) (suicide (caller)))
(when (= $0 'balance) (return @@$32))
(when (= $0 'approved) (return @@ (sha3pair (if (= (calldatasize) 64) (caller) $64) $32)) )
(when (= $0 'approve) {
[[(sha3pair (caller) $32)]] $32
(stop)
})
(when (= $0 'send) {
(set 'fromVar (if (= (calldatasize) 96)
(caller)
{
(when (! @@ (sha3pair (origin) (caller))) (return 0))
(origin)
}
))
(def 'to $32)
(def 'value $64)
(def 'from (get 'fromVar))
(set 'fromBal @@from)
(when (< @fromBal value) (return 0))
[[ from ]]: (- @fromBal value)
[[ to ]]: (+ @@to value)
(return 1)
})
(set 'n @@0x42)
(when (&& (|| (= $0 'mine) (! (calldatasize))) (> (number) @n)) {
(set 'b (- (number) @n))
[[(coinbase)]] (+ @@(coinbase) (* 1000 @b))
[[(caller)]] (+ @@(caller) (* 1000 @b))
[[0x42]] (number)
(return @b)
})
(return @@ $0)
})
}
");
var gavCoin;
env.note('Create GavCoin...')
eth.transact({ 'code': gavCoinCode }, function(a) { gavCoin = a; });
env.note('Register GavCoin...')
eth.transact({ 'to': config, 'data': ['2', gavCoin] });
var exchangeCode = eth.lll("
{
(regname 'Exchange)
(def 'min (a b) (if (< a b) a b))
(def 'head (_list) @@ _list)
(def 'next (_item) @@ _item)
(def 'inc (itemref) [itemref]: (next @itemref))
(def 'rateof (_item) @@ (+ _item 1))
(def 'idof (_item) @@ (+ _item 2))
(def 'wantof (_item) @@ (+ _item 3))
(def 'newitem (rate who want list) {
(set 'pos (sha3trip rate who list))
[[ (+ @pos 1) ]] rate
[[ (+ @pos 2) ]] who
[[ (+ @pos 3) ]] want
@pos
})
(def 'stitchitem (parent pos) {
[[ pos ]] @@ parent
[[ parent ]] pos
})
(def 'addwant (_item amount) [[ (+ _item 3) ]] (+ @@ (+ _item 3) amount))
(def 'deductwant (_item amount) [[ (+ _item 3) ]] (- @@ (+ _item 3) amount))
(def 'xfer (contract to amount)
(if contract {
[0] 'send
[32] to
[64] amount
(msg allgas contract 0 0 96)
}
(send to amount)
)
)
(def 'fpdiv (a b) (/ (+ (/ b 2) (* a (exp 2 128))) b))
(def 'fpmul (a b) (/ (* a b) (exp 2 128)) )
(returnlll {
(when (= $0 'new) {
(set 'offer $32)
(set 'xoffer (if @offer $64 (callvalue)))
(set 'want $96)
(set 'xwant $128)
(set 'rate (fpdiv @xoffer @xwant))
(set 'irate (fpdiv @xwant @xoffer))
(unless (&& @rate @irate @xoffer @xwant) (stop))
(when @offer {
(set 'arg1 'send)
(set 'arg2 (address))
(set 'arg3 @xoffer)
(set 'arg4 (caller))
(unless (msg allgas @offer 0 arg1 128) (stop))
})
(set 'list (sha3pair @offer @want))
(set 'ilist (sha3pair @want @offer))
(set 'last @ilist)
(set 'item @@ @last)
(for {} (&& @item (>= (rateof @item) @irate)) {} {
(set 'offerA (min @xoffer (wantof @item)))
(set 'wantA (fpmul @offerA (rateof @item)))
(set 'xoffer (- @xoffer @offerA))
(set 'xwant (- @xwant @wantA))
(deductwant @item @offerA)
(xfer @offer (idof @item) @offerA)
(xfer @want (caller) @wantA)
(unless @xoffer (stop))
(set 'item @@ @item)
[[ @last ]] @item
})
(set 'last @list)
(set 'item @@ @last)
(set 'newpos (newitem @rate (caller) @xwant @list))
(for {} (&& @item (!= @item @newpos) (>= (rateof @item) @rate)) { (set 'last @item) (inc item) } {})
(if (= @item @newpos)
(addwant @item @wantx)
(stitchitem @last @newpos)
)
(stop)
})
(when (= $0 'delete) {
(set 'offer $32)
(set 'want $64)
(set 'rate $96)
(set 'list (sha3pair @offer @want))
(set 'last @list)
(set 'item @@ @last)
(for {} (&& @item (!= (idof @item) (caller)) (!= (rateof @item) @rate)) { (set 'last @item) (inc item) } {})
(when @item {
(set 'xoffer (fpmul (wantof @item) (rateof @item)))
[[ @last ]] @@ @item
(xfer @offer (caller) @xoffer)
})
(stop)
})
(when (= $0 'price) {
(set 'offer $32)
(set 'want $96)
(set 'item (head (sha3pair @offer @want)))
(return (if @item (rateof @list) 0))
})
})
}
");
var exchange;
env.note('Create Exchange...')
eth.transact({ 'code': exchangeCode }, function(a) { exchange = a; });
env.note('Register Exchange...')
eth.transact({ 'to': config, 'data': ['3', exchange] });
env.note('Register my name...')
eth.transact({ 'to': nameReg, 'data': [ web3.fromAscii('register'), web3.fromAscii('Gav') ] });
env.note('Dole out ETH to other address...')
eth.transact({ 'value': '100000000000000000000', 'to': eth.accounts[1] });
env.note('Register my other name...')
eth.transact({ 'from': eth.keys[1], 'to': nameReg, 'data': [ web3.fromAscii('register'), web3.fromAscii("Gav Would") ] });
env.note('Approve Exchange...')
eth.transact({ 'to': gavCoin, 'data': [ web3.fromAscii('approve'), exchange ] });
env.note('Approve Exchange on other address...')
eth.transact({ 'from': eth.keys[1], 'to': gavCoin, 'data': [ web3.fromAscii('approve'), exchange ] });
env.note('Make offer 5000GAV/5ETH...')
eth.transact({ 'to': exchange, 'data': [web3.fromAscii('new'), gavCoin, '5000', '0', '5000000000000000000'] });
env.note('Register gav.eth...')
eth.transact({ 'to': dnsReg, 'data': [web3.fromAscii('register'), web3.fromAscii('gav'), web3.fromAscii('opensecrecy.com')] });
env.note('All done.')
*/
// env.load('/home/gav/Eth/cpp-ethereum/stdserv.js')

2
test/crypto.cpp

@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_ecdsa_sipaseckp256k1)
Secret secret(sha3(sbytes));
KeyPair key(secret);
bytes m({0xFF});
bytes m(1, 0xff);
int tests = 2;
while (m[0]++, tests--)
{

66
test/jsonrpc.cpp

@ -237,7 +237,73 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
BOOST_CHECK_EQUAL(jsToDecimal(balanceString2), "750000000000000000");
BOOST_CHECK_EQUAL(txAmount, balance2);
}
BOOST_AUTO_TEST_CASE(simple_contract)
{
cnote << "Testing jsonrpc contract...";
KeyPair kp = KeyPair::create();
web3->ethereum()->setAddress(kp.address());
jsonrpcServer->setAccounts({kp});
dev::eth::mine(*(web3->ethereum()), 1);
char const* sourceCode = "contract test {\n"
" function f(uint a) returns(uint d) { return a * 7; }\n"
"}\n";
string compiled = jsonrpcClient->eth_solidity(sourceCode);
Json::Value create;
create["code"] = compiled;
string contractAddress = jsonrpcClient->eth_transact(create);
dev::eth::mine(*(web3->ethereum()), 1);
Json::Value call;
call["to"] = contractAddress;
call["data"] = "0x00000000000000000000000000000000000000000000000000000000000000001";
string result = jsonrpcClient->eth_call(call);
BOOST_CHECK_EQUAL(result, "0x0000000000000000000000000000000000000000000000000000000000000007");
}
BOOST_AUTO_TEST_CASE(contract_storage)
{
cnote << "Testing jsonrpc contract storage...";
KeyPair kp = KeyPair::create();
web3->ethereum()->setAddress(kp.address());
jsonrpcServer->setAccounts({kp});
dev::eth::mine(*(web3->ethereum()), 1);
char const* sourceCode = R"(
contract test {
uint hello;
function writeHello(uint value) returns(bool d){
hello = value;
return true;
}
}
)";
string compiled = jsonrpcClient->eth_solidity(sourceCode);
Json::Value create;
create["code"] = compiled;
string contractAddress = jsonrpcClient->eth_transact(create);
dev::eth::mine(*(web3->ethereum()), 1);
Json::Value transact;
transact["to"] = contractAddress;
transact["data"] = "0x00000000000000000000000000000000000000000000000000000000000000003";
jsonrpcClient->eth_transact(transact);
dev::eth::mine(*(web3->ethereum()), 1);
Json::Value storage = jsonrpcClient->eth_storageAt(contractAddress);
BOOST_CHECK_EQUAL(storage.getMemberNames().size(), 1);
for (auto name: storage.getMemberNames())
BOOST_CHECK_EQUAL(storage[name].asString(), "0x03");
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

2
test/solidityCompiler.cpp

@ -128,8 +128,6 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers)
byte(Instruction::JUMP),
byte(Instruction::JUMPDEST),
// stack here: ret e h f(1,2,3)
byte(Instruction::DUP2),
byte(Instruction::POP),
byte(Instruction::SWAP1),
// stack here: ret e f(1,2,3) h
byte(Instruction::POP),

204
test/solidityEndToEndTest.cpp

@ -32,6 +32,9 @@ using namespace std;
namespace dev
{
/// Provider another overload for toBigEndian to encode arguments and return values.
inline bytes toBigEndian(bool _value) { return bytes({byte(_value)}); }
namespace solidity
{
namespace test
@ -137,6 +140,7 @@ private:
m_output = executive.out().toVector();
}
protected:
Address m_contractAddress;
eth::State m_state;
u256 const m_gasPrice = 100 * eth::szabo;
@ -496,6 +500,206 @@ BOOST_AUTO_TEST_CASE(state_smoke_test)
BOOST_CHECK(callContractFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0x3)));
}
BOOST_AUTO_TEST_CASE(simple_mapping)
{
char const* sourceCode = "contract test {\n"
" mapping(uint8 => uint8) table;\n"
" function get(uint8 k) returns (uint8 v) {\n"
" return table[k];\n"
" }\n"
" function set(uint8 k, uint8 v) {\n"
" table[k] = v;\n"
" }\n"
"}";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction(0, bytes({0x00})) == bytes({0x00}));
BOOST_CHECK(callContractFunction(0, bytes({0x01})) == bytes({0x00}));
BOOST_CHECK(callContractFunction(0, bytes({0xa7})) == bytes({0x00}));
callContractFunction(1, bytes({0x01, 0xa1}));
BOOST_CHECK(callContractFunction(0, bytes({0x00})) == bytes({0x00}));
BOOST_CHECK(callContractFunction(0, bytes({0x01})) == bytes({0xa1}));
BOOST_CHECK(callContractFunction(0, bytes({0xa7})) == bytes({0x00}));
callContractFunction(1, bytes({0x00, 0xef}));
BOOST_CHECK(callContractFunction(0, bytes({0x00})) == bytes({0xef}));
BOOST_CHECK(callContractFunction(0, bytes({0x01})) == bytes({0xa1}));
BOOST_CHECK(callContractFunction(0, bytes({0xa7})) == bytes({0x00}));
callContractFunction(1, bytes({0x01, 0x05}));
BOOST_CHECK(callContractFunction(0, bytes({0x00})) == bytes({0xef}));
BOOST_CHECK(callContractFunction(0, bytes({0x01})) == bytes({0x05}));
BOOST_CHECK(callContractFunction(0, bytes({0xa7})) == bytes({0x00}));
}
BOOST_AUTO_TEST_CASE(mapping_state)
{
char const* sourceCode = "contract Ballot {\n"
" mapping(address => bool) canVote;\n"
" mapping(address => uint) voteCount;\n"
" mapping(address => bool) voted;\n"
" function getVoteCount(address addr) returns (uint retVoteCount) {\n"
" return voteCount[addr];\n"
" }\n"
" function grantVoteRight(address addr) {\n"
" canVote[addr] = true;\n"
" }\n"
" function vote(address voter, address vote) returns (bool success) {\n"
" if (!canVote[voter] || voted[voter]) return false;\n"
" voted[voter] = true;\n"
" voteCount[vote] = voteCount[vote] + 1;\n"
" return true;\n"
" }\n"
"}\n";
compileAndRun(sourceCode);
class Ballot
{
public:
u256 getVoteCount(u160 _address) { return m_voteCount[_address]; }
void grantVoteRight(u160 _address) { m_canVote[_address] = true; }
bool vote(u160 _voter, u160 _vote)
{
if (!m_canVote[_voter] || m_voted[_voter]) return false;
m_voted[_voter] = true;
m_voteCount[_vote]++;
return true;
}
private:
map<u160, bool> m_canVote;
map<u160, u256> m_voteCount;
map<u160, bool> m_voted;
} ballot;
auto getVoteCount = bind(&Ballot::getVoteCount, &ballot, _1);
auto grantVoteRight = bind(&Ballot::grantVoteRight, &ballot, _1);
auto vote = bind(&Ballot::vote, &ballot, _1, _2);
testSolidityAgainstCpp(0, getVoteCount, u160(0));
testSolidityAgainstCpp(0, getVoteCount, u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(2));
// voting without vote right shourd be rejected
testSolidityAgainstCpp(2, vote, u160(0), u160(2));
testSolidityAgainstCpp(0, getVoteCount, u160(0));
testSolidityAgainstCpp(0, getVoteCount, u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(2));
// grant vote rights
testSolidityAgainstCpp(1, grantVoteRight, u160(0));
testSolidityAgainstCpp(1, grantVoteRight, u160(1));
// vote, should increase 2's vote count
testSolidityAgainstCpp(2, vote, u160(0), u160(2));
testSolidityAgainstCpp(0, getVoteCount, u160(0));
testSolidityAgainstCpp(0, getVoteCount, u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(2));
// vote again, should be rejected
testSolidityAgainstCpp(2, vote, u160(0), u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(0));
testSolidityAgainstCpp(0, getVoteCount, u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(2));
// vote without right to vote
testSolidityAgainstCpp(2, vote, u160(2), u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(0));
testSolidityAgainstCpp(0, getVoteCount, u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(2));
// grant vote right and now vote again
testSolidityAgainstCpp(1, grantVoteRight, u160(2));
testSolidityAgainstCpp(2, vote, u160(2), u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(0));
testSolidityAgainstCpp(0, getVoteCount, u160(1));
testSolidityAgainstCpp(0, getVoteCount, u160(2));
}
BOOST_AUTO_TEST_CASE(mapping_state_inc_dec)
{
char const* sourceCode = "contract test {\n"
" uint value;\n"
" mapping(uint => uint) table;\n"
" function f(uint x) returns (uint y) {\n"
" value = x;\n"
" if (x > 0) table[++value] = 8;\n"
" if (x > 1) value--;\n"
" if (x > 2) table[value]++;\n"
" return --table[value++];\n"
" }\n"
"}\n";
compileAndRun(sourceCode);
u256 value = 0;
map<u256, u256> table;
auto f = [&](u256 const& _x) -> u256
{
value = _x;
if (_x > 0)
table[++value] = 8;
if (_x > 1)
value --;
if (_x > 2)
table[value]++;
return --table[value++];
};
testSolidityAgainstCppOnRange(0, f, 0, 5);
}
BOOST_AUTO_TEST_CASE(multi_level_mapping)
{
char const* sourceCode = "contract test {\n"
" mapping(uint => mapping(uint => uint)) table;\n"
" function f(uint x, uint y, uint z) returns (uint w) {\n"
" if (z == 0) return table[x][y];\n"
" else return table[x][y] = z;\n"
" }\n"
"}\n";
compileAndRun(sourceCode);
map<u256, map<u256, u256>> table;
auto f = [&](u256 const& _x, u256 const& _y, u256 const& _z) -> u256
{
if (_z == 0) return table[_x][_y];
else return table[_x][_y] = _z;
};
testSolidityAgainstCpp(0, f, u256(4), u256(5), u256(0));
testSolidityAgainstCpp(0, f, u256(5), u256(4), u256(0));
testSolidityAgainstCpp(0, f, u256(4), u256(5), u256(9));
testSolidityAgainstCpp(0, f, u256(4), u256(5), u256(0));
testSolidityAgainstCpp(0, f, u256(5), u256(4), u256(0));
testSolidityAgainstCpp(0, f, u256(5), u256(4), u256(7));
testSolidityAgainstCpp(0, f, u256(4), u256(5), u256(0));
testSolidityAgainstCpp(0, f, u256(5), u256(4), u256(0));
}
BOOST_AUTO_TEST_CASE(structs)
{
char const* sourceCode = "contract test {\n"
" struct s1 {\n"
" uint8 x;\n"
" bool y;\n"
" }\n"
" struct s2 {\n"
" uint32 z;\n"
" s1 s1data;\n"
" mapping(uint8 => s2) recursive;\n"
" }\n"
" s2 data;\n"
" function check() returns (bool ok) {\n"
" return data.z == 1 && data.s1data.x == 2 && \n"
" data.s1data.y == true && \n"
" data.recursive[3].recursive[4].z == 5 && \n"
" data.recursive[4].recursive[3].z == 6 && \n"
" data.recursive[0].s1data.y == false && \n"
" data.recursive[4].z == 9;\n"
" }\n"
" function set() {\n"
" data.z = 1;\n"
" data.s1data.x = 2;\n"
" data.s1data.y = true;\n"
" data.recursive[3].recursive[4].z = 5;\n"
" data.recursive[4].recursive[3].z = 6;\n"
" data.recursive[0].s1data.y = false;\n"
" data.recursive[4].z = 9;\n"
" }\n"
"}\n";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction(0) == bytes({0x00}));
BOOST_CHECK(callContractFunction(1) == bytes());
BOOST_CHECK(callContractFunction(0) == bytes({0x01}));
}
BOOST_AUTO_TEST_SUITE_END()
}

38
test/solidityNameAndTypeResolution.cpp

@ -121,6 +121,44 @@ BOOST_AUTO_TEST_CASE(reference_to_later_declaration)
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
}
BOOST_AUTO_TEST_CASE(struct_definition_directly_recursive)
{
char const* text = "contract test {\n"
" struct MyStructName {\n"
" address addr;\n"
" MyStructName x;\n"
" }\n"
"}\n";
BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
}
BOOST_AUTO_TEST_CASE(struct_definition_indirectly_recursive)
{
char const* text = "contract test {\n"
" struct MyStructName1 {\n"
" address addr;\n"
" uint256 count;\n"
" MyStructName2 x;\n"
" }\n"
" struct MyStructName2 {\n"
" MyStructName1 x;\n"
" }\n"
"}\n";
BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
}
BOOST_AUTO_TEST_CASE(struct_definition_recursion_via_mapping)
{
char const* text = "contract test {\n"
" struct MyStructName1 {\n"
" address addr;\n"
" uint256 count;\n"
" mapping(uint => MyStructName1) x;\n"
" }\n"
"}\n";
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
}
BOOST_AUTO_TEST_CASE(type_inference_smoke_test)
{
char const* text = "contract test {\n"

85
test/webthreestubclient.h

@ -179,14 +179,13 @@ p.append(param3);
}
std::string eth_compile(const std::string& param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_compilers() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_compile",p);
if (result.isString())
return result.asString();
p = Json::nullValue;
Json::Value result = this->client->CallMethod("eth_compilers",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@ -217,26 +216,26 @@ p.append(param3);
}
std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
Json::Value eth_filterLogs(const int& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("eth_gasPrice",p);
if (result.isString())
return result.asString();
p.append(param1);
Json::Value result = this->client->CallMethod("eth_filterLogs",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_getMessages(const int& param1) throw (jsonrpc::JsonRpcException)
std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_getMessages",p);
if (result.isArray())
return result;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("eth_gasPrice",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@ -267,6 +266,19 @@ p.append(param3);
}
Json::Value eth_logs(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_logs",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool eth_mining() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@ -329,6 +341,19 @@ p.append(param3);
}
std::string eth_serpent(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_serpent",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool eth_setCoinbase(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@ -381,6 +406,19 @@ p.append(param3);
}
std::string eth_solidity(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_solidity",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_stateAt(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@ -395,6 +433,19 @@ p.append(param2);
}
Json::Value eth_storageAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_storageAt",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;

17
third/MainWin.cpp

@ -182,7 +182,7 @@ void Main::onKeysChanged()
installBalancesWatch();
}
unsigned Main::installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f)
unsigned Main::installWatch(dev::eth::LogFilter const& _tf, std::function<void()> const& _f)
{
auto ret = ethereum()->installWatch(_tf);
m_handlers[ret] = _f;
@ -198,37 +198,34 @@ unsigned Main::installWatch(dev::h256 _tf, std::function<void()> const& _f)
void Main::installWatches()
{
installWatch(dev::eth::MessageFilter().altered(c_config, 0), [=](){ installNameRegWatch(); });
installWatch(dev::eth::MessageFilter().altered(c_config, 1), [=](){ installCurrenciesWatch(); });
installWatch(dev::eth::LogFilter().topic((u256)(u160)c_config).topic((u256)0), [=](){ installNameRegWatch(); });
installWatch(dev::eth::LogFilter().topic((u256)(u160)c_config).topic((u256)1), [=](){ installCurrenciesWatch(); });
installWatch(dev::eth::ChainChangedFilter, [=](){ onNewBlock(); });
}
void Main::installNameRegWatch()
{
ethereum()->uninstallWatch(m_nameRegFilter);
m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
m_nameRegFilter = installWatch(dev::eth::LogFilter().topic(ethereum()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
}
void Main::installCurrenciesWatch()
{
ethereum()->uninstallWatch(m_currenciesFilter);
m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
m_currenciesFilter = installWatch(dev::eth::LogFilter().topic(ethereum()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
}
void Main::installBalancesWatch()
{
dev::eth::MessageFilter tf;
dev::eth::LogFilter tf;
vector<Address> altCoins;
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1));
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i)
altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys)
{
tf.altered(i.address());
for (auto c: altCoins)
tf.altered(c, (u160)i.address());
}
tf.address(c).topic((u256)(u160)i.address());
ethereum()->uninstallWatch(m_balancesFilter);
m_balancesFilter = installWatch(tf, [=](){ onBalancesChange(); });

4
third/MainWin.h

@ -40,7 +40,7 @@ namespace dev { class WebThreeDirect;
namespace eth {
class Client;
class State;
class MessageFilter;
class LogFilter;
}
namespace shh {
class WhisperHost;
@ -95,7 +95,7 @@ private:
void readSettings(bool _skipGeometry = false);
void writeSettings();
unsigned installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f);
unsigned installWatch(dev::eth::LogFilter const& _tf, std::function<void()> const& _f);
unsigned installWatch(dev::h256 _tf, std::function<void()> const& _f);
void onNewBlock();

9
windows/LibEthereum.vcxproj

@ -68,14 +68,14 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\libdevcore\_libdevcore.cpp" />
<ClCompile Include="..\libdevcrypto\AES.cpp" />
<ClCompile Include="..\libdevcrypto\Common.cpp" />
<ClCompile Include="..\libdevcrypto\CryptoPP.cpp" />
<ClCompile Include="..\libdevcrypto\EC.cpp" />
<ClCompile Include="..\libdevcrypto\ECDHE.cpp" />
<ClCompile Include="..\libdevcrypto\FileSystem.cpp" />
<ClCompile Include="..\libdevcrypto\MemoryDB.cpp" />
<ClCompile Include="..\libdevcrypto\OverlayDB.cpp" />
<ClCompile Include="..\libdevcrypto\SHA3.cpp" />
<ClCompile Include="..\libdevcrypto\SHA3MAC.cpp" />
<ClCompile Include="..\libdevcrypto\TrieCommon.cpp" />
<ClCompile Include="..\libdevcrypto\TrieDB.cpp" />
<ClCompile Include="..\libethcore\BlockInfo.cpp">
@ -125,8 +125,8 @@
<ClCompile Include="..\libethereum\Transaction.cpp" />
<ClCompile Include="..\libethereum\TransactionQueue.cpp" />
<ClCompile Include="..\libethereum\Utility.cpp" />
<ClCompile Include="..\libevmcore\Instruction.cpp" />
<ClCompile Include="..\libevmcore\Assembly.cpp" />
<ClCompile Include="..\libevmcore\Instruction.cpp" />
<ClCompile Include="..\libevm\ExtVMFace.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@ -341,7 +341,8 @@
<ClInclude Include="..\libethereum\Transaction.h" />
<ClInclude Include="..\libethereum\TransactionQueue.h" />
<ClInclude Include="..\libethereum\Utility.h" />
<ClCompile Include="..\libevmcore\Assembly.h" />
<ClInclude Include="..\libevmcore\Assembly.h" />
<ClInclude Include="..\libevmcore\Exceptions.h" />
<ClInclude Include="..\libevmcore\Instruction.h" />
<ClInclude Include="..\libevm\All.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>

17
windows/LibEthereum.vcxproj.filters

@ -40,9 +40,6 @@
<ClCompile Include="..\libevmcore\Instruction.cpp">
<Filter>libevmcore</Filter>
</ClCompile>
<ClCompile Include="..\liblll\Assembly.cpp">
<Filter>liblll</Filter>
</ClCompile>
<ClCompile Include="..\liblll\CodeFragment.cpp">
<Filter>liblll</Filter>
</ClCompile>
@ -202,6 +199,9 @@
<ClCompile Include="..\libethereum\Account.cpp">
<Filter>libethereum</Filter>
</ClCompile>
<ClCompile Include="..\libevmcore\Assembly.cpp">
<Filter>libevmcore</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@ -248,9 +248,6 @@
</ClInclude>
<ClInclude Include="..\liblll\All.h">
<Filter>liblll</Filter>
</ClInclude>
<ClInclude Include="..\libevmcore\Assembly.h">
<Filter>libevmcore</Filter>
</ClInclude>
<ClInclude Include="..\liblll\CodeFragment.h">
<Filter>liblll</Filter>
@ -435,6 +432,12 @@
<ClInclude Include="..\libethereum\Account.h">
<Filter>libethereum</Filter>
</ClInclude>
<ClInclude Include="..\libevmcore\Exceptions.h">
<Filter>libevmcore</Filter>
</ClInclude>
<ClInclude Include="..\libevmcore\Assembly.h">
<Filter>libevmcore</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Windows">
@ -471,4 +474,4 @@
<UniqueIdentifier>{d838fece-fc20-42f6-bff5-97c236159b80}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
</Project>
Loading…
Cancel
Save