From d76a44f2268c872f424762ca59aa411572f333da Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 24 Oct 2014 14:21:20 +0200 Subject: [PATCH] ethrpc -> web3jsonrpc, other issues fixed --- CMakeLists.txt | 6 +++-- alethzero/CMakeLists.txt | 2 +- alethzero/MainWin.cpp | 2 +- eth/CMakeLists.txt | 4 +++- eth/main.cpp | 22 ++++++++++++++--- {libethrpc => libweb3jsonrpc}/CMakeLists.txt | 2 +- .../CorsHttpServer.cpp | 0 .../CorsHttpServer.h | 0 .../WebThreeStubServer.cpp | 0 .../WebThreeStubServer.h | 0 .../abstractwebthreestubserver.h | 0 {libethrpc => libweb3jsonrpc}/spec.json | 0 neth/CMakeLists.txt | 4 +++- neth/main.cpp | 24 ++++++++++++++++--- test/CMakeLists.txt | 4 +++- test/jsonrpc.cpp | 4 ++-- third/CMakeLists.txt | 3 +-- third/MainWin.cpp | 2 +- 18 files changed, 60 insertions(+), 19 deletions(-) rename {libethrpc => libweb3jsonrpc}/CMakeLists.txt (98%) rename {libethrpc => libweb3jsonrpc}/CorsHttpServer.cpp (100%) rename {libethrpc => libweb3jsonrpc}/CorsHttpServer.h (100%) rename {libethrpc => libweb3jsonrpc}/WebThreeStubServer.cpp (100%) rename {libethrpc => libweb3jsonrpc}/WebThreeStubServer.h (100%) rename {libethrpc => libweb3jsonrpc}/abstractwebthreestubserver.h (100%) rename {libethrpc => libweb3jsonrpc}/spec.json (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e3e56f5c..8ceb3e99a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,9 @@ endif() add_subdirectory(lllc) add_subdirectory(solc) add_subdirectory(sc) -add_subdirectory(libethrpc) +if (JSONRPC_LS OR (NOT HEADLESS)) + add_subdirectory(libweb3jsonrpc) +endif() if (NOT LANGUAGES) add_subdirectory(secp256k1) add_subdirectory(libp2p) @@ -148,7 +150,7 @@ if (NOT LANGUAGES) if ("${TARGET_PLATFORM}" STREQUAL "w64") cmake_policy(SET CMP0020 NEW) endif () - + add_subdirectory(libqethereum) add_subdirectory(alethzero) add_subdirectory(third) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index 6e75b1577..51111cb02 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -53,7 +53,7 @@ else () endif () qt5_use_modules(${EXECUTEABLE} Core)# Gui Widgets Network WebKit WebKitWidgets) -target_link_libraries(${EXECUTEABLE} webthree qethereum ethereum evm ethcore devcrypto secp256k1 gmp ${CRYPTOPP_LS} serpent lll evmface devcore ethrpc) +target_link_libraries(${EXECUTEABLE} webthree qethereum ethereum evm ethcore devcrypto secp256k1 gmp ${CRYPTOPP_LS} serpent lll evmface devcore web3jsonrpc) if (APPLE) # First have qt5 install plugins and frameworks diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 0d2234df9..588b0d7ef 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include "DownloadView.h" #include "MiningView.h" #include "BuildInfo.h" diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index 56f78d347..29cf2471c 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -19,7 +19,9 @@ if(MINIUPNPC_LS) endif() target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) -target_link_libraries(${EXECUTABLE} ethrpc) +if(JSONRPC_LS) +target_link_libraries(${EXECUTABLE} web3jsonrpc) +endif() if(READLINE_LS) target_link_libraries(${EXECUTABLE} ${READLINE_LS}) endif() diff --git a/eth/main.cpp b/eth/main.cpp index 215ac9539..cd2622ca8 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -27,9 +27,10 @@ #include #include #include -#include -#include -#include +#if ETH_JSONRPC +#include +#include +#endif #include #include #include @@ -39,6 +40,9 @@ #include #include #endif +#if ETH_JSONRPC +#include +#endif #include "BuildInfo.h" using namespace std; using namespace dev; @@ -104,8 +108,10 @@ void help() << " -f,--force-mining Mine even when there are no transaction to mine (Default: off)" << endl << " -h,--help Show this help message and exit." << endl << " -i,--interactive Enter interactive mode (default: non-interactive)." << endl +#if ETH_JSONRPC << " -j,--json-rpc Enable JSON-RPC server (default: off)." << endl << " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: 8080)." << endl +#endif << " -l,--listen Listen on the given port for incoming connected (default: 30303)." << endl << " -m,--mining Enable mining, optionally for a specified number of blocks (Default: off)" << endl << " -n,--upnp Use upnp for NAT (default: on)." << endl @@ -179,7 +185,9 @@ int main(int argc, char** argv) NodeMode mode = NodeMode::Full; unsigned peers = 5; bool interactive = false; +#if ETH_JSONRPC int jsonrpc = -1; +#endif string publicIP; bool bootstrap = false; bool upnp = true; @@ -264,10 +272,12 @@ int main(int argc, char** argv) forceMining = true; else if (arg == "-i" || arg == "--interactive") interactive = true; +#if ETH_JSONRPC else if ((arg == "-j" || arg == "--json-rpc")) jsonrpc = jsonrpc == -1 ? 8080 : jsonrpc; else if (arg == "--json-rpc-port" && i + 1 < argc) jsonrpc = atoi(argv[++i]); +#endif else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc) g_logVerbosity = atoi(argv[++i]); else if ((arg == "-x" || arg == "--peers") && i + 1 < argc) @@ -326,12 +336,14 @@ int main(int argc, char** argv) if (remoteHost.size()) web3.connect(remoteHost, remotePort); +#if ETH_JSONRPC auto_ptr jsonrpcServer; if (jsonrpc > -1) { jsonrpcServer = auto_ptr(new WebThreeStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3, {us})); jsonrpcServer->StartListening(); } +#endif signal(SIGABRT, &sighandler); signal(SIGTERM, &sighandler); @@ -404,6 +416,7 @@ int main(int argc, char** argv) iss >> g_logVerbosity; cout << "Verbosity: " << g_logVerbosity << endl; } +#if ETH_JSONRPC else if (cmd == "jsonport") { if (iss.peek() != -1) @@ -423,6 +436,7 @@ int main(int argc, char** argv) jsonrpcServer->StopListening(); jsonrpcServer.reset(); } +#endif else if (cmd == "address") { cout << "Current address:" << endl; @@ -755,8 +769,10 @@ int main(int argc, char** argv) else cout << "Unrecognised command. Type 'help' for help in interactive mode." << endl; } +#if ETH_JSONRPC if (jsonrpcServer.get()) jsonrpcServer->StopListening(); +#endif } else if (c) { diff --git a/libethrpc/CMakeLists.txt b/libweb3jsonrpc/CMakeLists.txt similarity index 98% rename from libethrpc/CMakeLists.txt rename to libweb3jsonrpc/CMakeLists.txt index 60c6c6d5e..b35ba7627 100644 --- a/libethrpc/CMakeLists.txt +++ b/libweb3jsonrpc/CMakeLists.txt @@ -6,7 +6,7 @@ include_directories(..) link_directories(../libethcore) link_directories(../libwebthree) -set(EXECUTABLE ethrpc) +set(EXECUTABLE web3jsonrpc) file(GLOB HEADERS "*.h") if(ETH_STATIC) diff --git a/libethrpc/CorsHttpServer.cpp b/libweb3jsonrpc/CorsHttpServer.cpp similarity index 100% rename from libethrpc/CorsHttpServer.cpp rename to libweb3jsonrpc/CorsHttpServer.cpp diff --git a/libethrpc/CorsHttpServer.h b/libweb3jsonrpc/CorsHttpServer.h similarity index 100% rename from libethrpc/CorsHttpServer.h rename to libweb3jsonrpc/CorsHttpServer.h diff --git a/libethrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp similarity index 100% rename from libethrpc/WebThreeStubServer.cpp rename to libweb3jsonrpc/WebThreeStubServer.cpp diff --git a/libethrpc/WebThreeStubServer.h b/libweb3jsonrpc/WebThreeStubServer.h similarity index 100% rename from libethrpc/WebThreeStubServer.h rename to libweb3jsonrpc/WebThreeStubServer.h diff --git a/libethrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h similarity index 100% rename from libethrpc/abstractwebthreestubserver.h rename to libweb3jsonrpc/abstractwebthreestubserver.h diff --git a/libethrpc/spec.json b/libweb3jsonrpc/spec.json similarity index 100% rename from libethrpc/spec.json rename to libweb3jsonrpc/spec.json diff --git a/neth/CMakeLists.txt b/neth/CMakeLists.txt index 12a56f0fc..a0f10a052 100644 --- a/neth/CMakeLists.txt +++ b/neth/CMakeLists.txt @@ -20,7 +20,9 @@ target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS}) endif() target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) -target_link_libraries(${EXECUTABLE} ethrpc) +if(JSONRPC_LS) +target_link_libraries(${EXECUTABLE} web3jsonrpc) +endif() if ("${TARGET_PLATFORM}" STREQUAL "w64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") diff --git a/neth/main.cpp b/neth/main.cpp index 969282ea0..430694156 100644 --- a/neth/main.cpp +++ b/neth/main.cpp @@ -26,13 +26,17 @@ #include #include #include +#if ETH_JSONRPC #include -#include -#include -#include +#endif #include #include #include +#if ETH_JSONRPC +#include +#include +#include +#endif #include #include "BuildInfo.h" @@ -69,8 +73,10 @@ void help() << " -d,--db-path Load database from path (default: ~/.ethereum " << endl << " /Etherum or Library/Application Support/Ethereum)." << endl << " -h,--help Show this help message and exit." << endl +#if ETH_JSONRPC << " -j,--json-rpc Enable JSON-RPC server (default: off)." << endl << " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: 8080)." << endl +#endif << " -l,--listen Listen on the given port for incoming connected (default: 30303)." << endl << " -m,--mining Enable mining (default: off)" << endl << " -n,--upnp Use upnp for NAT (default: on)." << endl @@ -91,8 +97,10 @@ void interactiveHelp() << "Commands:" << endl << " netstart Starts the network sybsystem on a specific port." << endl << " netstop Stops the network subsystem." << endl +#if ETH_JSONRPC << " jsonstart Starts the JSON-RPC server." << endl << " jsonstop Stops the JSON-RPC server." << endl +#endif << " connect Connects to a specific peer." << endl << " minestart Starts mining." << endl << " minestop Stops mining." << endl @@ -296,7 +304,9 @@ int main(int argc, char** argv) string dbPath; bool mining = false; unsigned peers = 5; +#if ETH_JSONRPC int jsonrpc = 8080; +#endif string publicIP; bool upnp = true; string clientName; @@ -367,10 +377,12 @@ int main(int argc, char** argv) cerr << "Unknown mining option: " << m << endl; } } +#if ETH_JSONRPC else if ((arg == "-j" || arg == "--json-rpc")) jsonrpc = jsonrpc ? jsonrpc : 8080; else if (arg == "--json-rpc-port" && i + 1 < argc) jsonrpc = atoi(argv[++i]); +#endif else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc) g_logVerbosity = atoi(argv[++i]); else if ((arg == "-x" || arg == "--peers") && i + 1 < argc) @@ -462,12 +474,14 @@ int main(int argc, char** argv) if (mining) c.startMining(); +#if ETH_JSONRPC auto_ptr jsonrpcServer; if (jsonrpc > -1) { jsonrpcServer = auto_ptr(new WebThreeStubServer(new jsonrpc::HttpServer(jsonrpc), web3, {us})); jsonrpcServer->StartListening(); } +#endif while (true) { @@ -526,6 +540,7 @@ int main(int argc, char** argv) { c.stopMining(); } +#if ETH_JSONRPC else if (cmd == "jsonport") { if (iss.peek() != -1) @@ -545,6 +560,7 @@ int main(int argc, char** argv) jsonrpcServer->StopListening(); jsonrpcServer.reset(); } +#endif else if (cmd == "address") { ccout << "Current address:" << endl; @@ -986,8 +1002,10 @@ int main(int argc, char** argv) endwin(); refresh(); +#if ETH_JSONRPC if (jsonrpcServer.get()) jsonrpcServer->StopListening(); +#endif return 0; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9d5e66911..624c64fae 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,9 @@ target_link_libraries(testeth gmp) target_link_libraries(testeth solidity) target_link_libraries(testeth ${CRYPTOPP_LS}) target_link_libraries(testeth webthree) -target_link_libraries(testeth ethrpc) +if(JSONRPC_LS) +target_link_libraries(testeth web3jsonrpc) +endif() target_link_libraries(createRandomTest ethereum) target_link_libraries(createRandomTest ethcore) diff --git a/test/jsonrpc.cpp b/test/jsonrpc.cpp index ff2e3a5b4..10b890c50 100644 --- a/test/jsonrpc.cpp +++ b/test/jsonrpc.cpp @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/third/CMakeLists.txt b/third/CMakeLists.txt index f92d19c1f..f999c3b09 100644 --- a/third/CMakeLists.txt +++ b/third/CMakeLists.txt @@ -53,8 +53,7 @@ else () endif () qt5_use_modules(${EXECUTEABLE} Core)# Gui Widgets Network WebKit WebKitWidgets) -target_link_libraries(${EXECUTEABLE} webthree qethereum ethereum evm ethcore secp256k1 gmp ${CRYPTOPP_LS} serpent lll evmface devcore) -target_link_libraries(${EXECUTEABLE} ethrpc) +target_link_libraries(${EXECUTEABLE} webthree qethereum ethereum evm ethcore secp256k1 gmp ${CRYPTOPP_LS} serpent lll evmface devcore web3jsonrpc) if (APPLE) # First have qt5 install plugins and frameworks diff --git a/third/MainWin.cpp b/third/MainWin.cpp index 82f057883..200ee6971 100644 --- a/third/MainWin.cpp +++ b/third/MainWin.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include "BuildInfo.h" #include "MainWin.h" #include "ui_Main.h"