diff --git a/CMakeLists.txt b/CMakeLists.txt index 4adac7060..7e3b6a53c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -394,6 +394,7 @@ endif () if (JSCONSOLE) add_subdirectory(libjsengine) add_subdirectory(libjsconsole) + add_subdirectory(ethconsole) endif () add_subdirectory(secp256k1) diff --git a/eth/main.cpp b/eth/main.cpp index c5a15e5fd..ea69afdf6 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 @@ -1742,12 +1742,24 @@ int main(int argc, char** argv) if (useConsole) { #if ETH_JSCONSOLE - JSConsole console(web3, make_shared([&](){return web3.ethereum();}, getAccountPassword, keyManager)); + JSLocalConsole console; + + jsonrpcServer = shared_ptr(new dev::WebThreeStubServer(*jsonrpcConnector.get(), web3, make_shared([&](){ return web3.ethereum(); }, getAccountPassword, keyManager), vector(), keyManager, *gasPricer)); + jsonrpcServer->setMiningBenefactorChanger([&](Address const& a) { beneficiary = a; }); + jsonrpcServer->StartListening(); + if (jsonAdmin.empty()) + jsonAdmin = jsonrpcServer->newSession(SessionPermissions{{Priviledge::Admin}}); + else + jsonrpcServer->addSession(jsonAdmin, SessionPermissions{{Priviledge::Admin}}); + cout << "JSONRPC Admin Session Key: " << jsonAdmin << endl; + while (!g_exit) { console.readExpression(); stopMiningAfterXBlocks(c, n, mining); } + + jsonrpcServer->StopListening(); #endif } else 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..102bbcb40 --- /dev/null +++ b/ethconsole/main.cpp @@ -0,0 +1,27 @@ + +#include +#include + +using namespace std; +using namespace dev; +using namespace dev::eth; + +int main(int argc, char** argv) +{ + string remote; + if (argc != 2) + { + cout << "remote url not provided\n"; + cout << "using default:\n"; + cout << "./ethconsole http://localhost:8545\n"; + remote = "http://localhost:8545\n"; + } + else + remote = argv[1]; + + JSRemoteConsole console(remote); + while (true) + console.readExpression(); + + return 0; +} \ No newline at end of file diff --git a/ethkey/KeyAux.h b/ethkey/KeyAux.h index 11de30e39..ae8eaed92 100644 --- a/ethkey/KeyAux.h +++ b/ethkey/KeyAux.h @@ -198,7 +198,16 @@ public: if (m_masterPassword.empty()) cerr << "Aborted (empty password not allowed)." << endl; else - wallet.create(m_masterPassword); + { + try + { + wallet.create(m_masterPassword); + } + catch (Exception const& _e) + { + cerr << "unable to create wallet" << endl << boost::diagnostic_information(_e); + } + } } else if (m_mode < OperationMode::CreateWallet) { diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index facf1479e..57360e95a 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -104,10 +104,10 @@ bytes asNibbles(bytesConstRef const& _s); template inline void toBigEndian(_T _val, _Out& o_out) { - for (auto i = o_out.size(); i-- != 0; _val >>= 8) + for (auto i = o_out.size(); i != 0; _val >>= 8, i--) { _T v = _val & (_T)0xff; - o_out[i] = (typename _Out::value_type)(uint8_t)v; + o_out[i - 1] = (typename _Out::value_type)(uint8_t)v; } } diff --git a/libethcore/KeyManager.h b/libethcore/KeyManager.h index 0e54f3f42..a2b5a4e07 100644 --- a/libethcore/KeyManager.h +++ b/libethcore/KeyManager.h @@ -46,7 +46,7 @@ struct KeyInfo static h256 const UnknownPassword; /// Password query function that never returns a password. -static auto const DontKnowThrow = [](){ BOOST_THROW_EXCEPTION(PasswordUnknown()); return std::string(); }; +static auto const DontKnowThrow = [](){ throw PasswordUnknown(); return std::string(); }; enum class SemanticPassword { diff --git a/libjsconsole/CMakeLists.txt b/libjsconsole/CMakeLists.txt index e8f98de88..761435fe1 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) @@ -24,7 +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 new file mode 100644 index 000000000..c07059372 --- /dev/null +++ b/libjsconsole/CURLRequest.cpp @@ -0,0 +1,66 @@ +/* + 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" + +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..e025d1eb9 --- /dev/null +++ b/libjsconsole/CURLRequest.h @@ -0,0 +1,58 @@ +/* + 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 + +#pragma once + +#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/JSConsole.cpp b/libjsconsole/JSConsole.cpp index 29d547242..61376de79 100644 --- a/libjsconsole/JSConsole.cpp +++ b/libjsconsole/JSConsole.cpp @@ -20,65 +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)); - (void)_web3; (void)_accounts; -// m_jsonrpcServer.reset(new WebThreeStubServer(*m_jsonrpcConnector.get(), _web3, _accounts, vector())); -} - -void JSConsole::readExpression() 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 2e5144a5d..50f6d6ae5 100644 --- a/libjsconsole/JSConsole.h +++ b/libjsconsole/JSConsole.h @@ -22,32 +22,66 @@ #pragma once -#include -#include - -namespace dev { 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); - void readExpression() const; + JSConsole(): m_engine(Engine()), m_printer(Printer(m_engine)) {} + ~JSConsole() {} + + void readExpression() 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..04c6104a6 --- /dev/null +++ b/libjsconsole/JSLocalConsole.cpp @@ -0,0 +1,34 @@ +/* + 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 "JSLocalConsole.h" +#include "JSV8Connector.h" + +using namespace std; +using namespace dev; +using namespace dev::eth; + +JSLocalConsole::JSLocalConsole() +{ + m_jsonrpcConnector.reset(new JSV8Connector(m_engine)); +} diff --git a/libjsconsole/JSLocalConsole.h b/libjsconsole/JSLocalConsole.h new file mode 100644 index 000000000..48922faee --- /dev/null +++ b/libjsconsole/JSLocalConsole.h @@ -0,0 +1,50 @@ +/* + 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 JSLocalConsole: public JSConsole +{ +public: + JSLocalConsole(); + virtual ~JSLocalConsole() {} + + jsonrpc::AbstractServerConnector* connector() { return m_jsonrpcConnector.get(); } + +private: + std::unique_ptr m_jsonrpcConnector; +}; + +} +} diff --git a/libjsconsole/JSRemoteConsole.cpp b/libjsconsole/JSRemoteConsole.cpp new file mode 100644 index 000000000..b42c5b340 --- /dev/null +++ b/libjsconsole/JSRemoteConsole.cpp @@ -0,0 +1,23 @@ +/* + 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.cpp + * @author Marek Kotewicz + * @date 2015 + * Ethereum client. + */ + +#include "JSRemoteConsole.h" diff --git a/libjsconsole/JSRemoteConsole.h b/libjsconsole/JSRemoteConsole.h new file mode 100644 index 000000000..2baf516f6 --- /dev/null +++ b/libjsconsole/JSRemoteConsole.h @@ -0,0 +1,48 @@ +/* + 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 + +#include +#include +#include "JSV8RemoteConnector.h" +#include "JSConsole.h" + +namespace dev +{ +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/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..72e64faae --- /dev/null +++ b/libjsconsole/JSV8RemoteConnector.cpp @@ -0,0 +1,20 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +#include "JSV8RemoteConnector.h" + +using namespace std; +using namespace dev; +using namespace dev::eth; + +void JSV8RemoteConnector::onSend(char const* _payload) +{ + m_request.setUrl(m_url); + m_request.setBody(_payload); + long code; + string response; + tie(code, response) = m_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..5d28094ad --- /dev/null +++ b/libjsconsole/JSV8RemoteConnector.h @@ -0,0 +1,32 @@ +// +// Created by Marek Kotewicz on 15/06/15. +// + +#pragma once + +#include +#include +#include "CURLRequest.h" + +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; + CURLRequest m_request; +}; + +} +} 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 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(); diff --git a/libweb3jsonrpc/CMakeLists.txt b/libweb3jsonrpc/CMakeLists.txt index a28d51a06..c65efd39b 100644 --- a/libweb3jsonrpc/CMakeLists.txt +++ b/libweb3jsonrpc/CMakeLists.txt @@ -54,4 +54,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") - diff --git a/test/TestHelper.h b/test/TestHelper.h index 73b560aa0..1c1dfb5f0 100644 --- a/test/TestHelper.h +++ b/test/TestHelper.h @@ -224,7 +224,7 @@ public: bool bigData = false; bool wallet = false; bool nonetwork = false; - bool nodag = false; + bool nodag = true; /// @} /// Get reference to options diff --git a/test/libethcore/keymanager.cpp b/test/libethcore/keymanager.cpp new file mode 100644 index 000000000..69f4743b1 --- /dev/null +++ b/test/libethcore/keymanager.cpp @@ -0,0 +1,101 @@ +/* + 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 keymanager.cpp + * @author Christoph Jentzsch + * @date 2015 + * Keymanager test functions. + */ + + +#include +#include +#include +#include + +using namespace std; +using namespace dev; +using namespace dev::eth; + +BOOST_AUTO_TEST_SUITE(KeyManagerTests) + +BOOST_AUTO_TEST_CASE(KeyInfoDefaultConstructor) +{ + cnote << "KeyInfoDefaultConstructor"; + KeyInfo kiDefault; + BOOST_CHECK_EQUAL(kiDefault.accountName, ""); + BOOST_CHECK(kiDefault.passHash == h256()); +} + +BOOST_AUTO_TEST_CASE(KeyInfoConstructor) +{ + cnote << "KeyInfoConstructor"; + h256 passHash("0x2a"); + string accountName = "myAccount"; + KeyInfo ki(passHash, accountName); + BOOST_CHECK_EQUAL(ki.accountName, "myAccount"); + BOOST_CHECK(ki.passHash == h256("0x2a")); +} + +BOOST_AUTO_TEST_CASE(KeyManagerConstructor) +{ + cnote << "KeyManagerConstructor"; + KeyManager km; + BOOST_CHECK_EQUAL(km.keysFile(), km.defaultPath()); + BOOST_CHECK_EQUAL(km.defaultPath(), getDataDir("ethereum") + "/keys.info"); + BOOST_CHECK(km.store().keys() == SecretStore().keys()); +} + +BOOST_AUTO_TEST_CASE(KeyManagerKeysFile) +{ + cnote << "KeyManagerKeysFile"; + KeyManager km; + string password = "hardPassword"; + BOOST_CHECK(!km.load(password)); + + // set to valid path + TransientDirectory tmpDir; + km.setKeysFile(tmpDir.path()); + BOOST_CHECK(!km.exists()); + BOOST_CHECK_THROW(km.create(password), FileError); + km.setKeysFile(tmpDir.path() + "/notExistingDir/keysFile.json"); + BOOST_CHECK_THROW(km.create(password), FileError); + BOOST_CHECK(!km.exists()); + km.setKeysFile(tmpDir.path() + "keysFile.json"); + BOOST_CHECK_NO_THROW(km.create(password)); + + km.save(password); + BOOST_CHECK(km.load(password)); +} + +BOOST_AUTO_TEST_CASE(KeyManagerHints) +{ + cnote << "KeyManagerHints"; + KeyManager km; + string password = "hardPassword"; + + // set to valid path + TransientDirectory tmpDir; + km.setKeysFile(tmpDir.path() + "keysFile.json"); + km.create(password); + km.save(password); + + BOOST_CHECK(!km.haveHint(password + "2")); + km.notePassword(password); + BOOST_CHECK(km.haveHint(password)); +} + +BOOST_AUTO_TEST_SUITE_END()