From 77a15f749fd78d371ad51cef31f49f120b2a36ea Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Fri, 6 Feb 2015 15:19:22 +0800 Subject: [PATCH 01/10] change typedef to using according to preferred coding style --- evmjit/libevmjit/ExecutionEngine.cpp | 2 +- libdevcore/Exceptions.h | 12 ++++++------ libdevcore/RLP.h | 8 ++++---- libdevcore/vector_ref.h | 6 +++--- libdevcrypto/ECDHE.h | 2 +- libethcore/Exceptions.h | 8 ++++---- libethereum/BlockDetails.h | 6 +++--- libevmcore/Assembly.h | 4 ++-- liblll/Parser.cpp | 4 ++-- libp2p/Common.h | 6 +++--- libsolidity/Exceptions.h | 2 +- mix/CodeHighlighter.h | 2 +- mix/Exceptions.h | 8 ++++---- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/evmjit/libevmjit/ExecutionEngine.cpp b/evmjit/libevmjit/ExecutionEngine.cpp index 2db125c2d..aae5349d8 100644 --- a/evmjit/libevmjit/ExecutionEngine.cpp +++ b/evmjit/libevmjit/ExecutionEngine.cpp @@ -29,7 +29,7 @@ namespace jit namespace { -typedef ReturnCode(*EntryFuncPtr)(Runtime*); +using EntryFuncPtr = ReturnCode(*)(Runtime*); ReturnCode runEntryFunc(EntryFuncPtr _mainFunc, Runtime* _runtime) { diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index e13d41476..f3f9b1bf0 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -44,10 +44,10 @@ struct FileError: virtual Exception {}; struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): m_f("Interface " + _f + " not supported.") {} virtual const char* what() const noexcept { return m_f.c_str(); } private: std::string m_f; }; // error information to be added to exceptions -typedef boost::error_info errinfo_invalidSymbol; -typedef boost::error_info errinfo_wrongAddress; -typedef boost::error_info errinfo_comment; -typedef boost::error_info errinfo_required; -typedef boost::error_info errinfo_got; -typedef boost::tuple RequirementError; +using errinfo_invalidSymbol = boost::error_info; +using errinfo_wrongAddress = boost::error_info; +using errinfo_comment = boost::error_info; +using errinfo_required = boost::error_info; +using errinfo_got = boost::error_info; +using RequirementError = boost::tuple; } diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h index 2eedbaba2..34a0fc65f 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -37,7 +37,7 @@ namespace dev { class RLP; -typedef std::vector RLPs; +using RLPs = std::vector; template struct intTraits { static const unsigned maxSize = sizeof(_T); }; template <> struct intTraits { static const unsigned maxSize = 20; }; @@ -125,7 +125,7 @@ public: /// @note if used to access items in ascending order, this is efficient. RLP operator[](unsigned _i) const; - typedef RLP element_type; + using element_type = RLP; /// @brief Iterator class for iterating through items of RLP list. class iterator @@ -133,8 +133,8 @@ public: friend class RLP; public: - typedef RLP value_type; - typedef RLP element_type; + using value_type = RLP; + using element_type = RLP; iterator& operator++(); iterator operator++(int) { auto ret = *this; operator++(); return ret; } diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index 0cd3f8064..4b1df924d 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -12,9 +12,9 @@ template class vector_ref { public: - typedef _T value_type; - typedef _T element_type; - typedef typename std::conditional::value, typename std::remove_const<_T>::type, _T>::type mutable_value_type; + using value_type = _T; + using element_type = _T; + using mutable_value_type = typename std::conditional::value, typename std::remove_const<_T>::type, _T>::type; vector_ref(): m_data(nullptr), m_count(0) {} vector_ref(_T* _data, size_t _count): m_data(_data), m_count(_count) {} diff --git a/libdevcrypto/ECDHE.h b/libdevcrypto/ECDHE.h index f77f7fcff..4450aec4b 100644 --- a/libdevcrypto/ECDHE.h +++ b/libdevcrypto/ECDHE.h @@ -31,7 +31,7 @@ namespace crypto { /// Public key of remote and corresponding shared secret. -typedef std::pair AliasSession; +using AliasSession = std::pair; /** * @brief An addressable EC key pair. diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h index b53a62562..6127a3d00 100644 --- a/libethcore/Exceptions.h +++ b/libethcore/Exceptions.h @@ -29,10 +29,10 @@ namespace eth { // information to add to exceptions -typedef boost::error_info errinfo_name; -typedef boost::error_info errinfo_field; -typedef boost::error_info errinfo_data; -typedef boost::tuple BadFieldError; +using errinfo_name = boost::error_info; +using errinfo_field = boost::error_info; +using errinfo_data = boost::error_info; +using BadFieldError = boost::tuple; struct DatabaseAlreadyOpen: virtual dev::Exception {}; struct NotEnoughCash: virtual dev::Exception {}; diff --git a/libethereum/BlockDetails.h b/libethereum/BlockDetails.h index bbfd48e56..61b9667c4 100644 --- a/libethereum/BlockDetails.h +++ b/libethereum/BlockDetails.h @@ -70,9 +70,9 @@ struct BlockReceipts TransactionReceipts receipts; }; -typedef std::map BlockDetailsHash; -typedef std::map BlockLogBloomsHash; -typedef std::map BlockReceiptsHash; +using BlockDetailsHash = std::map; +using BlockLogBloomsHash = std::map; +using BlockReceiptsHash = std::map; static const BlockDetails NullBlockDetails; static const BlockLogBlooms NullBlockLogBlooms; diff --git a/libevmcore/Assembly.h b/libevmcore/Assembly.h index 81e4a9ff7..9d9e4093c 100644 --- a/libevmcore/Assembly.h +++ b/libevmcore/Assembly.h @@ -63,8 +63,8 @@ private: u256 m_data; }; -typedef std::vector AssemblyItems; -typedef vector_ref AssemblyItemsConstRef; +using AssemblyItems = std::vector; +using AssemblyItemsConstRef = vector_ref; std::ostream& operator<<(std::ostream& _out, AssemblyItemsConstRef _i); inline std::ostream& operator<<(std::ostream& _out, AssemblyItems const& _i) { return operator<<(_out, AssemblyItemsConstRef(&_i)); } diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index e94e88e19..df30f3897 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -89,8 +89,8 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) using qi::standard::space; using qi::standard::space_type; using dev::eth::parseTreeLLL_::tagNode; - typedef sp::basic_string symbol_type; - typedef string::const_iterator it; + using symbol_type = sp::basic_string; + using it = string::const_iterator; static const u256 ether = u256(1000000000) * 1000000000; static const u256 finney = u256(1000000000) * 1000000; diff --git a/libp2p/Common.h b/libp2p/Common.h index d46c5eed1..61df1350f 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -112,9 +112,9 @@ inline bool isPermanentProblem(DisconnectReason _r) /// @returns the string form of the given disconnection reason. std::string reasonOf(DisconnectReason _r); -typedef std::pair CapDesc; -typedef std::set CapDescSet; -typedef std::vector CapDescs; +using CapDesc = std::pair; +using CapDescSet = std::set; +using CapDescs = std::vector; struct PeerInfo { diff --git a/libsolidity/Exceptions.h b/libsolidity/Exceptions.h index 14f919772..0b25abee1 100644 --- a/libsolidity/Exceptions.h +++ b/libsolidity/Exceptions.h @@ -38,7 +38,7 @@ struct CompilerError: virtual Exception {}; struct InternalCompilerError: virtual Exception {}; struct DocstringParsingError: virtual Exception {}; -typedef boost::error_info errinfo_sourceLocation; +using errinfo_sourceLocation = boost::error_info; } } diff --git a/mix/CodeHighlighter.h b/mix/CodeHighlighter.h index 5083e6c82..3bdff5647 100644 --- a/mix/CodeHighlighter.h +++ b/mix/CodeHighlighter.h @@ -81,7 +81,7 @@ public: int start; int length; }; - typedef std::vector Formats; // Sorted by start position + using Formats = std::vector; // Sorted by start position public: /// Collect highligting information by lexing the source diff --git a/mix/Exceptions.h b/mix/Exceptions.h index 5403879f1..46178bf96 100644 --- a/mix/Exceptions.h +++ b/mix/Exceptions.h @@ -40,10 +40,10 @@ struct FunctionNotFoundException: virtual Exception {}; struct ExecutionStateException: virtual Exception {}; struct ParameterChangedException: virtual Exception {}; -typedef boost::error_info QmlErrorInfo; -typedef boost::error_info FileError; -typedef boost::error_info BlockIndex; -typedef boost::error_info FunctionName; +using QmlErrorInfo = boost::error_info; +using FileError = boost::error_info; +using BlockIndex = boost::error_info; +using FunctionName = boost::error_info; } } From 46b629a579b84288207b637462737ca1d95cd1f8 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 7 Feb 2015 11:58:38 +0100 Subject: [PATCH 02/10] jsonrpcstub integreted into cmake build process --- cmake/EthDependencies.cmake | 2 ++ libweb3jsonrpc/CMakeLists.txt | 11 +++++++++++ test/webthreestubclient.h | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index 9b00a182f..8ff3d1460 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -122,6 +122,8 @@ if (NOT HEADLESS) string(REGEX REPLACE "npm" "" ETH_NPM_DIRECTORY ${ETH_NPM}) message(" - npm location : ${ETH_NPM}") + find_program(ETH_JSON_RPC_STUB jsonrpcstub) + endif() #HEADLESS # use multithreaded boost libraries, with -mt suffix diff --git a/libweb3jsonrpc/CMakeLists.txt b/libweb3jsonrpc/CMakeLists.txt index f371024e6..e18a53cd8 100644 --- a/libweb3jsonrpc/CMakeLists.txt +++ b/libweb3jsonrpc/CMakeLists.txt @@ -32,6 +32,17 @@ target_link_libraries(${EXECUTABLE} secp256k1) target_link_libraries(${EXECUTABLE} solidity) target_link_libraries(${EXECUTABLE} serpent) +if (ETH_JSON_RPC_STUB) + add_custom_target(jsonrpcstub) + add_custom_command(TARGET jsonrpcstub + POST_BUILD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ${ETH_JSON_RPC_STUB} spec.json --cpp-server=AbstractWebThreeStubServer --cpp-client=WebThreeStubClient + COMMAND cmake -E rename webthreestubclient.h ../test/webthreestubclient.h + ) + add_dependencies(${EXECUTABLE} jsonrpcstub) +endif() + install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) diff --git a/test/webthreestubclient.h b/test/webthreestubclient.h index 6a82263d0..b7cdf015c 100644 --- a/test/webthreestubclient.h +++ b/test/webthreestubclient.h @@ -213,6 +213,16 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } + bool eth_flush() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_flush",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } Json::Value eth_blockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; @@ -347,13 +357,13 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_changed(const int& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_changed(const int& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); Json::Value result = this->CallMethod("eth_changed",p); - if (result.isBool()) - return result.asBool(); + if (result.isArray()) + return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } From d6c00187ed796f027899b7c23b865179840e1d79 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 7 Feb 2015 12:10:39 +0100 Subject: [PATCH 03/10] missing commands in client --- test/webthreestubclient.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/webthreestubclient.h b/test/webthreestubclient.h index b7cdf015c..1836f6506 100644 --- a/test/webthreestubclient.h +++ b/test/webthreestubclient.h @@ -387,6 +387,26 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } + Json::Value eth_getWork() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_getWork",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool eth_submitWork(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_submitWork",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } bool db_put(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) { Json::Value p; From 46853aa426d0cffc1139311c7a39485ce9abb3b1 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sun, 8 Feb 2015 22:10:15 +0100 Subject: [PATCH 04/10] fixed overwriting ETH_BUILD_PLATFORM --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d83f91bf4..dd79112f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,13 +65,13 @@ function(createBuildInfo) endif () if (EVMJIT) - set(ETH_BUILD_PLATFORM "${TARGET_PLATFORM}/JIT") + set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/JIT") else () - set(ETH_BUILD_PLATFORM "${TARGET_PLATFORM}/int") + set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/int") endif () if (PARANOIA) - set(ETH_BUILD_PLATFORM "${TARGET_PLATFORM}/PARA") + set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/PARA") endif () #cmake build type may be not specified when using msvc From 0a831eb79b66fabb10dce20e23e832be18a4aab1 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 9 Feb 2015 16:16:16 +0100 Subject: [PATCH 05/10] Mix: call filter for transaction log --- mix/ClientModel.cpp | 25 ++++++------- mix/ClientModel.h | 32 +++++++++-------- mix/MachineStates.h | 8 +++-- mix/MixClient.cpp | 73 +++++++++++++++++--------------------- mix/MixClient.h | 8 ++--- mix/qml/CallStack.qml | 31 ---------------- mix/qml/DebugInfoList.qml | 1 + mix/qml/TransactionLog.qml | 41 +++++++++++---------- mix/qml/main.qml | 10 ++++++ mix/res.qrc | 1 - 10 files changed, 105 insertions(+), 125 deletions(-) delete mode 100644 mix/qml/CallStack.qml diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 602940078..10a60811f 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -82,7 +82,7 @@ ClientModel::ClientModel(AppContext* _context): qRegisterMetaType("QInstruction"); qRegisterMetaType("QCode"); qRegisterMetaType("QCallData"); - qRegisterMetaType("TransactionLogEntry"); + qRegisterMetaType("RecordLogEntry"); connect(this, &ClientModel::runComplete, this, &ClientModel::showDebugger, Qt::QueuedConnection); m_client.reset(new MixClient(QStandardPaths::writableLocation(QStandardPaths::TempLocation).toStdString())); @@ -313,10 +313,10 @@ void ClientModel::showDebuggerForTransaction(ExecutionResult const& _t) } -void ClientModel::debugTransaction(unsigned _block, unsigned _index) +void ClientModel::debugRecord(unsigned _index) { - auto const& t = m_client->execution(_block, _index); - showDebuggerForTransaction(t); + ExecutionResult const& e = m_client->executions().at(_index); + showDebuggerForTransaction(e); } void ClientModel::showDebugError(QString const& _error) @@ -346,9 +346,10 @@ void ClientModel::onStateReset() void ClientModel::onNewTransaction() { - unsigned block = m_client->number() + 1; - unsigned index = m_client->pendingExecutions().size() - 1; ExecutionResult const& tr = m_client->lastExecution(); + unsigned block = m_client->number() + 1; + unsigned recordIndex = m_client->executions().size() - 1; + QString transactionIndex = tr.isCall() ? QObject::tr("Call") : QString("%1:%2").arg(block).arg(tr.transactionIndex); QString address = QString::fromStdString(toJS(tr.address)); QString value = QString::fromStdString(dev::toString(tr.value)); QString contract = address; @@ -359,7 +360,7 @@ void ClientModel::onNewTransaction() //TODO: handle value transfer FixedHash<4> functionHash; - bool call = false; + bool abi = false; if (creation) { //contract creation @@ -374,12 +375,12 @@ void ClientModel::onNewTransaction() } else { - //call + //transaction/call if (tr.transactionData.size() > 0 && tr.transactionData.front().size() >= 4) { functionHash = FixedHash<4>(tr.transactionData.front().data(), FixedHash<4>::ConstructFromPointer); function = QString::fromStdString(toJS(functionHash)); - call = true; + abi = true; } else function = QObject::tr(""); @@ -393,7 +394,7 @@ void ClientModel::onNewTransaction() auto compilerRes = m_context->codeModel()->code(); QContractDefinition* def = compilerRes->contract(); contract = def->name(); - if (call) + if (abi) { QFunctionDefinition* funcDef = def->getFunction(functionHash); if (funcDef) @@ -407,9 +408,9 @@ void ClientModel::onNewTransaction() } } - TransactionLogEntry* log = new TransactionLogEntry(block, index, contract, function, value, address, returned); + RecordLogEntry* log = new RecordLogEntry(recordIndex, transactionIndex, contract, function, value, address, returned, tr.isCall()); QQmlEngine::setObjectOwnership(log, QQmlEngine::JavaScriptOwnership); - emit newTransaction(log); + emit newRecord(log); } } diff --git a/mix/ClientModel.h b/mix/ClientModel.h index bb912f983..530dc50cf 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -69,13 +69,13 @@ struct TransactionSettings /// UI Transaction log record -class TransactionLogEntry: public QObject +class RecordLogEntry: public QObject { Q_OBJECT - /// Transaction block number - Q_PROPERTY(unsigned block MEMBER m_block CONSTANT) - /// Transaction index within the block - Q_PROPERTY(unsigned tindex MEMBER m_index CONSTANT) + /// Recording index + Q_PROPERTY(unsigned recordIndex MEMBER m_recordIndex CONSTANT) + /// Human readable transaction bloack and transaction index + Q_PROPERTY(QString transactionIndex MEMBER m_transactionIndex CONSTANT) /// Contract name if any Q_PROPERTY(QString contract MEMBER m_contract CONSTANT) /// Function name if any @@ -86,21 +86,25 @@ class TransactionLogEntry: public QObject Q_PROPERTY(QString address MEMBER m_address CONSTANT) /// Returned value or transaction address in case of creation Q_PROPERTY(QString returned MEMBER m_returned CONSTANT) + /// true if call, false if transaction + Q_PROPERTY(bool call MEMBER m_call CONSTANT) + public: - TransactionLogEntry(): - m_block(0), m_index(0) {} - TransactionLogEntry(int _block, int _index, QString _contract, QString _function, QString _value, QString _address, QString _returned): - m_block(_block), m_index(_index), m_contract(_contract), m_function(_function), m_value(_value), m_address(_address), m_returned(_returned) {} + RecordLogEntry(): + m_recordIndex(0), m_call(false) {} + RecordLogEntry(unsigned _recordIndex, QString _transactionIndex, QString _contract, QString _function, QString _value, QString _address, QString _returned, bool _call): + m_recordIndex(_recordIndex), m_transactionIndex(_transactionIndex), m_contract(_contract), m_function(_function), m_value(_value), m_address(_address), m_returned(_returned), m_call(_call) {} private: - unsigned m_block; - unsigned m_index; + unsigned m_recordIndex; + QString m_transactionIndex; QString m_contract; QString m_function; QString m_value; QString m_address; QString m_returned; + bool m_call; }; /** @@ -133,8 +137,8 @@ public slots: /// Setup state, run transaction sequence, show debugger for the last transaction /// @param _state JS object with state configuration void setupState(QVariantMap _state); - /// Show the debugger for a specified transaction - Q_INVOKABLE void debugTransaction(unsigned _block, unsigned _index); + /// Show the debugger for a specified record + Q_INVOKABLE void debugRecord(unsigned _index); private slots: /// Update UI with machine states result. Display a modal dialog. @@ -168,7 +172,7 @@ signals: /// @param _message RPC response in Json format void apiResponse(QString const& _message); /// New transaction log entry - void newTransaction(TransactionLogEntry* _tr); + void newRecord(RecordLogEntry* _r); /// State (transaction log) cleared void stateCleared(); diff --git a/mix/MachineStates.h b/mix/MachineStates.h index d19fd9b74..9506dcf63 100644 --- a/mix/MachineStates.h +++ b/mix/MachineStates.h @@ -61,7 +61,7 @@ namespace mix */ struct ExecutionResult { - ExecutionResult() : receipt(dev::h256(), dev::h256(), dev::eth::LogEntries()) {} + ExecutionResult(): transactionIndex(std::numeric_limits::max()) {} std::vector machineStates; std::vector transactionData; @@ -71,9 +71,11 @@ namespace mix dev::Address sender; dev::Address contractAddress; dev::u256 value; - dev::eth::TransactionReceipt receipt; + unsigned transactionIndex; + + bool isCall() const { return transactionIndex == std::numeric_limits::max(); } }; using ExecutionResults = std::vector; } -} \ No newline at end of file +} diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index f182211c9..b2a367929 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -15,7 +15,6 @@ along with cpp-ethereum. If not, see . */ /** @file MixClient.cpp - * @author Yann yann@ethdev.com * @author Arkadiy Paronyan arkadiy@ethdev.com * @date 2015 * Ethereum IDE client. @@ -90,11 +89,10 @@ void MixClient::resetState(u256 _balance) m_state = eth::State(m_userAccount.address(), m_stateDB, BaseState::Empty); m_state.sync(bc()); m_startState = m_state; - m_pendingExecutions.clear(); m_executions.clear(); } -void MixClient::executeTransaction(Transaction const& _t, State& _state) +void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _call) { bytes rlp = _t.rlp(); @@ -171,30 +169,33 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state) d.value = _t.value(); if (_t.isCreation()) d.contractAddress = right160(sha3(rlpList(_t.sender(), _t.nonce()))); - d.receipt = TransactionReceipt(execState.rootHash(), execution.gasUsed(), execution.logs()); //TODO: track gas usage - m_pendingExecutions.emplace_back(std::move(d)); + if (!_call) + d.transactionIndex = m_state.pending().size(); + m_executions.emplace_back(std::move(d)); // execute on a state - _state.execute(lastHashes, rlp, nullptr, true); - - // collect watches - h256Set changed; - Guard l(m_filterLock); - for (std::pair& i: m_filters) - if ((unsigned)i.second.filter.latest() > bc().number()) - { - // acceptable number. - auto m = i.second.filter.matches(_state.receipt(_state.pending().size() - 1)); - if (m.size()) + if (!_call) + { + _state.execute(lastHashes, rlp, nullptr, true); + // collect watches + h256Set changed; + Guard l(m_filterLock); + for (std::pair& i: m_filters) + if ((unsigned)i.second.filter.latest() > bc().number()) { - // filter catches them - for (LogEntry const& l: m) - i.second.changes.push_back(LocalisedLogEntry(l, bc().number() + 1)); - changed.insert(i.first); + // acceptable number. + auto m = i.second.filter.matches(_state.receipt(_state.pending().size() - 1)); + if (m.size()) + { + // filter catches them + for (LogEntry const& l: m) + i.second.changes.push_back(LocalisedLogEntry(l, bc().number() + 1)); + changed.insert(i.first); + } } - } - changed.insert(dev::eth::PendingChangedFilter); - noteChanged(changed); + changed.insert(dev::eth::PendingChangedFilter); + noteChanged(changed); + } } void MixClient::mine() @@ -206,28 +207,18 @@ void MixClient::mine() bc().import(m_state.blockData(), m_stateDB); m_state.sync(bc()); m_startState = m_state; - m_executions.emplace_back(std::move(m_pendingExecutions)); h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter }; noteChanged(changed); } -ExecutionResult const& MixClient::execution(unsigned _block, unsigned _transaction) const -{ - if (_block == bc().number() + 1) - return m_pendingExecutions.at(_transaction); - return m_executions.at(_block - 1).at(_transaction); -} - ExecutionResult const& MixClient::lastExecution() const { - if (m_pendingExecutions.size() > 0) - return m_pendingExecutions.back(); - return m_executions.back().back(); + return m_executions.back(); } -ExecutionResults const& MixClient::pendingExecutions() const +ExecutionResults const& MixClient::executions() const { - return m_pendingExecutions; + return m_executions; } State MixClient::asOf(int _block) const @@ -246,7 +237,7 @@ void MixClient::transact(Secret _secret, u256 _value, Address _dest, bytes const WriteGuard l(x_state); u256 n = m_state.transactionsFrom(toAddress(_secret)); Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret); - executeTransaction(t, m_state); + executeTransaction(t, m_state, false); } Address MixClient::transact(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice) @@ -254,7 +245,7 @@ Address MixClient::transact(Secret _secret, u256 _endowment, bytes const& _init, WriteGuard l(x_state); u256 n = m_state.transactionsFrom(toAddress(_secret)); eth::Transaction t(_endowment, _gasPrice, _gas, _init, n, _secret); - executeTransaction(t, m_state); + executeTransaction(t, m_state, false); Address address = right160(sha3(rlpList(t.sender(), t.nonce()))); return address; } @@ -263,7 +254,7 @@ void MixClient::inject(bytesConstRef _rlp) { WriteGuard l(x_state); eth::Transaction t(_rlp, CheckSignature::None); - executeTransaction(t, m_state); + executeTransaction(t, m_state, false); } void MixClient::flushTransactions() @@ -282,8 +273,8 @@ bytes MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _ Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret); bytes rlp = t.rlp(); WriteGuard lw(x_state); //TODO: lock is required only for last execution state - executeTransaction(t, temp); - return m_pendingExecutions.back().returnValue; + executeTransaction(t, temp, true); + return lastExecution().returnValue; } u256 MixClient::balanceAt(Address _a, int _block) const diff --git a/mix/MixClient.h b/mix/MixClient.h index 9e376e5b1..9ec5ff659 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -45,9 +45,8 @@ public: void resetState(u256 _balance); KeyPair const& userAccount() const { return m_userAccount; } void mine(); - ExecutionResult const& execution(unsigned _block, unsigned _transaction) const; ExecutionResult const& lastExecution() const; - ExecutionResults const& pendingExecutions() const; + ExecutionResults const& executions() const; //dev::eth::Interface void transact(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice) override; @@ -90,7 +89,7 @@ public: bool submitNonce(h256 const&) override { return false; } private: - void executeTransaction(dev::eth::Transaction const& _t, eth::State& _state); + void executeTransaction(dev::eth::Transaction const& _t, eth::State& _state, bool _call); void noteChanged(h256Set const& _filters); dev::eth::State asOf(int _block) const; MixBlockChain& bc() { return *m_bc; } @@ -105,8 +104,7 @@ private: mutable std::mutex m_filterLock; std::map m_filters; std::map m_watches; - std::vector m_executions; - ExecutionResults m_pendingExecutions; + ExecutionResults m_executions; std::string m_dbPath; unsigned m_minigThreads; }; diff --git a/mix/qml/CallStack.qml b/mix/qml/CallStack.qml deleted file mode 100644 index 218c8c02e..000000000 --- a/mix/qml/CallStack.qml +++ /dev/null @@ -1,31 +0,0 @@ -import QtQuick 2.2 -import QtQuick.Controls.Styles 1.1 -import QtQuick.Controls 1.1 -import QtQuick.Layouts 1.1 - -Item { - property alias model: callTable.model - signal frameActivated(int index) - ColumnLayout { - anchors.fill: parent - Text { - text: qsTr("Call Stack") - Layout.fillWidth: true - } - TableView { - id: callTable - Layout.fillWidth: true - Layout.fillHeight: true - headerDelegate: null - - TableViewColumn { - role: "modelData" - title: qsTr("Address") - width: parent.width - } - onActivated: { - frameActivated(row); - } - } - } -} diff --git a/mix/qml/DebugInfoList.qml b/mix/qml/DebugInfoList.qml index 80c2d5509..c1ab11596 100644 --- a/mix/qml/DebugInfoList.qml +++ b/mix/qml/DebugInfoList.qml @@ -115,6 +115,7 @@ ColumnLayout { //storageContainer.state = ""; } } + onActivated: rowActivated(row); TableViewColumn { role: "modelData" width: parent.width diff --git a/mix/qml/TransactionLog.qml b/mix/qml/TransactionLog.qml index 970c4c21d..b31956898 100644 --- a/mix/qml/TransactionLog.qml +++ b/mix/qml/TransactionLog.qml @@ -5,6 +5,14 @@ import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 Item { + + property bool showLogs: true + property ListModel fullModel: ListModel{} + property ListModel transactionModel: ListModel{} + onShowLogsChanged: { + logTable.model = showLogs ? fullModel : transactionModel + } + Action { id: addStateAction text: "Add State" @@ -70,17 +78,13 @@ Item { } } TableView { + id: logTable Layout.fillWidth: true Layout.fillHeight: true - model: logModel + model: fullModel TableViewColumn { - role: "block" - title: qsTr("Block") - width: 40 - } - TableViewColumn { - role: "tindex" + role: "transactionIndex" title: qsTr("Index") width: 40 } @@ -110,30 +114,31 @@ Item { width: 120 } onActivated: { - var item = logModel.get(row); - clientModel.debugTransaction(item.block, item.tindex); + var item = logTable.model.get(row); + clientModel.debugRecord(item.recordIndex); } Keys.onPressed: { - if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_C && currentRow >=0 && currentRow < logModel.count) { - var item = logModel.get(currentRow); + if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_C && currentRow >=0 && currentRow < logTable.model.count) { + var item = logTable.model.get(currentRow); appContext.toClipboard(item.returned); } } } } - ListModel { - id: logModel - } - Connections { target: clientModel onStateCleared: { - logModel.clear(); + fullModel.clear(); + transactionModel.clear(); } - onNewTransaction: { + onNewRecord: { if (recording.checked) - logModel.append(_tr); + { + fullModel.append(_r); + if (!_r.call) + transactionModel.append(_r); + } } } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index 7998cbb20..ea5d6dd04 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -54,6 +54,7 @@ ApplicationWindow { MenuItem { action: toggleTransactionLogAction } MenuItem { action: toggleWebPreviewAction } MenuItem { action: toggleWebPreviewOrientationAction } + MenuItem { action: toggleCallsInLog } } } @@ -162,6 +163,15 @@ ApplicationWindow { onTriggered: mainContent.toggleWebPreviewOrientation(); } + Action { + id: toggleCallsInLog + text: qsTr("Show Calls in Transaction Log") + shortcut: "" + checkable: true + checked: mainContent.rightPane.transactionLog.showLogs + onTriggered: mainContent.rightPane.transactionLog.showLogs = !mainContent.rightPane.transactionLog.showLogs + } + Action { id: toggleRunOnLoadAction text: qsTr("Load State on Startup") diff --git a/mix/res.qrc b/mix/res.qrc index d17c32549..a33323870 100644 --- a/mix/res.qrc +++ b/mix/res.qrc @@ -61,7 +61,6 @@ stdc/std.sol qml/TransactionLog.qml res/mix_256x256x32.png - qml/CallStack.qml qml/QVariableDeclaration.qml qml/Style.qml qml/qmldir From 82250e1a8eb5542ddbc11f9dc0265c5068847012 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Tue, 10 Feb 2015 00:02:01 +0800 Subject: [PATCH 06/10] simplify ether unit with templates --- libethcore/CommonEth.cpp | 41 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 7e3305963..7153cd9eb 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -35,27 +35,30 @@ namespace eth const unsigned c_protocolVersion = 53; const unsigned c_databaseVersion = 5; +template constexpr u256 eth_unit() { return eth_unit() * u256(1000); } +template <> constexpr u256 eth_unit<0>() { return u256(1); } + static const vector> g_units = { - {((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000, "Uether"}, - {((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000, "Vether"}, - {((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000, "Dether"}, - {(((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000, "Nether"}, - {(((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000, "Yether"}, - {(((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000, "Zether"}, - {((u256(1000000000) * 1000000000) * 1000000000) * 1000000000, "Eether"}, - {((u256(1000000000) * 1000000000) * 1000000000) * 1000000, "Pether"}, - {((u256(1000000000) * 1000000000) * 1000000000) * 1000, "Tether"}, - {(u256(1000000000) * 1000000000) * 1000000000, "Gether"}, - {(u256(1000000000) * 1000000000) * 1000000, "Mether"}, - {(u256(1000000000) * 1000000000) * 1000, "grand"}, - {u256(1000000000) * 1000000000, "ether"}, - {u256(1000000000) * 1000000, "finney"}, - {u256(1000000000) * 1000, "szabo"}, - {u256(1000000000), "Gwei"}, - {u256(1000000), "Mwei"}, - {u256(1000), "Kwei"}, - {u256(1), "wei"} + {eth_unit<18>(), "Uether"}, + {eth_unit<17>(), "Vether"}, + {eth_unit<16>(), "Dether"}, + {eth_unit<15>(), "Nether"}, + {eth_unit<14>(), "Yether"}, + {eth_unit<13>(), "Zether"}, + {eth_unit<12>(), "Eether"}, + {eth_unit<11>(), "Pether"}, + {eth_unit<10>(), "Tether"}, + {eth_unit<9>(), "Gether"}, + {eth_unit<8>(), "Mether"}, + {eth_unit<7>(), "grand"}, + {eth_unit<6>(), "ether"}, + {eth_unit<5>(), "finney"}, + {eth_unit<4>(), "szabo"}, + {eth_unit<3>(), "Gwei"}, + {eth_unit<2>(), "Mwei"}, + {eth_unit<1>(), "Kwei"}, + {eth_unit<0>(), "wei"} }; vector> const& units() From df03f575d26d42110c430acde35a4802862fd15a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 9 Feb 2015 08:38:49 -0800 Subject: [PATCH 07/10] Minor type fix in EVM. --- libevm/VM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libevm/VM.cpp b/libevm/VM.cpp index 45017db9c..9274628fb 100644 --- a/libevm/VM.cpp +++ b/libevm/VM.cpp @@ -354,7 +354,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) auto base = m_stack.back(); auto expon = m_stack[m_stack.size() - 2]; m_stack.pop_back(); - m_stack.back() = (u256)boost::multiprecision::powm((bigint)base, (bigint)expon, bigint(2) << 256); + m_stack.back() = (u256)boost::multiprecision::powm((bigint)base, (bigint)expon, bigint(1) << 256); break; } case Instruction::NOT: From 86bc98c004c67507c30fb7bcc60c3f90a527718f Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 9 Feb 2015 08:39:25 -0800 Subject: [PATCH 08/10] Related typo fix. --- libevmcore/Assembly.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libevmcore/Assembly.cpp b/libevmcore/Assembly.cpp index f7a71102f..889865d9f 100644 --- a/libevmcore/Assembly.cpp +++ b/libevmcore/Assembly.cpp @@ -291,7 +291,7 @@ Assembly& Assembly::optimise(bool _enable) { Instruction::SDIV, [](u256 a, u256 b)->u256{return s2u(u2s(a) / u2s(b));} }, { Instruction::MOD, [](u256 a, u256 b)->u256{return a % b;} }, { Instruction::SMOD, [](u256 a, u256 b)->u256{return s2u(u2s(a) % u2s(b));} }, - { Instruction::EXP, [](u256 a, u256 b)->u256{return (u256)boost::multiprecision::powm((bigint)a, (bigint)b, bigint(2) << 256);} }, + { Instruction::EXP, [](u256 a, u256 b)->u256{return (u256)boost::multiprecision::powm((bigint)a, (bigint)b, bigint(1) << 256);} }, { Instruction::SIGNEXTEND, signextend }, { Instruction::LT, [](u256 a, u256 b)->u256{return a < b ? 1 : 0;} }, { Instruction::GT, [](u256 a, u256 b)->u256{return a > b ? 1 : 0;} }, From 11cbd42220fb566f02605c2ff952d362014f3303 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 9 Feb 2015 12:34:31 -0800 Subject: [PATCH 09/10] Cleanups for ether denominations. --- libethcore/CommonEth.cpp | 61 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 7153cd9eb..f71969525 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -35,35 +35,42 @@ namespace eth const unsigned c_protocolVersion = 53; const unsigned c_databaseVersion = 5; -template constexpr u256 eth_unit() { return eth_unit() * u256(1000); } -template <> constexpr u256 eth_unit<0>() { return u256(1); } +template constexpr u256 exp10() +{ + return exp10() * u256(10); +} -static const vector> g_units = +template <> constexpr u256 exp10<0>() { - {eth_unit<18>(), "Uether"}, - {eth_unit<17>(), "Vether"}, - {eth_unit<16>(), "Dether"}, - {eth_unit<15>(), "Nether"}, - {eth_unit<14>(), "Yether"}, - {eth_unit<13>(), "Zether"}, - {eth_unit<12>(), "Eether"}, - {eth_unit<11>(), "Pether"}, - {eth_unit<10>(), "Tether"}, - {eth_unit<9>(), "Gether"}, - {eth_unit<8>(), "Mether"}, - {eth_unit<7>(), "grand"}, - {eth_unit<6>(), "ether"}, - {eth_unit<5>(), "finney"}, - {eth_unit<4>(), "szabo"}, - {eth_unit<3>(), "Gwei"}, - {eth_unit<2>(), "Mwei"}, - {eth_unit<1>(), "Kwei"}, - {eth_unit<0>(), "wei"} -}; + return u256(1); +} vector> const& units() { - return g_units; + static const vector> s_units = + { + {exp10<54>(), "Uether"}, + {exp10<51>(), "Vether"}, + {exp10<48>(), "Dether"}, + {exp10<45>(), "Nether"}, + {exp10<42>(), "Yether"}, + {exp10<39>(), "Zether"}, + {exp10<36>(), "Eether"}, + {exp10<33>(), "Pether"}, + {exp10<30>(), "Tether"}, + {exp10<27>(), "Gether"}, + {exp10<24>(), "Mether"}, + {exp10<21>(), "grand"}, + {exp10<18>(), "ether"}, + {exp10<15>(), "finney"}, + {exp10<12>(), "szabo"}, + {exp10<9>(), "Gwei"}, + {exp10<6>(), "Mwei"}, + {exp10<3>(), "Kwei"}, + {exp10<0>(), "wei"} + }; + + return s_units; } std::string formatBalance(bigint const& _b) @@ -78,13 +85,13 @@ std::string formatBalance(bigint const& _b) else b = (u256)_b; - if (b > g_units[0].first * 10000) + if (b > units()[0].first * 10000) { - ret << (b / g_units[0].first) << " " << g_units[0].second; + ret << (b / units()[0].first) << " " << units()[0].second; return ret.str(); } ret << setprecision(5); - for (auto const& i: g_units) + for (auto const& i: units()) if (i.first != 1 && b >= i.first * 100) { ret << (double(b / (i.first / 1000)) / 1000.0) << " " << i.second; From d2165828ff663600e5347644b029e49693088e61 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 9 Feb 2015 13:39:01 -0800 Subject: [PATCH 10/10] Fixed #988. --- CMakeLists.txt | 4 ++++ test/CMakeLists.txt | 7 ++++--- test/natspec.cpp | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd79112f4..a3adde425 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,10 @@ function(configureProject) if (EVMJIT) add_definitions(-DETH_EVMJIT) endif() + + if (HEADLESS) + add_definitions(-DETH_HEADLESS) + endif() endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 36876eea6..ab8afcd70 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,9 +21,10 @@ target_link_libraries(testeth ethereum) target_link_libraries(testeth ethcore) target_link_libraries(testeth secp256k1) target_link_libraries(testeth solidity) -target_link_libraries(testeth webthree) -target_link_libraries(testeth natspec) - +if (NOT HEADLESS) + target_link_libraries(testeth webthree) + target_link_libraries(testeth natspec) +endif() if (JSONRPC) target_link_libraries(testeth web3jsonrpc) target_link_libraries(testeth ${JSON_RPC_CPP_CLIENT_LIBRARIES}) diff --git a/test/natspec.cpp b/test/natspec.cpp index 827f96625..8ba660418 100644 --- a/test/natspec.cpp +++ b/test/natspec.cpp @@ -19,6 +19,8 @@ * @date 2015 */ +#if !ETH_HEADLESS + #include #include #include @@ -110,3 +112,5 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_error) } BOOST_AUTO_TEST_SUITE_END() + +#endif