From 8580f916786b6cc2a0b3964dabb4cffa290c023b Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 15 Jun 2015 08:11:02 +0200 Subject: [PATCH 01/14] separated JSConsole core --- eth/main.cpp | 4 +- libjsconsole/JSConsole.cpp | 63 +------------------------------- libjsconsole/JSConsole.h | 65 +++++++++++++++++++++++++-------- libjsconsole/JSLocalConsole.cpp | 36 ++++++++++++++++++ libjsconsole/JSLocalConsole.h | 51 ++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 80 deletions(-) create mode 100644 libjsconsole/JSLocalConsole.cpp create mode 100644 libjsconsole/JSLocalConsole.h diff --git a/eth/main.cpp b/eth/main.cpp index 4b23ef62a..71fb535ea 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -41,7 +41,7 @@ #include #if ETH_JSCONSOLE || !ETH_TRUE -#include +#include #endif #if ETH_READLINE || !ETH_TRUE #include @@ -1696,7 +1696,7 @@ int main(int argc, char** argv) if (useConsole) { #if ETH_JSCONSOLE - JSConsole console(web3, make_shared([&](){return web3.ethereum();}, getAccountPassword, keyManager)); + JSLocalConsole console(web3, make_shared([&](){return web3.ethereum();}, getAccountPassword, keyManager)); while (!g_exit) { console.repl(); diff --git a/libjsconsole/JSConsole.cpp b/libjsconsole/JSConsole.cpp index d1f7c0264..61376de79 100644 --- a/libjsconsole/JSConsole.cpp +++ b/libjsconsole/JSConsole.cpp @@ -20,66 +20,5 @@ * Ethereum client. */ -#include -#include -#include -#include "JSConsole.h" -#include "JSV8Connector.h" - -// TODO! make readline optional! -#include -#include - -using namespace std; -using namespace dev; -using namespace dev::eth; - -JSConsole::JSConsole(WebThreeDirect& _web3, shared_ptr const& _accounts): - m_engine(), - m_printer(m_engine) -{ - m_jsonrpcConnector.reset(new JSV8Connector(m_engine)); - m_jsonrpcServer.reset(new WebThreeStubServer(*m_jsonrpcConnector.get(), _web3, _accounts, vector())); -} - -JSConsole::~JSConsole() {} -void JSConsole::repl() const -{ - string cmd = ""; - g_logPost = [](std::string const& a, char const*) { cout << "\r \r" << a << endl << flush; rl_forced_update_display(); }; - - bool isEmpty = true; - int openBrackets = 0; - do { - char* buff = readline(promptForIndentionLevel(openBrackets).c_str()); - isEmpty = !(buff && *buff); - if (!isEmpty) - { - cmd += string(buff); - cmd += " "; - free(buff); - int open = count(cmd.begin(), cmd.end(), '{'); - open += count(cmd.begin(), cmd.end(), '('); - int closed = count(cmd.begin(), cmd.end(), '}'); - closed += count(cmd.begin(), cmd.end(), ')'); - openBrackets = open - closed; - } - } while (openBrackets > 0); - - if (!isEmpty) - { - add_history(cmd.c_str()); - auto value = m_engine.eval(cmd.c_str()); - string result = m_printer.prettyPrint(value).cstr(); - cout << result << endl; - } -} - -std::string JSConsole::promptForIndentionLevel(int _i) const -{ - if (_i == 0) - return "> "; - - return string((_i + 1) * 2, ' '); -} +#include "JSConsole.h" diff --git a/libjsconsole/JSConsole.h b/libjsconsole/JSConsole.h index b7aded4f3..b53f69e9f 100644 --- a/libjsconsole/JSConsole.h +++ b/libjsconsole/JSConsole.h @@ -22,33 +22,66 @@ #pragma once -#include -#include - -class WebThreeStubServer; -namespace jsonrpc { class AbstractServerConnector; } +#include +// TODO! make readline optional! +#include +#include namespace dev { namespace eth { -class AccountHolder; - +template class JSConsole { public: - JSConsole(WebThreeDirect& _web3, std::shared_ptr const& _accounts); - ~JSConsole(); - void repl() const; + JSConsole(): m_engine(Engine()), m_printer(Printer(m_engine)) {}; + ~JSConsole() {}; + + void repl() const + { + std::string cmd = ""; + g_logPost = [](std::string const& a, char const*) { std::cout << "\r \r" << a << std::endl << std::flush; rl_forced_update_display(); }; + + bool isEmpty = true; + int openBrackets = 0; + do { + char* buff = readline(promptForIndentionLevel(openBrackets).c_str()); + isEmpty = !(buff && *buff); + if (!isEmpty) + { + cmd += std::string(buff); + cmd += " "; + free(buff); + int open = std::count(cmd.begin(), cmd.end(), '{'); + open += std::count(cmd.begin(), cmd.end(), '('); + int closed = std::count(cmd.begin(), cmd.end(), '}'); + closed += std::count(cmd.begin(), cmd.end(), ')'); + openBrackets = open - closed; + } + } while (openBrackets > 0); + + if (!isEmpty) + { + add_history(cmd.c_str()); + auto value = m_engine.eval(cmd.c_str()); + std::string result = m_printer.prettyPrint(value).cstr(); + std::cout << result << std::endl; + } + } + +protected: + Engine m_engine; + Printer m_printer; -private: - std::string promptForIndentionLevel(int _i) const; + virtual std::string promptForIndentionLevel(int _i) const + { + if (_i == 0) + return "> "; - JSV8Engine m_engine; - JSV8Printer m_printer; - std::unique_ptr m_jsonrpcServer; - std::unique_ptr m_jsonrpcConnector; + return std::string((_i + 1) * 2, ' '); + } }; } diff --git a/libjsconsole/JSLocalConsole.cpp b/libjsconsole/JSLocalConsole.cpp new file mode 100644 index 000000000..43fc259a3 --- /dev/null +++ b/libjsconsole/JSLocalConsole.cpp @@ -0,0 +1,36 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file JSLocalConsole.cpp + * @author Marek Kotewicz + * @date 2015 + * Ethereum client. + */ + +#include +#include +#include "JSLocalConsole.h" +#include "JSV8Connector.h" + +using namespace std; +using namespace dev; +using namespace dev::eth; + +JSLocalConsole::JSLocalConsole(WebThreeDirect& _web3, shared_ptr const& _accounts) +{ + m_jsonrpcConnector.reset(new JSV8Connector(m_engine)); +// m_jsonrpcServer.reset(new WebThreeStubServer(*m_jsonrpcConnector.get(), _web3, _accounts, vector())); +} diff --git a/libjsconsole/JSLocalConsole.h b/libjsconsole/JSLocalConsole.h new file mode 100644 index 000000000..126127b35 --- /dev/null +++ b/libjsconsole/JSLocalConsole.h @@ -0,0 +1,51 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file JSLocalConsole.h + * @author Marek Kotewicz + * @date 2015 + * Ethereum client. + */ + +#pragma once + +#include +#include +#include "JSConsole.h" + +class WebThreeStubServer; +namespace jsonrpc { class AbstractServerConnector; } + +namespace dev +{ +namespace eth +{ + +class AccountHolder; + +class JSLocalConsole: public JSConsole +{ +public: + JSLocalConsole(WebThreeDirect& _web3, std::shared_ptr const& _accounts); + virtual ~JSLocalConsole() {}; + +private: + std::unique_ptr m_jsonrpcServer; + std::unique_ptr m_jsonrpcConnector; +}; + +} +} From 6d87e226e01c4034ee4ede636180e63e346d7cb5 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 15 Jun 2015 09:57:47 +0200 Subject: [PATCH 02/14] js remote console && remote connector --- cmake/EthDependencies.cmake | 8 ++--- cmake/FindCURL.cmake | 16 +++++----- libjsconsole/CMakeLists.txt | 2 ++ libjsconsole/CURLRequest.cpp | 48 ++++++++++++++++++++++++++++ libjsconsole/CURLRequest.h | 38 ++++++++++++++++++++++ libjsconsole/JSRemoteConsole.cpp | 5 +++ libjsconsole/JSRemoteConsole.h | 22 +++++++++++++ libjsconsole/JSV8Connector.h | 2 +- libjsconsole/JSV8RemoteConnector.cpp | 22 +++++++++++++ libjsconsole/JSV8RemoteConnector.h | 30 +++++++++++++++++ 10 files changed, 180 insertions(+), 13 deletions(-) create mode 100644 libjsconsole/CURLRequest.cpp create mode 100644 libjsconsole/CURLRequest.h create mode 100644 libjsconsole/JSRemoteConsole.cpp create mode 100644 libjsconsole/JSRemoteConsole.h create mode 100644 libjsconsole/JSV8RemoteConnector.cpp create mode 100644 libjsconsole/JSV8RemoteConnector.h diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index 9a18a98e7..b47d06b40 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -103,11 +103,11 @@ if (GMP_FOUND) message(" - gmp lib : ${GMP_LIBRARIES}") endif() -# curl is only requried for tests -# TODO specify min curl version, on windows we are currently using 7.29 +# m_curl is only requried for tests +# TODO specify min m_curl version, on windows we are currently using 7.29 find_package (CURL) -message(" - curl header: ${CURL_INCLUDE_DIRS}") -message(" - curl lib : ${CURL_LIBRARIES}") +message(" - m_curl header: ${CURL_INCLUDE_DIRS}") +message(" - m_curl lib : ${CURL_LIBRARIES}") # cpuid required for eth find_package (Cpuid) diff --git a/cmake/FindCURL.cmake b/cmake/FindCURL.cmake index f9d2693ec..35d75b8de 100644 --- a/cmake/FindCURL.cmake +++ b/cmake/FindCURL.cmake @@ -1,26 +1,26 @@ # Find CURL # -# Find the curl includes and library +# Find the m_curl includes and library # # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH # # This module defines # CURL_INCLUDE_DIRS, where to find header, etc. -# CURL_LIBRARIES, the libraries needed to use curl. -# CURL_FOUND, If false, do not try to use curl. +# CURL_LIBRARIES, the libraries needed to use m_curl. +# CURL_FOUND, If false, do not try to use m_curl. # only look in default directories find_path( CURL_INCLUDE_DIR - NAMES curl/curl.h - DOC "curl include dir" + NAMES m_curl/m_curl.h + DOC "m_curl include dir" ) find_library( CURL_LIBRARY # names from cmake's FindCURL - NAMES curl curllib libcurl_imp curllib_static libcurl - DOC "curl library" + NAMES m_curl curllib libcurl_imp curllib_static libcurl + DOC "m_curl library" ) set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) @@ -34,7 +34,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") find_library( CURL_LIBRARY_DEBUG NAMES curld libcurld - DOC "curl debug library" + DOC "m_curl debug library" ) set(CURL_LIBRARIES optimized ${CURL_LIBRARIES} debug ${CURL_LIBRARY_DEBUG}) diff --git a/libjsconsole/CMakeLists.txt b/libjsconsole/CMakeLists.txt index e8f98de88..39bba922a 100644 --- a/libjsconsole/CMakeLists.txt +++ b/libjsconsole/CMakeLists.txt @@ -14,6 +14,7 @@ include_directories(BEFORE ${V8_INCLUDE_DIRS}) include_directories(BEFORE ..) include_directories(${READLINE_INCLUDE_DIRS}) include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) +include_directories(${CURL_INCLUDE_DIRS}) set(EXECUTABLE jsconsole) @@ -28,3 +29,4 @@ target_link_libraries(${EXECUTABLE} web3jsonrpc) install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) + diff --git a/libjsconsole/CURLRequest.cpp b/libjsconsole/CURLRequest.cpp new file mode 100644 index 000000000..683ccb05a --- /dev/null +++ b/libjsconsole/CURLRequest.cpp @@ -0,0 +1,48 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +#include "CURLRequest.h" + +using namespace std; + +static size_t write_data(void *buffer, size_t elementSize, size_t numberOfElements, void *userp) +{ + static_cast(userp)->write((const char *)buffer, elementSize * numberOfElements); + return elementSize * numberOfElements; +} + +void CURLRequest::commonCURLPreparation() +{ + m_resultBuffer.str(""); + curl_easy_setopt(m_curl, CURLOPT_URL, (m_url + "?").c_str()); + curl_easy_setopt(m_curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, write_data); + curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &m_resultBuffer); +} + +std::tuple CURLRequest::commonCURLPerform() +{ + CURLcode res = curl_easy_perform(m_curl); + if (res != CURLE_OK) { + throw runtime_error(curl_easy_strerror(res)); + } + long httpCode = 0; + curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &httpCode); + return make_tuple(httpCode, m_resultBuffer.str()); +} + +std::tuple CURLRequest::post() +{ + commonCURLPreparation(); + curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, m_body.c_str()); + + struct curl_slist *headerList = NULL; + headerList = curl_slist_append(headerList, "Content-Type: application/json"); + curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, headerList); + + auto result = commonCURLPerform(); + + curl_slist_free_all(headerList); + return result; +} diff --git a/libjsconsole/CURLRequest.h b/libjsconsole/CURLRequest.h new file mode 100644 index 000000000..372c449ca --- /dev/null +++ b/libjsconsole/CURLRequest.h @@ -0,0 +1,38 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +// based on http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c/27026683#27026683 + +#include +#include +#include +#include + +class CURLRequest +{ +public: + CURLRequest(): m_curl(curl_easy_init()) {}; + ~CURLRequest() + { + if (m_curl) + curl_easy_cleanup(m_curl); + } + + void setUrl(std::string _url) { m_url = _url; } + void setBody(std::string _body) { m_body = _body; } + + std::tuple post(); + +private: + std::string m_url; + std::string m_body; + + CURL* m_curl; + std::stringstream m_resultBuffer; + + void commonCURLPreparation(); + std::tuple commonCURLPerform(); +}; + + diff --git a/libjsconsole/JSRemoteConsole.cpp b/libjsconsole/JSRemoteConsole.cpp new file mode 100644 index 000000000..69444854b --- /dev/null +++ b/libjsconsole/JSRemoteConsole.cpp @@ -0,0 +1,5 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +#include "JSRemoteConsole.h" diff --git a/libjsconsole/JSRemoteConsole.h b/libjsconsole/JSRemoteConsole.h new file mode 100644 index 000000000..fa2c0267d --- /dev/null +++ b/libjsconsole/JSRemoteConsole.h @@ -0,0 +1,22 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +#pragma once + +#include +#include +#include "JSConsole.h" + +namespace dev +{ +namespace eth +{ + +class JSRemoteConsole: public JSConsole +{ + +}; + +} +} diff --git a/libjsconsole/JSV8Connector.h b/libjsconsole/JSV8Connector.h index 98cef4c2c..34c38fed1 100644 --- a/libjsconsole/JSV8Connector.h +++ b/libjsconsole/JSV8Connector.h @@ -43,7 +43,7 @@ public: bool SendResponse(std::string const& _response, void* _addInfo = nullptr); // implement JSV8RPC interface - void onSend(char const* payload); + void onSend(char const* _payload); }; } diff --git a/libjsconsole/JSV8RemoteConnector.cpp b/libjsconsole/JSV8RemoteConnector.cpp new file mode 100644 index 000000000..483f8bd44 --- /dev/null +++ b/libjsconsole/JSV8RemoteConnector.cpp @@ -0,0 +1,22 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +#include "JSV8RemoteConnector.h" +#include "CURLRequest.h" + +using namespace std; +using namespace dev; +using namespace dev::eth; + +void JSV8RemoteConnector::onSend(char const* _payload) +{ + CURLRequest request; + request.setUrl(m_url); + request.setBody(_payload); + long code; + string response; + tie(code, response) = request.post(); + (void)code; + m_lastResponse = response.c_str(); +} diff --git a/libjsconsole/JSV8RemoteConnector.h b/libjsconsole/JSV8RemoteConnector.h new file mode 100644 index 000000000..8f1a33847 --- /dev/null +++ b/libjsconsole/JSV8RemoteConnector.h @@ -0,0 +1,30 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +#pragma once + +#include +#include + +namespace dev +{ +namespace eth +{ + +class JSV8RemoteConnector : public JSV8RPC +{ + +public: + JSV8RemoteConnector(JSV8Engine const& _engine, std::string _url): JSV8RPC(_engine), m_url(_url) {} + virtual ~JSV8RemoteConnector(); + + // implement JSV8RPC interface + void onSend(char const* _payload); + +private: + std::string m_url; +}; + +} +} From 736bb0438995e0ba6793ecd338447a900127a7d3 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 15 Jun 2015 10:05:41 +0200 Subject: [PATCH 03/14] missing implementation of jsremoteconsole --- libjsconsole/JSRemoteConsole.cpp | 5 +++++ libjsconsole/JSRemoteConsole.h | 8 ++++++++ libjsconsole/JSV8RemoteConnector.h | 1 + 3 files changed, 14 insertions(+) diff --git a/libjsconsole/JSRemoteConsole.cpp b/libjsconsole/JSRemoteConsole.cpp index 69444854b..1b42bddde 100644 --- a/libjsconsole/JSRemoteConsole.cpp +++ b/libjsconsole/JSRemoteConsole.cpp @@ -3,3 +3,8 @@ // #include "JSRemoteConsole.h" + +using namespace std; +using namespace dev; +using namespace dev::eth; + diff --git a/libjsconsole/JSRemoteConsole.h b/libjsconsole/JSRemoteConsole.h index fa2c0267d..b9303027f 100644 --- a/libjsconsole/JSRemoteConsole.h +++ b/libjsconsole/JSRemoteConsole.h @@ -6,6 +6,7 @@ #include #include +#include "JSV8RemoteConnector.h" #include "JSConsole.h" namespace dev @@ -16,6 +17,13 @@ namespace eth class JSRemoteConsole: public JSConsole { +public: + JSRemoteConsole(std::string _url): m_connector(m_engine, _url) {}; + virtual ~JSRemoteConsole() {}; + +private: + JSV8RemoteConnector m_connector; + }; } diff --git a/libjsconsole/JSV8RemoteConnector.h b/libjsconsole/JSV8RemoteConnector.h index 8f1a33847..b54f2efd6 100644 --- a/libjsconsole/JSV8RemoteConnector.h +++ b/libjsconsole/JSV8RemoteConnector.h @@ -24,6 +24,7 @@ public: private: std::string m_url; + }; } From ba64e80c4dff270515d0616d9784563472ad8143 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 15 Jun 2015 11:18:39 +0200 Subject: [PATCH 04/14] ethconsole executable --- CMakeLists.txt | 1 + cmake/FindCURL.cmake | 16 +++++++-------- eth/main.cpp | 2 +- ethconsole/CMakeLists.txt | 31 ++++++++++++++++++++++++++++++ ethconsole/main.cpp | 23 ++++++++++++++++++++++ libjsconsole/CMakeLists.txt | 8 ++++++-- libjsconsole/CURLRequest.cpp | 24 ++++++++++++++++++++--- libjsconsole/CURLRequest.h | 24 ++++++++++++++++++++--- libjsconsole/JSLocalConsole.cpp | 2 +- libjsconsole/JSLocalConsole.h | 5 +++-- libjsconsole/JSRemoteConsole.cpp | 27 +++++++++++++++++++------- libjsconsole/JSRemoteConsole.h | 24 ++++++++++++++++++++--- libjsconsole/JSV8RemoteConnector.h | 2 +- libweb3jsonrpc/CMakeLists.txt | 1 - 14 files changed, 158 insertions(+), 32 deletions(-) create mode 100644 ethconsole/CMakeLists.txt create mode 100644 ethconsole/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 71d12353c..15eb1b919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,6 +375,7 @@ endif () if (JSCONSOLE) add_subdirectory(libjsengine) add_subdirectory(libjsconsole) + add_subdirectory(ethconsole) endif () add_subdirectory(secp256k1) diff --git a/cmake/FindCURL.cmake b/cmake/FindCURL.cmake index 35d75b8de..f9d2693ec 100644 --- a/cmake/FindCURL.cmake +++ b/cmake/FindCURL.cmake @@ -1,26 +1,26 @@ # Find CURL # -# Find the m_curl includes and library +# Find the curl includes and library # # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH # # This module defines # CURL_INCLUDE_DIRS, where to find header, etc. -# CURL_LIBRARIES, the libraries needed to use m_curl. -# CURL_FOUND, If false, do not try to use m_curl. +# CURL_LIBRARIES, the libraries needed to use curl. +# CURL_FOUND, If false, do not try to use curl. # only look in default directories find_path( CURL_INCLUDE_DIR - NAMES m_curl/m_curl.h - DOC "m_curl include dir" + NAMES curl/curl.h + DOC "curl include dir" ) find_library( CURL_LIBRARY # names from cmake's FindCURL - NAMES m_curl curllib libcurl_imp curllib_static libcurl - DOC "m_curl library" + NAMES curl curllib libcurl_imp curllib_static libcurl + DOC "curl library" ) set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) @@ -34,7 +34,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") find_library( CURL_LIBRARY_DEBUG NAMES curld libcurld - DOC "m_curl debug library" + DOC "curl debug library" ) set(CURL_LIBRARIES optimized ${CURL_LIBRARIES} debug ${CURL_LIBRARY_DEBUG}) diff --git a/eth/main.cpp b/eth/main.cpp index 71fb535ea..cb9f3820f 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1696,7 +1696,7 @@ int main(int argc, char** argv) if (useConsole) { #if ETH_JSCONSOLE - JSLocalConsole console(web3, make_shared([&](){return web3.ethereum();}, getAccountPassword, keyManager)); + JSLocalConsole console; while (!g_exit) { console.repl(); diff --git a/ethconsole/CMakeLists.txt b/ethconsole/CMakeLists.txt new file mode 100644 index 000000000..08fa7ca83 --- /dev/null +++ b/ethconsole/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_policy(SET CMP0015 NEW) +set(CMAKE_AUTOMOC OFF) + +aux_source_directory(. SRC_LIST) + +include_directories(BEFORE ..) +include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) +include_directories(${CURL_INCLUDE_DIRS}) +include_directories(${V8_INCLUDE_DIRS}) + +set(EXECUTABLE ethconsole) + +file(GLOB HEADERS "*.h") + +add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) + +target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES}) +target_link_libraries(${EXECUTABLE} ${READLINE_LIBRARIES}) +target_link_libraries(${EXECUTABLE} ${CURL_LIBRARIES}) + +if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) + eth_copy_dlls(${EXECUTABLE} CURL_DLLS) +endif() +target_link_libraries(${EXECUTABLE} jsconsole) + +if (APPLE) + install(TARGETS ${EXECUTABLE} DESTINATION bin) +else() + eth_install_executable(${EXECUTABLE}) +endif() + diff --git a/ethconsole/main.cpp b/ethconsole/main.cpp new file mode 100644 index 000000000..5101d79b5 --- /dev/null +++ b/ethconsole/main.cpp @@ -0,0 +1,23 @@ + +#include + +using namespace std; +using namespace dev; +using namespace dev::eth; + +int main(int argc, char** argv) +{ + if (argc != 2) + { + cout << "You must provide remote url\n"; + cout << "eg:\n"; + cout << "./ethconsole http://localhost:8545\n"; + return 1; + } + + JSRemoteConsole console(argv[1]); + while (true) + console.repl(); + + return 0; +} \ No newline at end of file diff --git a/libjsconsole/CMakeLists.txt b/libjsconsole/CMakeLists.txt index 39bba922a..761435fe1 100644 --- a/libjsconsole/CMakeLists.txt +++ b/libjsconsole/CMakeLists.txt @@ -25,8 +25,12 @@ add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) target_link_libraries(${EXECUTABLE} jsengine) target_link_libraries(${EXECUTABLE} devcore) target_link_libraries(${EXECUTABLE} ${READLINE_LIBRARIES}) -target_link_libraries(${EXECUTABLE} web3jsonrpc) +target_link_libraries(${EXECUTABLE} ${JSON_RPC_CPP_SERVER_LIBRARIES}) + +target_link_libraries(${EXECUTABLE} ${CURL_LIBRARIES}) +if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) + eth_copy_dlls(${EXECUTABLE} CURL_DLLS) +endif() install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) - diff --git a/libjsconsole/CURLRequest.cpp b/libjsconsole/CURLRequest.cpp index 683ccb05a..c07059372 100644 --- a/libjsconsole/CURLRequest.cpp +++ b/libjsconsole/CURLRequest.cpp @@ -1,6 +1,24 @@ -// -// Created by Marek Kotewicz on 15/06/15. -// +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file CURLRequest.cpp + * @author Marek Kotewicz + * @date 2015 + * Ethereum client. + */ #include "CURLRequest.h" diff --git a/libjsconsole/CURLRequest.h b/libjsconsole/CURLRequest.h index 372c449ca..ea1e37d95 100644 --- a/libjsconsole/CURLRequest.h +++ b/libjsconsole/CURLRequest.h @@ -1,6 +1,24 @@ -// -// Created by Marek Kotewicz on 15/06/15. -// +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file CURLRequest.h + * @author Marek Kotewicz + * @date 2015 + * Ethereum client. + */ // based on http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c/27026683#27026683 diff --git a/libjsconsole/JSLocalConsole.cpp b/libjsconsole/JSLocalConsole.cpp index 43fc259a3..03bb07b56 100644 --- a/libjsconsole/JSLocalConsole.cpp +++ b/libjsconsole/JSLocalConsole.cpp @@ -29,7 +29,7 @@ using namespace std; using namespace dev; using namespace dev::eth; -JSLocalConsole::JSLocalConsole(WebThreeDirect& _web3, shared_ptr const& _accounts) +JSLocalConsole::JSLocalConsole() { m_jsonrpcConnector.reset(new JSV8Connector(m_engine)); // m_jsonrpcServer.reset(new WebThreeStubServer(*m_jsonrpcConnector.get(), _web3, _accounts, vector())); diff --git a/libjsconsole/JSLocalConsole.h b/libjsconsole/JSLocalConsole.h index 126127b35..e7ad1a3c3 100644 --- a/libjsconsole/JSLocalConsole.h +++ b/libjsconsole/JSLocalConsole.h @@ -39,11 +39,12 @@ class AccountHolder; class JSLocalConsole: public JSConsole { public: - JSLocalConsole(WebThreeDirect& _web3, std::shared_ptr const& _accounts); + JSLocalConsole(); virtual ~JSLocalConsole() {}; + jsonrpc::AbstractServerConnector* connector() { return m_jsonrpcConnector.get(); } + private: - std::unique_ptr m_jsonrpcServer; std::unique_ptr m_jsonrpcConnector; }; diff --git a/libjsconsole/JSRemoteConsole.cpp b/libjsconsole/JSRemoteConsole.cpp index 1b42bddde..b42c5b340 100644 --- a/libjsconsole/JSRemoteConsole.cpp +++ b/libjsconsole/JSRemoteConsole.cpp @@ -1,10 +1,23 @@ -// -// Created by Marek Kotewicz on 15/06/15. -// +/* + This file is part of cpp-ethereum. -#include "JSRemoteConsole.h" + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 General Public License for more details. -using namespace std; -using namespace dev; -using namespace dev::eth; + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file JSRemoteConsole.cpp + * @author Marek Kotewicz + * @date 2015 + * Ethereum client. + */ +#include "JSRemoteConsole.h" diff --git a/libjsconsole/JSRemoteConsole.h b/libjsconsole/JSRemoteConsole.h index b9303027f..c4d8bd7e5 100644 --- a/libjsconsole/JSRemoteConsole.h +++ b/libjsconsole/JSRemoteConsole.h @@ -1,6 +1,24 @@ -// -// Created by Marek Kotewicz on 15/06/15. -// +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file JSRemoteConsole.h + * @author Marek Kotewicz + * @date 2015 + * Ethereum client. + */ #pragma once diff --git a/libjsconsole/JSV8RemoteConnector.h b/libjsconsole/JSV8RemoteConnector.h index b54f2efd6..e0e47f9f5 100644 --- a/libjsconsole/JSV8RemoteConnector.h +++ b/libjsconsole/JSV8RemoteConnector.h @@ -17,7 +17,7 @@ class JSV8RemoteConnector : public JSV8RPC public: JSV8RemoteConnector(JSV8Engine const& _engine, std::string _url): JSV8RPC(_engine), m_url(_url) {} - virtual ~JSV8RemoteConnector(); + virtual ~JSV8RemoteConnector() {}; // implement JSV8RPC interface void onSend(char const* _payload); diff --git a/libweb3jsonrpc/CMakeLists.txt b/libweb3jsonrpc/CMakeLists.txt index e265910fa..a9d3a97e2 100644 --- a/libweb3jsonrpc/CMakeLists.txt +++ b/libweb3jsonrpc/CMakeLists.txt @@ -55,4 +55,3 @@ install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib L install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) add_custom_target(aux_json SOURCES "spec.json") - From 0385fe277b99fce1ce9b13fae3c7d1065bea2963 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 15 Jun 2015 11:33:06 +0200 Subject: [PATCH 05/14] persistant connection --- libjsconsole/CURLRequest.h | 2 ++ libjsconsole/JSV8RemoteConnector.cpp | 8 +++----- libjsconsole/JSV8RemoteConnector.h | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libjsconsole/CURLRequest.h b/libjsconsole/CURLRequest.h index ea1e37d95..4651f750c 100644 --- a/libjsconsole/CURLRequest.h +++ b/libjsconsole/CURLRequest.h @@ -22,6 +22,8 @@ // based on http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c/27026683#27026683 +#pragma once + #include #include #include diff --git a/libjsconsole/JSV8RemoteConnector.cpp b/libjsconsole/JSV8RemoteConnector.cpp index 483f8bd44..72e64faae 100644 --- a/libjsconsole/JSV8RemoteConnector.cpp +++ b/libjsconsole/JSV8RemoteConnector.cpp @@ -3,7 +3,6 @@ // #include "JSV8RemoteConnector.h" -#include "CURLRequest.h" using namespace std; using namespace dev; @@ -11,12 +10,11 @@ using namespace dev::eth; void JSV8RemoteConnector::onSend(char const* _payload) { - CURLRequest request; - request.setUrl(m_url); - request.setBody(_payload); + m_request.setUrl(m_url); + m_request.setBody(_payload); long code; string response; - tie(code, response) = request.post(); + tie(code, response) = m_request.post(); (void)code; m_lastResponse = response.c_str(); } diff --git a/libjsconsole/JSV8RemoteConnector.h b/libjsconsole/JSV8RemoteConnector.h index e0e47f9f5..867b553cb 100644 --- a/libjsconsole/JSV8RemoteConnector.h +++ b/libjsconsole/JSV8RemoteConnector.h @@ -6,6 +6,7 @@ #include #include +#include "CURLRequest.h" namespace dev { @@ -24,7 +25,7 @@ public: private: std::string m_url; - + CURLRequest m_request; }; } From 0ccc6b973dd923102725a926856dba9c83265841 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 20 Jun 2015 07:40:16 +0200 Subject: [PATCH 06/14] jsconsole session --- eth/main.cpp | 11 +++++ libjsqrc/admin.js | 120 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 libjsqrc/admin.js diff --git a/eth/main.cpp b/eth/main.cpp index cb9f3820f..a69c59b74 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1697,11 +1697,22 @@ int main(int argc, char** argv) { #if ETH_JSCONSOLE JSLocalConsole console; + + jsonrpcServer = jsonrpcServer.reset(new WebThreeStubServer(*console.connector(), web3, make_shared([&](){return web3.ethereum();}, getAccountPassword, keyManager), vector(), keyManager)); + jsonrpcServer->StartListening(); + if (jsonAdmin.empty()) + jsonAdmin = jsonrpcServer->newSession(SessionPermissions{true}); + else + jsonrpcServer->addSession(jsonAdmin, SessionPermissions{true}); + cout << "JSONRPC Admin Session Key: " << jsonAdmin << endl; + while (!g_exit) { console.repl(); stopMiningAfterXBlocks(c, n, mining); } + + jsonrpcServer->StopListening(); #endif } else diff --git a/libjsqrc/admin.js b/libjsqrc/admin.js new file mode 100644 index 000000000..abd2efcc7 --- /dev/null +++ b/libjsqrc/admin.js @@ -0,0 +1,120 @@ +web3.admin = {}; +web3.admin.setSessionKey = function(s) { web3.admin.sessionKey = s; }; + +var getSessionKey = function () { return web3.admin.sessionKey; }; + +web3._extend([ + property: 'admin', + methods: [new web3._extend.Method({ + name: 'web3.setVerbosity', + call: 'admin_web3_setVerbosity', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'net.start', + call: 'admin_net_start', + inputFormatter: [getSessionKey], + params: 1 + }), new web3._extend.Method({ + name: 'net.stop', + call: 'admin_net_stop', + inputFormatter: [getSessionKey], + params: 1 + }), new web3._extend.Method({ + name: 'net.connect' + call: 'admin_net_connect', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'net.peers', + call: 'admin_net_peers', + inputFormatter: [getSessionKey], + params: 1 + }), new web3._extend.Method({ + name: 'eth.blockQueueStatus', + call: 'admin_eth_blockQueueStatus', + inputFormatter: [getSessionKey], + params: 1 + }), new web3._extend.Method({ + name: 'eth.setAskPrice', + call: 'admin_eth_setAskPrice', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.setBidPrice', + call: 'admin_eth_setBidPrice', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.setReferencePrice', + call: 'admin_eth_setReferencePrice', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.setPriority', + call: 'admin_eth_setPriority', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.setMining', + call: 'admin_eth_setMining', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.findBlock', + call: 'admin_eth_findBlock', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.blockQueueFirstUnknown', + call: 'admin_eth_blockQueueFirstUnknown', + inputFormatter: [getSessionKey], + params: 1 + }), new web3._extend.Method({ + name: 'eth.blockQueueRetryUnknown', + call: 'admin_eth_blockQueueRetryUnknown', + inputFormatter: [getSessionKey], + params: 1 + }), new web3._extend.Method({ + name: 'eth.allAccounts', + call: 'admin_eth_allAccounts', + inputFormatter: [getSessionKey], + params: 1 + }), new web3._extend.Method({ + name: 'eth.newAccount', + call: 'admin_eth_newAccount', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.setSigningKey', + call: 'admin_eth_setSigningKey', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.setMiningBenefactor', + call: 'admin_eth_setMiningBenefactor', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.inspect', + call: 'admin_eth_inspect', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.reprocess', + call: 'admin_eth_reprocess', + inputFormatter: [null, getSessionKey], + params: 2 + }), new web3._extend.Method({ + name: 'eth.vmTrace', + call: 'admin_eth_vmTrace', + inputFormatter: [null, null, getSessionKey], + params: 3 + }), new web3._extend.Method({ + name: 'eth.getReceiptByHashAndIndex', + call: 'admin_eth_getReceiptByHashAndIndex', + inputFormatter: [null, null, getSessionKey], + params: 3 + })] +]); + From c3bf182eb37319227babe6314e42112114d552cc Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 23 Jun 2015 14:36:21 +0200 Subject: [PATCH 07/14] removed unused commented line --- libjsconsole/JSLocalConsole.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libjsconsole/JSLocalConsole.cpp b/libjsconsole/JSLocalConsole.cpp index 03bb07b56..0220e18fc 100644 --- a/libjsconsole/JSLocalConsole.cpp +++ b/libjsconsole/JSLocalConsole.cpp @@ -32,5 +32,4 @@ using namespace dev::eth; JSLocalConsole::JSLocalConsole() { m_jsonrpcConnector.reset(new JSV8Connector(m_engine)); -// m_jsonrpcServer.reset(new WebThreeStubServer(*m_jsonrpcConnector.get(), _web3, _accounts, vector())); } From 2110162a4d6e0145c3edd554c5d83aae603a54f4 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 23 Jun 2015 14:54:23 +0200 Subject: [PATCH 08/14] standalone javascript console --- libjsconsole/JSLocalConsole.cpp | 1 - libjsconsole/JSLocalConsole.h | 2 -- libjsengine/JSResources.cmake | 3 ++- libjsengine/JSV8Engine.cpp | 2 ++ libjsengine/JSV8Engine.h | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libjsconsole/JSLocalConsole.cpp b/libjsconsole/JSLocalConsole.cpp index 0220e18fc..04c6104a6 100644 --- a/libjsconsole/JSLocalConsole.cpp +++ b/libjsconsole/JSLocalConsole.cpp @@ -21,7 +21,6 @@ */ #include -#include #include "JSLocalConsole.h" #include "JSV8Connector.h" diff --git a/libjsconsole/JSLocalConsole.h b/libjsconsole/JSLocalConsole.h index e7ad1a3c3..cb520fe36 100644 --- a/libjsconsole/JSLocalConsole.h +++ b/libjsconsole/JSLocalConsole.h @@ -34,8 +34,6 @@ namespace dev namespace eth { -class AccountHolder; - class JSLocalConsole: public JSConsole { public: diff --git a/libjsengine/JSResources.cmake b/libjsengine/JSResources.cmake index d4370a8da..15e788778 100644 --- a/libjsengine/JSResources.cmake +++ b/libjsengine/JSResources.cmake @@ -1,8 +1,9 @@ set(web3 "${CMAKE_CURRENT_LIST_DIR}/../libjsqrc/ethereumjs/dist/web3.js") +set(admin "${CMAKE_CURRENT_LIST_DIR}/../libjsqrc/admin.js") set(pretty_print "${CMAKE_CURRENT_LIST_DIR}/PrettyPrint.js") set(common "${CMAKE_CURRENT_LIST_DIR}/Common.js") set(ETH_RESOURCE_NAME "JSEngineResources") set(ETH_RESOURCE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}") -set(ETH_RESOURCES "web3" "pretty_print" "common") +set(ETH_RESOURCES "web3" "pretty_print" "common" "admin") diff --git a/libjsengine/JSV8Engine.cpp b/libjsengine/JSV8Engine.cpp index 4e06f0f65..ebf0a0e72 100644 --- a/libjsengine/JSV8Engine.cpp +++ b/libjsengine/JSV8Engine.cpp @@ -143,9 +143,11 @@ JSV8Engine::JSV8Engine(): m_scope(new JSV8Scope()) JSEngineResources resources; string common = resources.loadResourceAsString("common"); string web3 = resources.loadResourceAsString("web3"); + string admin = resources.loadResourceAsString("admin"); eval(common.c_str()); eval(web3.c_str()); eval("web3 = require('web3');"); + eval(admin.c_str()); } JSV8Engine::~JSV8Engine() diff --git a/libjsengine/JSV8Engine.h b/libjsengine/JSV8Engine.h index 56459c5d0..563642d73 100644 --- a/libjsengine/JSV8Engine.h +++ b/libjsengine/JSV8Engine.h @@ -22,7 +22,10 @@ #pragma once +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" #include +#pragma clang diagnostic pop #include "JSEngine.h" namespace dev From e5af58f0d665ade3f418a7be023164f246a209a3 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 23 Jun 2015 14:55:21 +0200 Subject: [PATCH 09/14] reversed m_curl --- cmake/EthDependencies.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index 8ea8ae661..86415f2dd 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -109,11 +109,11 @@ if (GMP_FOUND) message(" - gmp lib : ${GMP_LIBRARIES}") endif() -# m_curl is only requried for tests -# TODO specify min m_curl version, on windows we are currently using 7.29 +# curl is only requried for tests +# TODO specify min curl version, on windows we are currently using 7.29 find_package (CURL) -message(" - m_curl header: ${CURL_INCLUDE_DIRS}") -message(" - m_curl lib : ${CURL_LIBRARIES}") +message(" - curl header: ${CURL_INCLUDE_DIRS}") +message(" - curl lib : ${CURL_LIBRARIES}") # cpuid required for eth find_package (Cpuid) From 3246bb99efcd05c564282665207aea4b3855498e Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 24 Jun 2015 00:23:10 +0200 Subject: [PATCH 10/14] Copy only expected arguments for constructor if statically sized. --- libsolidity/Compiler.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libsolidity/Compiler.cpp b/libsolidity/Compiler.cpp index 68052e279..f5570b98f 100644 --- a/libsolidity/Compiler.cpp +++ b/libsolidity/Compiler.cpp @@ -165,10 +165,26 @@ void Compiler::appendConstructor(FunctionDefinition const& _constructor) // copy constructor arguments from code to memory and then to stack, they are supplied after the actual program if (!_constructor.getParameters().empty()) { + unsigned argumentSize = 0; + for (ASTPointer const& var: _constructor.getParameters()) + if (var->getType()->isDynamicallySized()) + { + argumentSize = 0; + break; + } + else + argumentSize += var->getType()->getCalldataEncodedSize(); + CompilerUtils(m_context).fetchFreeMemoryPointer(); - m_context.appendProgramSize(); // program itself - // CODESIZE is program plus manually added arguments - m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB; + if (argumentSize == 0) + { + // argument size is dynamic, use CODESIZE to determine it + m_context.appendProgramSize(); // program itself + // CODESIZE is program plus manually added arguments + m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB; + } + else + m_context << u256(argumentSize); // stack: m_context << eth::Instruction::DUP1; m_context.appendProgramSize(); From ca6a3cba495744e092240c338ee9f19276ba3bbf Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 24 Jun 2015 08:01:44 +0200 Subject: [PATCH 11/14] ethconsole by default connects to http://localhost:8545 --- ethconsole/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ethconsole/main.cpp b/ethconsole/main.cpp index 3bba6f42e..102bbcb40 100644 --- a/ethconsole/main.cpp +++ b/ethconsole/main.cpp @@ -1,4 +1,5 @@ +#include #include using namespace std; @@ -7,15 +8,18 @@ using namespace dev::eth; int main(int argc, char** argv) { + string remote; if (argc != 2) { - cout << "You must provide remote url\n"; - cout << "eg:\n"; + cout << "remote url not provided\n"; + cout << "using default:\n"; cout << "./ethconsole http://localhost:8545\n"; - return 1; + remote = "http://localhost:8545\n"; } + else + remote = argv[1]; - JSRemoteConsole console(argv[1]); + JSRemoteConsole console(remote); while (true) console.readExpression(); From ffa11dd6403a58e6b08595c96440060a50f191de Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 24 Jun 2015 16:45:13 +0200 Subject: [PATCH 12/14] removed trailing ;s --- libjsconsole/CURLRequest.h | 2 +- libjsconsole/JSConsole.h | 4 ++-- libjsconsole/JSLocalConsole.h | 2 +- libjsconsole/JSRemoteConsole.h | 4 ++-- libjsconsole/JSV8RemoteConnector.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libjsconsole/CURLRequest.h b/libjsconsole/CURLRequest.h index 4651f750c..e025d1eb9 100644 --- a/libjsconsole/CURLRequest.h +++ b/libjsconsole/CURLRequest.h @@ -32,7 +32,7 @@ class CURLRequest { public: - CURLRequest(): m_curl(curl_easy_init()) {}; + CURLRequest(): m_curl(curl_easy_init()) {} ~CURLRequest() { if (m_curl) diff --git a/libjsconsole/JSConsole.h b/libjsconsole/JSConsole.h index 8babd05ca..50f6d6ae5 100644 --- a/libjsconsole/JSConsole.h +++ b/libjsconsole/JSConsole.h @@ -36,8 +36,8 @@ template class JSConsole { public: - JSConsole(): m_engine(Engine()), m_printer(Printer(m_engine)) {}; - ~JSConsole() {}; + JSConsole(): m_engine(Engine()), m_printer(Printer(m_engine)) {} + ~JSConsole() {} void readExpression() const { diff --git a/libjsconsole/JSLocalConsole.h b/libjsconsole/JSLocalConsole.h index cb520fe36..48922faee 100644 --- a/libjsconsole/JSLocalConsole.h +++ b/libjsconsole/JSLocalConsole.h @@ -38,7 +38,7 @@ class JSLocalConsole: public JSConsole { public: JSLocalConsole(); - virtual ~JSLocalConsole() {}; + virtual ~JSLocalConsole() {} jsonrpc::AbstractServerConnector* connector() { return m_jsonrpcConnector.get(); } diff --git a/libjsconsole/JSRemoteConsole.h b/libjsconsole/JSRemoteConsole.h index c4d8bd7e5..2baf516f6 100644 --- a/libjsconsole/JSRemoteConsole.h +++ b/libjsconsole/JSRemoteConsole.h @@ -36,8 +36,8 @@ class JSRemoteConsole: public JSConsole { public: - JSRemoteConsole(std::string _url): m_connector(m_engine, _url) {}; - virtual ~JSRemoteConsole() {}; + JSRemoteConsole(std::string _url): m_connector(m_engine, _url) {} + virtual ~JSRemoteConsole() {} private: JSV8RemoteConnector m_connector; diff --git a/libjsconsole/JSV8RemoteConnector.h b/libjsconsole/JSV8RemoteConnector.h index 867b553cb..5d28094ad 100644 --- a/libjsconsole/JSV8RemoteConnector.h +++ b/libjsconsole/JSV8RemoteConnector.h @@ -18,7 +18,7 @@ class JSV8RemoteConnector : public JSV8RPC public: JSV8RemoteConnector(JSV8Engine const& _engine, std::string _url): JSV8RPC(_engine), m_url(_url) {} - virtual ~JSV8RemoteConnector() {}; + virtual ~JSV8RemoteConnector() {} // implement JSV8RPC interface void onSend(char const* _payload); From 21df032a9f35aba988986e99eec45bdcd2e52b63 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 24 Jun 2015 21:54:56 +0200 Subject: [PATCH 13/14] set max_open_files for blocks and details db --- libethereum/BlockChain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 640fd2df4..964afa92e 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -149,6 +149,7 @@ void BlockChain::open(std::string const& _path, WithExisting _we) ldb::Options o; o.create_if_missing = true; + o.max_open_files = 256; ldb::DB::Open(o, path + "/blocks", &m_blocksDB); ldb::DB::Open(o, path + "/details", &m_extrasDB); if (!m_blocksDB || !m_extrasDB) From 8dfcf284a12b8cb76cafcbd982e67bb8a310b571 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 25 Jun 2015 13:26:41 +0200 Subject: [PATCH 14/14] fixed propogation to all peers --- libethereum/EthereumHost.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index afe12639a..4a13a247f 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -166,20 +166,20 @@ tuple>, vector>, vector vector> allowed; vector> sessions; - auto const& ps = peerSessions(); - allowed.reserve(ps.size()); - for (auto const& j: ps) + size_t peerCount = 0; + foreachPeer([&](std::shared_ptr _p) { - auto pp = j.first->cap(); - if (_allow(pp.get())) + if (_allow(_p.get())) { - allowed.push_back(move(pp)); - sessions.push_back(move(j.first)); + allowed.push_back(_p); + sessions.push_back(_p->session()); } - } + ++peerCount; + return true; + }); - chosen.reserve((ps.size() * _percent + 99) / 100); - for (unsigned i = (ps.size() * _percent + 99) / 100; i-- && allowed.size();) + chosen.reserve((peerCount * _percent + 99) / 100); + for (unsigned i = (peerCount * _percent + 99) / 100; i-- && allowed.size();) { unsigned n = rand() % allowed.size(); chosen.push_back(std::move(allowed[n]));