From d7721df21b08ff403b980d69a4bf3d6a64319e20 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Mon, 25 Sep 2017 23:01:24 +0300 Subject: [PATCH 01/14] Tryed to add boost::program_options library --- CMakeLists.txt | 4 ++-- eth/main.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10998a38bb8..15940e56897 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,8 +93,8 @@ include(EthExecutableHelper) include(EthDependencies) include(EthUtils) -hunter_add_package(Boost COMPONENTS filesystem system thread) -find_package(Boost CONFIG REQUIRED filesystem system thread) +hunter_add_package(Boost COMPONENTS program_options filesystem system thread) +find_package(Boost CONFIG REQUIRED program_options filesystem system thread) hunter_add_package(jsoncpp) find_package(jsoncpp CONFIG REQUIRED) diff --git a/eth/main.cpp b/eth/main.cpp index 682036fb101..36e5dc357f2 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -30,7 +30,7 @@ #include #include #include - +#include #include #include #include @@ -70,6 +70,7 @@ using namespace dev; using namespace dev::p2p; using namespace dev::eth; using namespace boost::algorithm; + namespace fs = boost::filesystem; static std::atomic g_silence = {false}; @@ -305,7 +306,7 @@ int main(int argc, char** argv) #else g_logVerbosity = 1; #endif - + boost::program_options::option_description desc; /// Operating mode. OperationMode mode = OperationMode::Node; // unsigned prime = 0; From e5917bd12ec16f3ca4aca0180815aed47efc6e26 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Wed, 27 Sep 2017 09:21:16 +0300 Subject: [PATCH 02/14] Adding a boost::program_options library --- eth/CMakeLists.txt | 10 +++++++--- eth/main.cpp | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index d6676c4227d..3f850f5c5ed 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -6,9 +6,13 @@ set( ) add_executable(eth ${sources}) -target_link_libraries( - eth - PRIVATE ethereum ethashseal evm web3jsonrpc webthree devcore + + + +target_link_libraries ( + eth + PRIVATE ethereum ethashseal evm web3jsonrpc webthree devcore Boost::program_options + ) install(TARGETS eth DESTINATION bin) diff --git a/eth/main.cpp b/eth/main.cpp index 36e5dc357f2..92576efd884 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -31,6 +31,8 @@ #include #include #include +#include + #include #include #include From a4cfdecd3cbf5309b44728a6b01a0540824a0e0e Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Sat, 30 Sep 2017 20:37:31 +0300 Subject: [PATCH 03/14] Adding client mode(default) options --- eth/main.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/eth/main.cpp b/eth/main.cpp index 92576efd884..c3ecbdaec97 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -72,7 +72,7 @@ using namespace dev; using namespace dev::p2p; using namespace dev::eth; using namespace boost::algorithm; - +namespace po = boost::program_options; namespace fs = boost::filesystem; static std::atomic g_silence = {false}; @@ -409,6 +409,31 @@ int main(int argc, char** argv) bool chainConfigIsSet = false; string configJSON; string genesisJSON; + po::options_description client_default_mode("Client mode (default)"); + client_default_mode.add_options() + ("mainnet", "Use the main network protocol.") + ("ropsten", "Use the Ropsten testnet.") + ("private", po::value(), " Use a private chain.") + ("test", "Testing mode: Disable PoW and provide test rpc interface.") + ("config", po::value(), " Configure specialised blockchain using given JSON information.") +//("oppose-dao-fork", "Ignore DAO hard fork (default is to participate).") + ("mode,o", po::value(), " Start a full node or a peer node (default: full).\n") + ("json-rpc,j", "Enable JSON-RPC server (default: off).") + ("ipc", "Enable IPC server (default: on).") + ("ipcpath", po::value(), "Set .ipc socket path (default: data directory)") + ("admin-via-http", "Expose admin interface via http - UNSAFE! (default: off).") + ("no-ipc", "Disable IPC server.") + //TODO << " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ").\n" + ("rpccorsdomain", po::value(), " Domain on which to send Access-Control-Allow-Origin header.") + ("admin", po::value(), " Specify admin session key for JSON-RPC (default: auto-generated and printed at start-up).") + ("kill,K", "Kill the blockchain first.") + ("rebuild,R", "Rebuild the blockchain from the existing database.") + ("rescue", "Attempt to rescue a corrupt database.\n") + ("import-presale", po::value(), " Import a pre-sale key; you'll need to specify the password to this key.") + ("import-secret,s", po::value(), " Import a secret key into the key store.") + ("master", po::value(), " Give the master password for the key store. Use --master \"\" to show a prompt.") + ("password", po::value(), " Give a password for a private key.\n") + ; for (int i = 1; i < argc; ++i) { string arg = argv[i]; From f20ff93ee946a01b8665e661809eb842ee427d26 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Sat, 30 Sep 2017 21:12:01 +0300 Subject: [PATCH 04/14] Adding client transacting options and client mining options --- eth/main.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index c3ecbdaec97..9c9e7a6cff0 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -409,14 +409,14 @@ int main(int argc, char** argv) bool chainConfigIsSet = false; string configJSON; string genesisJSON; - po::options_description client_default_mode("Client mode (default)"); - client_default_mode.add_options() + po::options_description clientDefaultMode("Client mode (default)"); + clientDefaultMode.add_options() ("mainnet", "Use the main network protocol.") ("ropsten", "Use the Ropsten testnet.") ("private", po::value(), " Use a private chain.") ("test", "Testing mode: Disable PoW and provide test rpc interface.") ("config", po::value(), " Configure specialised blockchain using given JSON information.") -//("oppose-dao-fork", "Ignore DAO hard fork (default is to participate).") + ("oppose-dao-fork", "Ignore DAO hard fork (default is to participate).") ("mode,o", po::value(), " Start a full node or a peer node (default: full).\n") ("json-rpc,j", "Enable JSON-RPC server (default: off).") ("ipc", "Enable IPC server (default: on).") @@ -427,6 +427,7 @@ int main(int argc, char** argv) ("rpccorsdomain", po::value(), " Domain on which to send Access-Control-Allow-Origin header.") ("admin", po::value(), " Specify admin session key for JSON-RPC (default: auto-generated and printed at start-up).") ("kill,K", "Kill the blockchain first.") + ("kill-blockchain", "Kill the blockchain first.") ("rebuild,R", "Rebuild the blockchain from the existing database.") ("rescue", "Attempt to rescue a corrupt database.\n") ("import-presale", po::value(), " Import a pre-sale key; you'll need to specify the password to this key.") @@ -434,6 +435,21 @@ int main(int argc, char** argv) ("master", po::value(), " Give the master password for the key store. Use --master \"\" to show a prompt.") ("password", po::value(), " Give a password for a private key.\n") ; + po::options_description clientTransacting("Client transactions"); + clientTransacting.add_options() + //TODO << " --ask Set the minimum ask gas price under which no transaction will be mined (default " << toString(DefaultGasPrice) << " ).\n; + //TODO << " --bid Set the bid gas price to pay for transactions (default " << toString(DefaultGasPrice) << " ).\n" + ("unsafe-transactions", "Allow all transactions to proceed without verification. EXTREMELY UNSAFE.") + ; + po::options_description clientMining("Client mining"); + clientMining.add_options() + ("address,a", po::value(), " Set the author (mining payout) address to given address (default: auto).") + ("author", po::value(), " Set the author (mining payout) address to given address (default: auto).") + ("mining,m", po::value(), " Enable mining, optionally for a specified number of blocks (default: off).") + ("force-mining,f", "Mine even when there are no transactions to mine (default: off).") + ("cpu,C", "When mining, use the CPU.") + ("mining-threads,t", " Limit number of CPU/GPU miners to n (default: use everything available on selected platform).") + ; for (int i = 1; i < argc; ++i) { string arg = argv[i]; From 5f2385174b693da2055cbe06f79dd6c861089dde Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Sat, 30 Sep 2017 21:21:23 +0300 Subject: [PATCH 05/14] fixing todo --- eth/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 9c9e7a6cff0..fe0cc1468d0 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -437,8 +437,8 @@ int main(int argc, char** argv) ; po::options_description clientTransacting("Client transactions"); clientTransacting.add_options() - //TODO << " --ask Set the minimum ask gas price under which no transaction will be mined (default " << toString(DefaultGasPrice) << " ).\n; - //TODO << " --bid Set the bid gas price to pay for transactions (default " << toString(DefaultGasPrice) << " ).\n" + //TODO << "--ask Set the minimum ask gas price under which no transaction will be mined (default " << toString(DefaultGasPrice) << " ).\n; + //TODO << "--bid Set the bid gas price to pay for transactions (default " << toString(DefaultGasPrice) << " ).\n" ("unsafe-transactions", "Allow all transactions to proceed without verification. EXTREMELY UNSAFE.") ; po::options_description clientMining("Client mining"); From 0febf63bcf63a3984f462b9f5380a5c11a811429 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Sun, 1 Oct 2017 22:35:25 +0300 Subject: [PATCH 06/14] adding clientNetworking options --- eth/main.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/eth/main.cpp b/eth/main.cpp index fe0cc1468d0..a727c5e781d 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -450,6 +450,30 @@ int main(int argc, char** argv) ("cpu,C", "When mining, use the CPU.") ("mining-threads,t", " Limit number of CPU/GPU miners to n (default: use everything available on selected platform).") ; + po::options_description clientNetworking("Client networking"); + clientNetworking.add_options() + ("client-name", po::value(), " Add a name to your client's version string (default: blank).") + ("bootstrap,b", "Connect to the default Ethereum peer servers (default unless --no-discovery used).") + ("no-bootstrap", "Do not connect to the default Ethereum peer servers (default only when --no-discovery is used).") + ("peers,x", po::value(), " Attempt to connect to a given number of peers (default: 11).") + ("peer-stretch", po::value(), " Give the accepted connection multiplier (default: 7).") + ("public-ip", po::value(), " Force advertised public IP to the given IP (default: auto).") + ("public", po::value(), " Force advertised public IP to the given IP (default: auto).") + ("listen-ip", po::value(), "(:) Listen on the given IP for incoming connections (default: 0.0.0.0).") + ("listen", po::value(), " Listen on the given port for incoming connections (default: 30303).") + ("listen-port", po::value(), " Listen on the given port for incoming connections (default: 30303).") + ("remote,r", po::value(), "(:) Connect to the given remote host (default: none).") + ("port", po::value(), " Connect to the given remote port (default: 30303).") + ("network-id", po::value(), " Only connect to other hosts with this network id.") + ("upnp", po::value(), " Use UPnP for NAT (default: on).") + ("peerset", po::value(), " Space delimited list of peers; element format: type:publickey@ipAddress[:port].\n Types:\n default Attempt connection when no other peers are available and pinning is disabled.\n required Keep connected at all times.\n") + // TODO: + // << " --trust-peers Space delimited list of publickeys." << endl + ("no-discovery", "Disable node discovery, implies --no-bootstrap.") + ("pin", "Only accept or connect to trusted peers.") + ("hermit", "Equivalent to --no-discovery --pin.") + ("sociable", "Force discovery and no pinning.\n") + ; for (int i = 1; i < argc; ++i) { string arg = argv[i]; From eb4f786cb4bdb68753c4c8ab26f7bf0bdb49eb85 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Wed, 4 Oct 2017 10:20:34 +0300 Subject: [PATCH 07/14] Rewriting command string arguments in ethvm and eth --- CMakeLists.txt | 2 ++ eth/main.cpp | 35 +++++++++++++++++++++++++++++++---- ethvm/main.cpp | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15940e56897..a640355ad40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,3 +149,5 @@ endif() # TODO: Split out json_spirit, libscrypt and sec256k1. add_subdirectory(utils) + +add_executable(main ethvm/main.cpp) diff --git a/eth/main.cpp b/eth/main.cpp index a727c5e781d..3cf985d69b8 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -153,7 +153,7 @@ void help() << " --only Equivalent to --export-from n --export-to n.\n" << " --dont-check Prevent checking some block aspects. Faster importing, but to apply only when the data is known to be valid.\n\n" << " --import-snapshot Import blockchain and state data from the Parity Warp Sync snapshot." << endl - << "General Options:\n" + << "General Options:\n" << " -d,--db-path,--datadir Load database from path (default: " << getDataDir() << ").\n" #if ETH_EVMJIT << " --vm Select VM; options are: interpreter, jit or smart (default: interpreter).\n" @@ -413,10 +413,10 @@ int main(int argc, char** argv) clientDefaultMode.add_options() ("mainnet", "Use the main network protocol.") ("ropsten", "Use the Ropsten testnet.") - ("private", po::value(), " Use a private chain.") + ("private", po::value(), " Use a private chain.") ("test", "Testing mode: Disable PoW and provide test rpc interface.") ("config", po::value(), " Configure specialised blockchain using given JSON information.") - ("oppose-dao-fork", "Ignore DAO hard fork (default is to participate).") + ("oppose-dao-fork", "Ignore DAO hard fork (default is to participate).\n") ("mode,o", po::value(), " Start a full node or a peer node (default: full).\n") ("json-rpc,j", "Enable JSON-RPC server (default: off).") ("ipc", "Enable IPC server (default: on).") @@ -466,7 +466,7 @@ int main(int argc, char** argv) ("port", po::value(), " Connect to the given remote port (default: 30303).") ("network-id", po::value(), " Only connect to other hosts with this network id.") ("upnp", po::value(), " Use UPnP for NAT (default: on).") - ("peerset", po::value(), " Space delimited list of peers; element format: type:publickey@ipAddress[:port].\n Types:\n default Attempt connection when no other peers are available and pinning is disabled.\n required Keep connected at all times.\n") + ("peerset", po::value(), " Space delimited list of peers; element format: type:publickey@ipAddress[:port].\n Types:\n default Attempt connection when no other peers are available and pinning is disabled.\n required Keep connected at all times.\n") // TODO: // << " --trust-peers Space delimited list of publickeys." << endl ("no-discovery", "Disable node discovery, implies --no-bootstrap.") @@ -474,6 +474,33 @@ int main(int argc, char** argv) ("hermit", "Equivalent to --no-discovery --pin.") ("sociable", "Force discovery and no pinning.\n") ; + po::options_description importExportMode("Import/export mode"); + importExportMode.add_options() + ("from", po::value(), " Export only from block n; n may be a decimal, a '0x' prefixed hash, or 'latest'.") + ("to", po::value(), " Export only to block n (inclusive); n may be a decimal, a '0x' prefixed hash, or 'latest'.") + ("only", po::value(), " Equivalent to --export-from n --export-to n.") + ("dont-check", "Prevent checking some block aspects. Faster importing, but to apply only when the data is known to be valid.\n") + ("import-snapshot", po::value(), " Import blockchain and state data from the Parity Warp Sync snapshot.") + ; + po::options_description generalOptions("General Options"); + generalOptions.add_options() + //TODO " -d,--db-path,--datadir Load database from path (default: " << getDataDir() << ").\n" + //TODO #if ETH_EVMJIT + //TODO << " --vm Select VM; options are: interpreter, jit or smart (default: interpreter).\n" + //TODO #endif // ETH_EVMJIT + ("verbosity,v", po::value(), "<0 - 9> Set the log verbosity from 0 to 9 (default: 8).") + ("version,V", "Show the version and exit.") + ("help,h", "Show this help message and exit.\n") + ; + po::options_description experimentalProofOfConcept("Experimental / Proof of Concept"); + experimentalProofOfConcept.add_options() + ("shh", "Enable Whisper.\n") + ; + po::options_description allowedOptions("Allowed options"); + allowedOptions.add(clientDefaultMode).add(clientTransacting).add(clientMining).add(clientNetworking).add(importExportMode).add(generalOptions); + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, allowedOptions), vm); + po::notify(vm); for (int i = 1; i < argc; ++i) { string arg = argv[i]; diff --git a/ethvm/main.cpp b/ethvm/main.cpp index f401e4cc7e4..2a033ebd489 100755 --- a/ethvm/main.cpp +++ b/ethvm/main.cpp @@ -32,13 +32,14 @@ #include #include #include +#include #include #include #include using namespace std; using namespace dev; using namespace eth; - +namespace po = boost::program_options; namespace { int64_t maxBlockGasLimit() @@ -149,7 +150,39 @@ int main(int argc, char** argv) Ethash::init(); NoProof::init(); - + po::options_description transactionOptions("Transaction options"); + transactionOptions.add_options() + ("value", po::value(), " Transaction should transfer the wei (default: 0).") + ("gas", po::value(), " Transaction should be given gas (default: block gas limit).") + //TODO ("gas-limit", " Block gas limit (default: " << maxBlockGasLimit() << ").") + ("gas-price", po::value(), " Transaction's gas price' should be (default: 0).") + ("sender", po::value(), " Transaction sender should be (default: 0000...0069).") + ("origin", po::value(), " Transaction origin should be (default: 0000...0069).") + ("input", po::value(), " Transaction code should be ") + ("code", po::value(), " Contract code . Makes transaction a call to this contract") + ; + po::options_description vmOptions("VM options"); + #if ETH_EVMJIT + vmOptions.add_options() + ("vm", " Select VM. Options are: interpreter, jit, smart. (default: interpreter)") + ; + #endif // ETH_EVMJIT + po::options_description networkOptions("Network options"); + networkOptions.add_options() + ("network", po::value(), "Main|Ropsten|Homestead|Frontier|Byzantium|Constantinople\n"); + ; + po::options_description optionsForTrace("Options for trace"); + optionsForTrace.add_options() + ("flat", "Minimal whitespace in the JSON.") + ("mnemonics", "Show instruction mnemonics in the trace (non-standard).\n") + ; + po::options_description generalOptions("General options"); + generalOptions.add_options() + ("version,v", "Show the version and exit.") + ("help,h", "Show this help message and exit.") + ; + po::options_description allowedOptions("Usage ethvm [trace|stats|output|test] (|-)"); + allowedOptions.add(transactionOptions).add(vmOptions).add(networkOptions).add(optionsForTrace).add(generalOptions); for (int i = 1; i < argc; ++i) { string arg = argv[i]; From eb1cd288d562580f463e08f063a44b232d35a7a6 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Thu, 5 Oct 2017 20:23:58 +0300 Subject: [PATCH 08/14] Finish of rewriting ethvm --- ethvm/CMakeLists.txt | 2 +- ethvm/main.cpp | 186 ++++++++++++++++++++----------------------- 2 files changed, 88 insertions(+), 100 deletions(-) diff --git a/ethvm/CMakeLists.txt b/ethvm/CMakeLists.txt index f1c5518538f..7405636ee3d 100644 --- a/ethvm/CMakeLists.txt +++ b/ethvm/CMakeLists.txt @@ -1,5 +1,5 @@ add_executable(ethvm main.cpp) -target_link_libraries(ethvm PRIVATE ethereum evm ethashseal devcore) +target_link_libraries(ethvm PRIVATE ethereum evm ethashseal devcore Boost::program_options) install(TARGETS ethvm DESTINATION bin OPTIONAL) diff --git a/ethvm/main.cpp b/ethvm/main.cpp index 2a033ebd489..7cfab75a2d9 100755 --- a/ethvm/main.cpp +++ b/ethvm/main.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -48,34 +49,6 @@ int64_t maxBlockGasLimit() return limit; } -void help() -{ - cout - << "Usage ethvm [trace|stats|output|test] (|-)\n" - << "Transaction options:\n" - << " --value Transaction should transfer the wei (default: 0).\n" - << " --gas Transaction should be given gas (default: block gas limit).\n" - << " --gas-limit Block gas limit (default: " << maxBlockGasLimit() << ").\n" - << " --gas-price Transaction's gas price' should be (default: 0).\n" - << " --sender Transaction sender should be (default: 0000...0069).\n" - << " --origin Transaction origin should be (default: 0000...0069).\n" - << " --input Transaction code should be \n" - << " --code Contract code . Makes transaction a call to this contract\n" -#if ETH_EVMJIT - << "\nVM options:\n" - << " --vm Select VM. Options are: interpreter, jit, smart. (default: interpreter)\n" -#endif // ETH_EVMJIT - << "Network options:\n" - << " --network Main|Ropsten|Homestead|Frontier|Byzantium|Constantinople\n\n" - << "Options for trace:\n" - << " --flat Minimal whitespace in the JSON.\n" - << " --mnemonics Show instruction mnemonics in the trace (non-standard).\n\n" - << "General options:\n" - << " -V,--version Show the version and exit.\n" - << " -h,--help Show this help message and exit.\n"; - exit(0); -} - void version() { cout << "ethvm version " << dev::Version << "\n"; @@ -154,19 +127,19 @@ int main(int argc, char** argv) transactionOptions.add_options() ("value", po::value(), " Transaction should transfer the wei (default: 0).") ("gas", po::value(), " Transaction should be given gas (default: block gas limit).") - //TODO ("gas-limit", " Block gas limit (default: " << maxBlockGasLimit() << ").") ("gas-price", po::value(), " Transaction's gas price' should be (default: 0).") ("sender", po::value(), " Transaction sender should be (default: 0000...0069).") ("origin", po::value(), " Transaction origin should be (default: 0000...0069).") ("input", po::value(), " Transaction code should be ") ("code", po::value(), " Contract code . Makes transaction a call to this contract") + ("gas-limit", po::value(), "") ; po::options_description vmOptions("VM options"); - #if ETH_EVMJIT - vmOptions.add_options() - ("vm", " Select VM. Options are: interpreter, jit, smart. (default: interpreter)") - ; - #endif // ETH_EVMJIT + //#if ETH_EVMJIT + vmOptions.add_options() + ("vm", " Select VM. Options are: interpreter, jit, smart. (default: interpreter)") + ; + //#endif // ETH_EVMJIT po::options_description networkOptions("Network options"); networkOptions.add_options() ("network", po::value(), "Main|Ropsten|Homestead|Frontier|Byzantium|Constantinople\n"); @@ -180,78 +153,97 @@ int main(int argc, char** argv) generalOptions.add_options() ("version,v", "Show the version and exit.") ("help,h", "Show this help message and exit.") + ("author", po::value(), " Set author") + ("difficulty", po::value(), " Set difficulty") + ("number", po::value(), " Set number") + ("timestamp", po::value(), " Set timestamp") ; po::options_description allowedOptions("Usage ethvm [trace|stats|output|test] (|-)"); - allowedOptions.add(transactionOptions).add(vmOptions).add(networkOptions).add(optionsForTrace).add(generalOptions); - for (int i = 1; i < argc; ++i) - { - string arg = argv[i]; - if (arg == "-h" || arg == "--help") - help(); - else if (arg == "-V" || arg == "--version") - version(); - else if (arg == "--vm" && i + 1 < argc) - { - string vmKindStr = argv[++i]; - if (vmKindStr == "interpreter") - vmKind = VMKind::Interpreter; + allowedOptions.add(vmOptions).add(networkOptions).add(optionsForTrace).add(generalOptions).add(transactionOptions); + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, allowedOptions), vm); + po::notify(vm); + if (vm.count("help")) { + cout << allowedOptions; + cout << " Block gas limit (default: " << maxBlockGasLimit() << ")."; + exit(0); + } + if (vm.count("version")) { + version(); + } + if (vm.count("vm")) { + string vmKindStr = vm["vm"].as(); + if (vmKindStr == "interpreter") + vmKind = VMKind::Interpreter; #if ETH_EVMJIT else if (vmKindStr == "jit") vmKind = VMKind::JIT; else if (vmKindStr == "smart") vmKind = VMKind::Smart; #endif - else - { - cerr << "Unknown/unsupported VM kind: " << vmKindStr << "\n"; - return -1; - } + else + { + cerr << "Unknown/unsupported VM kind: " << vmKindStr << "\n"; + return -1; } - else if (arg == "--mnemonics") - st.setShowMnemonics(); - else if (arg == "--flat") - styledJson = false; - else if (arg == "--sender" && i + 1 < argc) - sender = Address(argv[++i]); - else if (arg == "--origin" && i + 1 < argc) - origin = Address(argv[++i]); - else if (arg == "--gas" && i + 1 < argc) - gas = u256(argv[++i]); - else if (arg == "--gas-price" && i + 1 < argc) - gasPrice = u256(argv[++i]); - else if (arg == "--author" && i + 1 < argc) - blockHeader.setAuthor(Address(argv[++i])); - else if (arg == "--number" && i + 1 < argc) - blockHeader.setNumber(u256(argv[++i])); - else if (arg == "--difficulty" && i + 1 < argc) - blockHeader.setDifficulty(u256(argv[++i])); - else if (arg == "--timestamp" && i + 1 < argc) - blockHeader.setTimestamp(u256(argv[++i])); - else if (arg == "--gas-limit" && i + 1 < argc) - blockHeader.setGasLimit(u256(argv[++i]).convert_to()); - else if (arg == "--value" && i + 1 < argc) - value = u256(argv[++i]); - else if (arg == "--network" && i + 1 < argc) + } + if (vm.count("mnemonics")) + st.setShowMnemonics(); + if (vm.count("flat")) + styledJson = false; + if (vm.count("sender")) + sender = Address(vm["sender"].as()); + if (vm.count("origin")) + origin = Address(vm["origin"].as()); + if (vm.count("gas")) + gas = u256(vm["gas"].as()); + if (vm.count("gas-price")) + gasPrice = u256(vm["gas-price"].as()); + if (vm.count("author")) + blockHeader.setAuthor(Address(vm["author"].as())); + if (vm.count("number")) + blockHeader.setNumber(u256(vm["number"].as())); + if (vm.count("difficulty")) + blockHeader.setDifficulty(u256(vm["difficulty"].as())); + if (vm.count("timestamp")) + blockHeader.setTimestamp(u256(vm["timestamp"].as())); + if (vm.count("gas-limit")) + blockHeader.setGasLimit(u256(vm["gas-limit"].as()).convert_to()); + if (vm.count("value")) + value = u256(vm["value"].as()); + if (vm.count("network")) + { + string network = vm["network"].as(); + if (network == "Constantinople") + networkName = Network::ConstantinopleTest; + else if (network == "Byzantium") + networkName = Network::ByzantiumTest; + else if (network == "Frontier") + networkName = Network::FrontierTest; + else if (network == "Ropsten") + networkName = Network::Ropsten; + else if (network == "Homestead") + networkName = Network::HomesteadTest; + else if (network == "Main") + networkName = Network::MainNetwork; + else { - string network = argv[++i]; - if (network == "Constantinople") - networkName = Network::ConstantinopleTest; - else if (network == "Byzantium") - networkName = Network::ByzantiumTest; - else if (network == "Frontier") - networkName = Network::FrontierTest; - else if (network == "Ropsten") - networkName = Network::Ropsten; - else if (network == "Homestead") - networkName = Network::HomesteadTest; - else if (network == "Main") - networkName = Network::MainNetwork; - else - { - cerr << "Unknown network type: " << network << "\n"; - return -1; - } + cerr << "Unknown network type: " << network << "\n"; + return -1; } + } + if (vm.count("input")) + data = fromHex(vm["input"].as()); + if (vm.count("code")) + code = fromHex(vm["code"].as()); + for (int i = 1; i < argc; ++i) + { + string arg = argv[i]; + if ((i + 1 < argc && (arg == "--vm" || arg == "--sender" || + arg == "--origin" || arg == "--gas" || arg == "--gas-price" || arg == "--author" || arg == "--number" || + arg == "--difficulty" || arg == "--timestamp" || arg == "--gas-limit" || arg == "--value" || arg == "--network"|| + arg == "--input" || arg == "--code")) || arg == "--mnemonics" || arg == "--flat") + continue; else if (arg == "stats") mode = Mode::Statistics; else if (arg == "output") @@ -260,10 +252,6 @@ int main(int argc, char** argv) mode = Mode::Trace; else if (arg == "test") mode = Mode::Test; - else if (arg == "--input" && i + 1 < argc) - data = fromHex(argv[++i]); - else if (arg == "--code" && i + 1 < argc) - code = fromHex(argv[++i]); else if (inputFile.empty()) inputFile = arg; // Assign input file name only once. else From 7ce58ad209fc55b8ff55db9e69e2aaa239eb66f7 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Thu, 5 Oct 2017 21:32:34 +0300 Subject: [PATCH 09/14] Fixing ethvm/main.cpp and ethkey/main.cpp --- ethkey/CMakeLists.txt | 2 +- ethkey/main.cpp | 43 ++++++++++++++++++++++----- ethvm/main.cpp | 67 +++++++++++++++++++++++++++---------------- 3 files changed, 79 insertions(+), 33 deletions(-) diff --git a/ethkey/CMakeLists.txt b/ethkey/CMakeLists.txt index 43629dd2a7a..c65a7ed8fab 100644 --- a/ethkey/CMakeLists.txt +++ b/ethkey/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(ethkey KeyAux.h main.cpp) -target_link_libraries(ethkey PRIVATE ethcore devcore) +target_link_libraries(ethkey PRIVATE ethcore devcore Boost::program_options) diff --git a/ethkey/main.cpp b/ethkey/main.cpp index e6353e30424..99071f53e3f 100644 --- a/ethkey/main.cpp +++ b/ethkey/main.cpp @@ -26,12 +26,16 @@ #include #include #include +#include +#include #include "BuildInfo.h" #include "KeyAux.h" using namespace std; using namespace dev; using namespace dev::eth; +namespace po = boost::program_options; + void help() { cout @@ -82,23 +86,48 @@ int main(int argc, char** argv) setDefaultOrCLocale(); KeyCLI m(KeyCLI::OperationMode::ListBare); g_logVerbosity = 0; - + po::options_description generalOptions("General Options"); + generalOptions.add_options() + ("verbosity,v", po::value(), "<0 - 9> Set the log verbosity from 0 to 9 (default: 8).") + ("version,V", "Show the version and exit.") + ("help,h", "Show this help message and exit.") + ; + int ac = 1; for (int i = 1; i < argc; ++i) { string arg = argv[i]; if (m.interpretOption(i, argc, argv)) {} - else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc) - g_logVerbosity = atoi(argv[++i]); - else if (arg == "-h" || arg == "--help") - help(); - else if (arg == "-V" || arg == "--version") - version(); + else if (((arg == "-v" || arg == "--verbosity") && i + 1 < argc) || arg == "-h" || arg == "--help" || arg == "-V" || arg == "--version") { + argv[ac] = argv[i]; + ac++; + if (arg == "-v" || arg == "--verbosity") { + i++; + argv[ac] = argv[i]; + ac++; + } + continue; + } else { cerr << "Invalid argument: " << arg << endl; exit(-1); } } + po::variables_map vm; + po::store(po::parse_command_line(ac, argv, generalOptions), vm); + po::notify(vm); + if (vm.count("help")) { + cout + << "Usage ethkey [OPTIONS]" << endl + << "Options:" << endl << endl; + KeyCLI::streamHelp(cout); + cout << generalOptions; + exit(0); + } + if (vm.count("version")) + version(); + if (vm.count("verbosity")) + g_logVerbosity = atoi(vm["verbosity"].as().c_str()); m.execute(); diff --git a/ethvm/main.cpp b/ethvm/main.cpp index 7cfab75a2d9..743c7fe521e 100755 --- a/ethvm/main.cpp +++ b/ethvm/main.cpp @@ -161,7 +161,47 @@ int main(int argc, char** argv) po::options_description allowedOptions("Usage ethvm [trace|stats|output|test] (|-)"); allowedOptions.add(vmOptions).add(networkOptions).add(optionsForTrace).add(generalOptions).add(transactionOptions); po::variables_map vm; - po::store(po::parse_command_line(argc, argv, allowedOptions), vm); + int ac = 1; + for (int i = 1; i < argc; ++i) { + string arg = argv[i]; + if ((i + 1 < argc && (arg == "--vm" || arg == "--sender" || + arg == "--origin" || arg == "--gas" || arg == "--gas-price" || arg == "--author" || + arg == "--number" || + arg == "--difficulty" || arg == "--timestamp" || arg == "--gas-limit" || + arg == "--value" || arg == "--network" || + arg == "--input" || arg == "--code")) || arg == "--mnemonics" || arg == "--flat" || + arg == "-h" || arg == "--help" || arg == "--version" || arg == "-V") { + argv[ac] = argv[i]; + ac++; + if (arg == "--vm" || arg == "--sender" || + arg == "--origin" || arg == "--gas" || arg == "--gas-price" || arg == "--author" || + arg == "--number" || + arg == "--difficulty" || arg == "--timestamp" || arg == "--gas-limit" || + arg == "--value" || arg == "--network" || + arg == "--input" || arg == "--code") { + i++; + argv[ac] = argv[i]; + ac++; + } + continue; + } + else if (arg == "stats") + mode = Mode::Statistics; + else if (arg == "output") + mode = Mode::OutputOnly; + else if (arg == "trace") + mode = Mode::Trace; + else if (arg == "test") + mode = Mode::Test; + else if (inputFile.empty()) + inputFile = arg; // Assign input file name only once. + else + { + cerr << "Unknown argument: " << arg << '\n'; + return -1; + } + } + po::store(po::parse_command_line(ac, argv, allowedOptions), vm); po::notify(vm); if (vm.count("help")) { cout << allowedOptions; @@ -236,30 +276,7 @@ int main(int argc, char** argv) data = fromHex(vm["input"].as()); if (vm.count("code")) code = fromHex(vm["code"].as()); - for (int i = 1; i < argc; ++i) - { - string arg = argv[i]; - if ((i + 1 < argc && (arg == "--vm" || arg == "--sender" || - arg == "--origin" || arg == "--gas" || arg == "--gas-price" || arg == "--author" || arg == "--number" || - arg == "--difficulty" || arg == "--timestamp" || arg == "--gas-limit" || arg == "--value" || arg == "--network"|| - arg == "--input" || arg == "--code")) || arg == "--mnemonics" || arg == "--flat") - continue; - else if (arg == "stats") - mode = Mode::Statistics; - else if (arg == "output") - mode = Mode::OutputOnly; - else if (arg == "trace") - mode = Mode::Trace; - else if (arg == "test") - mode = Mode::Test; - else if (inputFile.empty()) - inputFile = arg; // Assign input file name only once. - else - { - cerr << "Unknown argument: " << arg << '\n'; - return -1; - } - } + VMFactory::setKind(vmKind); From af0d89af1bc0631cf34e3aa050c0c12a6cda4b2e Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Tue, 10 Oct 2017 11:20:08 +0300 Subject: [PATCH 10/14] Fixing eth/main.cpp and rip.cpp and peer.cpp --- CMakeLists.txt | 4 +- eth/AccountManager.cpp | 2 + eth/main.cpp | 6 +- rlp/CMakeLists.txt | 2 +- rlp/main.cpp | 185 ++++++++++++++++++++------------- test/CMakeLists.txt | 2 +- test/unittests/libp2p/peer.cpp | 43 ++++++-- 7 files changed, 158 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a640355ad40..265cfce36f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,4 +150,6 @@ endif() # TODO: Split out json_spirit, libscrypt and sec256k1. add_subdirectory(utils) -add_executable(main ethvm/main.cpp) +add_executable(main rlp/main.cpp) + +add_executable(peer test/unittests/libp2p/peer.cpp) \ No newline at end of file diff --git a/eth/AccountManager.cpp b/eth/AccountManager.cpp index 6360972fb2a..e3fb0c63b35 100644 --- a/eth/AccountManager.cpp +++ b/eth/AccountManager.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "AccountManager.h" using namespace std; using namespace dev; diff --git a/eth/main.cpp b/eth/main.cpp index 3cf985d69b8..94b96b7508e 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -498,9 +498,6 @@ int main(int argc, char** argv) ; po::options_description allowedOptions("Allowed options"); allowedOptions.add(clientDefaultMode).add(clientTransacting).add(clientMining).add(clientNetworking).add(importExportMode).add(generalOptions); - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, allowedOptions), vm); - po::notify(vm); for (int i = 1; i < argc; ++i) { string arg = argv[i]; @@ -897,6 +894,9 @@ int main(int argc, char** argv) exit(-1); } } + //po::variables_map vm; + //po::store(po::parse_command_line(argc, argv, allowedOptions), vm); + //po::notify(vm); if (!configJSON.empty()) { diff --git a/rlp/CMakeLists.txt b/rlp/CMakeLists.txt index 184f77ff834..0a26589f159 100644 --- a/rlp/CMakeLists.txt +++ b/rlp/CMakeLists.txt @@ -1,3 +1,3 @@ add_executable(rlp main.cpp) target_include_directories(rlp PRIVATE ../utils) -target_link_libraries(rlp PRIVATE devcrypto devcore) +target_link_libraries(rlp PRIVATE devcrypto devcore Boost::program_options) diff --git a/rlp/main.cpp b/rlp/main.cpp index 68499f9fefc..4d6ed45f35f 100644 --- a/rlp/main.cpp +++ b/rlp/main.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -34,39 +36,7 @@ using namespace std; using namespace dev; namespace js = json_spirit; - -void help() -{ - cout - << "Usage rlp [OPTIONS]" << endl - << "Modes:" << endl - << " create Given a simplified JSON string, output the RLP." << endl - << " render [ | -- ] Render the given RLP. Options:" << endl - << " --indent Use string as the level indentation (default ' ')." << endl - << " --hex-ints Render integers in hex." << endl - << " --string-ints Render integers in the same way as strings." << endl - << " --ascii-strings Render data as C-style strings or hex depending on content being ASCII." << endl - << " --force-string Force all data to be rendered as C-style strings." << endl - << " --force-escape When rendering as C-style strings, force all characters to be escaped." << endl - << " --force-hex Force all data to be rendered as raw hex." << endl - << " list [ | -- ] List the items in the RLP list by hash and size." << endl - << " extract [ | -- ] Extract all items in the RLP list, named by hash." << endl - << " assemble [ | ] ... Given a manifest & files, output the RLP." << endl - << " -D,--dapp Dapp-building mode; equivalent to --encrypt --64." << endl - << endl - << "General options:" << endl - << " -e,--encrypt Encrypt the RLP data prior to output." << endl - << " -L,--lenience Try not to bomb out early if possible." << endl - << " -x,--hex,--base-16 Treat input RLP as hex encoded data." << endl - << " -k,--keccak Output Keccak-256 hash only." << endl - << " --64,--base-64 Treat input RLP as base-64 encoded data." << endl - << " -b,--bin,--base-256 Treat input RLP as raw binary data." << endl - << " -q,--quiet Don't place additional information on stderr." << endl - << " -h,--help Print this help message and exit." << endl - << " -V,--version Show the version and exit." << endl - ; - exit(0); -} +namespace po = boost::program_options; void version() { @@ -215,61 +185,136 @@ int main(int argc, char** argv) bool quiet = false; bool encrypt = false; RLPStreamer::Prefs prefs; - + po::options_description modesOptions("Modes"); + modesOptions.add_options() + ("indent,i", po::value (), " Use string as the level indentation (default ' ').") + ("hex-ints", "Render integers in hex.") + ("string-ints", "Render integers in the same way as strings.") + ("ascii-strings", "Render data as C-style strings or hex depending on content being ASCII.") + ("force-string", "Force all data to be rendered as C-style strings.") + ("force-escape", "When rendering as C-style strings, force all characters to be escaped.") + ("force-hex", "Force all data to be rendered as raw hex.") + ("dapp,D", "Dapp-building mode; equivalent to --encrypt --64.") + ; + po::options_description generalOptions("General options"); + generalOptions.add_options() + ("encrypt,e", "Encrypt the RLP data prior to output.") + ("lenience,L", "Try not to bomb out early if possible.") + ("hex,x", "Treat input RLP as hex encoded data.") + ("base-16", "Treat input RLP as hex encoded data.") + ("keccak,k", "Output Keccak-256 hash only.") + ("base-64", "Treat input RLP as base-64 encoded data.") + ("64", "Treat input RLP as base-64 encoded data.") + ("bin,b", "Treat input RLP as raw binary data.") + ("base-256", "Treat input RLP as raw binary data.") + ("quiet,q", "Don't place additional information on stderr.") + ("help,h", "Print this help message and exit.") + ("version,V", "Show the version and exit.") + ; + po::options_description allowedOptions("Allowed options"); + allowedOptions.add(generalOptions).add(modesOptions); + int ac = 1; for (int i = 1; i < argc; ++i) { + string arg = argv[i]; - if (arg == "-h" || arg == "--help") - help(); + if ((arg == "-i" || arg == "--indent") && i + 1 < argc) { + argv[ac] = argv[i]; + ac++; + i++; + argv[ac] = argv[i]; + ac++; + continue; + } + else if (arg == "-h" || arg == "--help" || arg == "--hex-ints" || arg == "--ascii-strings" || arg == "-L" || arg == "--lenience" || + arg == "--force-string" || arg == "--force-hex" || arg == "--force-escape" || arg == "-n" || arg == "--nice" || + arg == "-D" || arg == "--dapp" || arg == "-V" || arg == "--version" || arg == "-q" || arg == "--quiet" || arg == "-x" || + arg == "--hex" || arg == "--base-16" || arg == "-k" || arg == "--keccak" || arg == "--64" || arg == "--base-64" || + arg == "-b" || arg == "--bin" || arg == "--base-256" || arg == "-e" || arg == "--encrypt") { + argv[ac] = argv[i]; + ac++; + continue; + } else if (arg == "render") mode = Mode::Render; else if (arg == "create") mode = Mode::Create; - else if ((arg == "-i" || arg == "--indent") && i + 1 < argc) - prefs.indent = argv[++i]; - else if (arg == "--hex-ints") - prefs.hexInts = true; - else if (arg == "--string-ints") - prefs.stringInts = true; - else if (arg == "--ascii-strings") - prefs.forceString = prefs.forceHex = false; - else if (arg == "--force-string") - prefs.forceString = true; - else if (arg == "--force-hex") - prefs.forceHex = true, prefs.forceString = false; - else if (arg == "--force-escape") - prefs.escapeAll = true; - else if (arg == "-n" || arg == "--nice") - prefs.forceString = true, prefs.stringInts = false, prefs.forceHex = false, prefs.indent = " "; else if (arg == "list") mode = Mode::ListArchive; else if (arg == "extract") mode = Mode::ExtractArchive; else if (arg == "assemble") mode = Mode::AssembleArchive; - else if (arg == "-L" || arg == "--lenience") - lenience = true; - else if (arg == "-D" || arg == "--dapp") - encrypt = true, encoding = Encoding::Base64; - else if (arg == "-V" || arg == "--version") - version(); - else if (arg == "-q" || arg == "--quiet") - quiet = true; - else if (arg == "-x" || arg == "--hex" || arg == "--base-16") - encoding = Encoding::Hex; - else if (arg == "-k" || arg == "--keccak") - encoding = Encoding::Keccak; - else if (arg == "--64" || arg == "--base-64") - encoding = Encoding::Base64; - else if (arg == "-b" || arg == "--bin" || arg == "--base-256") - encoding = Encoding::Binary; - else if (arg == "-e" || arg == "--encrypt") - encrypt = true; else if (inputFile.empty()) inputFile = arg; else otherInputs.push_back(arg); } + po::variables_map vm; + po::store(po::parse_command_line(ac, argv, allowedOptions), vm); + po::notify(vm); + if (vm.count("help")) { + cout << "Usage rlp [OPTIONS]" << endl << modesOptions + << " create Given a simplified JSON string, output the RLP." << endl + << " render [ | -- ] Render the given RLP. Options:" << endl + << " list [ | -- ] List the items in the RLP list by hash and size." << endl + << " extract [ | -- ] Extract all items in the RLP list, named by hash." << endl + << " assemble [ | ] ... Given a manifest & files, output the RLP." << endl + << generalOptions; + exit(0); + } + if (vm.count("lenience")) + lenience = true; + if (vm.count("dapp")) + encrypt = true, encoding = Encoding::Base64; + if (vm.count("version")) + version(); + if (vm.count("quiet")) + quiet = true; + if (vm.count("hex") || vm.count("base-16")) + encoding = Encoding::Hex; + if (vm.count("keccak")) + encoding = Encoding::Keccak; + if (vm.count("64") || vm.count("base-64")) + encoding = Encoding::Base64; + if (vm.count("bin") || vm.count("base-256")) + encoding = Encoding::Binary; + if (vm.count("encrypt")) + encrypt = true; + if (vm.count("indent")) + prefs.indent = vm["indent"].as(); + if (vm.count("hex-ints")) + prefs.hexInts = true; + if (vm.count("string-ints")) + prefs.stringInts = true; + if (vm.count("ascii-strings")) + prefs.forceString = prefs.forceHex = false; + if (vm.count("force-string")) + prefs.forceString = true; + if (vm.count("force-hex")) + prefs.forceHex = true, prefs.forceString = false; + if (vm.count("force-escape")) + prefs.escapeAll = true; + if (vm.count("nice")) + prefs.forceString = true, prefs.stringInts = false, prefs.forceHex = false, prefs.indent = " "; + if (vm.count("lenience")) + lenience = true; + if (vm.count("dapp")) + encrypt = true, encoding = Encoding::Base64; + if (vm.count("version")) + version(); + if (vm.count("quiet")) + quiet = true; + if (vm.count("hex") || vm.count("base-16")) + encoding = Encoding::Hex; + if (vm.count("keccak")) + encoding = Encoding::Keccak; + if (vm.count("64") || vm.count("base-64")) + encoding = Encoding::Base64; + if (vm.count("bin") || vm.count("base-256")) + encoding = Encoding::Binary; + if (vm.count("encrypt")) + encrypt = true; bytes in; if (inputFile == "--") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9d4005e1cc4..9b070976ce4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -48,7 +48,7 @@ endforeach(file) add_executable(testeth ${sources}) target_include_directories(testeth PRIVATE ../utils) -target_link_libraries(testeth PRIVATE ethereum ethashseal web3jsonrpc devcrypto devcore Cryptopp) +target_link_libraries(testeth PRIVATE ethereum ethashseal web3jsonrpc devcrypto devcore Cryptopp Boost::program_options) enable_testing() set(CTEST_OUTPUT_ON_FAILURE TRUE) diff --git a/test/unittests/libp2p/peer.cpp b/test/unittests/libp2p/peer.cpp index 64c092eabe3..e7a545609ca 100644 --- a/test/unittests/libp2p/peer.cpp +++ b/test/unittests/libp2p/peer.cpp @@ -28,11 +28,14 @@ #include #include #include +#include +#include using namespace std; using namespace dev; using namespace dev::test; using namespace dev::p2p; +namespace po = boost::program_options; struct P2PPeerFixture: public TestOutputHelper { @@ -328,22 +331,42 @@ int peerTest(int argc, char** argv) short listenPort = 30304; string remoteHost; short remotePort = 30304; - + po::options_description generalOptions("General options"); + generalOptions.add_options() + ("listenPort,l", po::value(), " set number of listenPort") + ("remoteHost,r", po::value(), " set string to remoteHost") + ("remotePort,p", po::value(), " set number to remotePort") + ("remoteAlias,ra", po::value(), " set remoteAlias"); + ; + int ac = 1; for (int i = 1; i < argc; ++i) { string arg = argv[i]; - if (arg == "-l" && i + 1 < argc) - listenPort = (short)atoi(argv[++i]); - else if (arg == "-r" && i + 1 < argc) - remoteHost = argv[++i]; - else if (arg == "-p" && i + 1 < argc) - remotePort = (short)atoi(argv[++i]); - else if (arg == "-ra" && i + 1 < argc) - remoteAlias = Public(dev::fromHex(argv[++i])); + if ((arg == "-l" || arg == "-r" || arg == "-p" || arg == "-ra") && i + 1 < argc) { + argv[ac] = argv[i]; + ac++; + i++; + argv[ac] = argv[i]; + ac++; + } else remoteHost = argv[i]; } - + po::variables_map vm; + po::store(po::parse_command_line(ac, argv, generalOptions), vm); + po::notify(vm); + if (vm.count("listenPort")) { + listenPort = vm["listenPort"].as(); + } + if (vm.count("remoteHost")) { + remoteHost = vm["remoteHost"].as(); + } + if (vm.count("remotePort")) { + remotePort = vm["remotePort"].as(); + } + if (vm.count("remoteAlias")) { + remoteAlias = Public(dev::fromHex(vm["remoteAlias"].as())); + } Host ph("Test", NetworkPreferences(listenPort)); if (!remoteHost.empty() && !remoteAlias) From 691d0e604e7525bd8fb42635a82a0632b79cf084 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Thu, 12 Oct 2017 20:48:41 +0300 Subject: [PATCH 11/14] Fixing eth/main.cpp --- eth/main.cpp | 873 ++++++++++++++++++++++++++------------------------- 1 file changed, 445 insertions(+), 428 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 94b96b7508e..2f6a02c06ab 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -77,95 +77,6 @@ namespace fs = boost::filesystem; static std::atomic g_silence = {false}; -void help() -{ - cout - << "Usage eth [OPTIONS]\n" - << "Options:\n\n" - << "Wallet usage:\n"; - AccountManager::streamAccountHelp(cout); - AccountManager::streamWalletHelp(cout); - cout - << "\nClient mode (default):\n" - << " --mainnet Use the main network protocol.\n" - << " --ropsten Use the Ropsten testnet.\n" - << " --private Use a private chain.\n" - << " --test Testing mode: Disable PoW and provide test rpc interface.\n" - << " --config Configure specialised blockchain using given JSON information.\n" - << " --oppose-dao-fork Ignore DAO hard fork (default is to participate).\n\n" - << " -o,--mode Start a full node or a peer node (default: full).\n\n" - << " -j,--json-rpc Enable JSON-RPC server (default: off).\n" - << " --ipc Enable IPC server (default: on).\n" - << " --ipcpath Set .ipc socket path (default: data directory)\n" - << " --admin-via-http Expose admin interface via http - UNSAFE! (default: off).\n" - << " --no-ipc Disable IPC server.\n" - << " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ").\n" - << " --rpccorsdomain Domain on which to send Access-Control-Allow-Origin header.\n" - << " --admin Specify admin session key for JSON-RPC (default: auto-generated and printed at start-up).\n" - << " -K,--kill Kill the blockchain first.\n" - << " -R,--rebuild Rebuild the blockchain from the existing database.\n" - << " --rescue Attempt to rescue a corrupt database.\n\n" - << " --import-presale Import a pre-sale key; you'll need to specify the password to this key.\n" - << " -s,--import-secret Import a secret key into the key store.\n" - << " --master Give the master password for the key store. Use --master \"\" to show a prompt.\n" - << " --password Give a password for a private key.\n\n" - << "Client transacting:\n" - << " --ask Set the minimum ask gas price under which no transaction will be mined (default " << toString(DefaultGasPrice) << " ).\n" - << " --bid Set the bid gas price to pay for transactions (default " << toString(DefaultGasPrice) << " ).\n" - << " --unsafe-transactions Allow all transactions to proceed without verification. EXTREMELY UNSAFE.\n" - << "Client mining:\n" - << " -a,--address Set the author (mining payout) address to given address (default: auto).\n" - << " -m,--mining Enable mining, optionally for a specified number of blocks (default: off).\n" - << " -f,--force-mining Mine even when there are no transactions to mine (default: off).\n" - << " -C,--cpu When mining, use the CPU.\n" - << " -t, --mining-threads Limit number of CPU/GPU miners to n (default: use everything available on selected platform).\n\n" - << "Client networking:\n" - << " --client-name Add a name to your client's version string (default: blank).\n" - << " --bootstrap Connect to the default Ethereum peer servers (default unless --no-discovery used).\n" - << " --no-bootstrap Do not connect to the default Ethereum peer servers (default only when --no-discovery is used).\n" - << " -x,--peers Attempt to connect to a given number of peers (default: 11).\n" - << " --peer-stretch Give the accepted connection multiplier (default: 7).\n" - - << " --public-ip Force advertised public IP to the given IP (default: auto).\n" - << " --listen-ip (:) Listen on the given IP for incoming connections (default: 0.0.0.0).\n" - << " --listen Listen on the given port for incoming connections (default: 30303).\n" - << " -r,--remote (:) Connect to the given remote host (default: none).\n" - << " --port Connect to the given remote port (default: 30303).\n" - << " --network-id Only connect to other hosts with this network id.\n" - << " --upnp Use UPnP for NAT (default: on).\n" - - << " --peerset Space delimited list of peers; element format: type:publickey@ipAddress[:port].\n" - << " Types:\n" - << " default Attempt connection when no other peers are available and pinning is disabled.\n" - << " required Keep connected at all times.\n" -// TODO: -// << " --trust-peers Space delimited list of publickeys." << endl - - << " --no-discovery Disable node discovery, implies --no-bootstrap.\n" - << " --pin Only accept or connect to trusted peers.\n" - << " --hermit Equivalent to --no-discovery --pin.\n" - << " --sociable Force discovery and no pinning.\n\n"; - MinerCLI::streamHelp(cout); - cout - << "Import/export modes:\n" - << " --from Export only from block n; n may be a decimal, a '0x' prefixed hash, or 'latest'.\n" - << " --to Export only to block n (inclusive); n may be a decimal, a '0x' prefixed hash, or 'latest'.\n" - << " --only Equivalent to --export-from n --export-to n.\n" - << " --dont-check Prevent checking some block aspects. Faster importing, but to apply only when the data is known to be valid.\n\n" - << " --import-snapshot Import blockchain and state data from the Parity Warp Sync snapshot." << endl - << "General Options:\n" - << " -d,--db-path,--datadir Load database from path (default: " << getDataDir() << ").\n" -#if ETH_EVMJIT - << " --vm Select VM; options are: interpreter, jit or smart (default: interpreter).\n" -#endif // ETH_EVMJIT - << " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (default: 8).\n" - << " -V,--version Show the version and exit.\n" - << " -h,--help Show this help message and exit.\n\n" - << "Experimental / Proof of Concept:\n" - << " --shh Enable Whisper.\n\n"; - exit(0); -} - string ethCredits(bool _interactive = false) { std::ostringstream cout; @@ -411,8 +322,12 @@ int main(int argc, char** argv) string genesisJSON; po::options_description clientDefaultMode("Client mode (default)"); clientDefaultMode.add_options() + ("format", po::value(), " Set format.") + ("script", po::value(), "