diff options
author | stoffu <stoffu@protonmail.ch> | 2018-02-16 20:04:04 +0900 |
---|---|---|
committer | stoffu <stoffu@protonmail.ch> | 2018-03-05 11:55:05 +0900 |
commit | af773211cbc620a1be54f517bd60e587d58a7e93 (patch) | |
tree | 40e747cbfc21c7182db27291fb29f9b033de2379 /src/daemon | |
parent | command_line: allow args to depend on more than one args (diff) | |
download | monero-af773211cbc620a1be54f517bd60e587d58a7e93.tar.xz |
Stagenet
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/command_line_args.h | 32 | ||||
-rw-r--r-- | src/daemon/command_parser_executor.cpp | 50 | ||||
-rw-r--r-- | src/daemon/core.h | 7 | ||||
-rw-r--r-- | src/daemon/daemon.cpp | 5 | ||||
-rw-r--r-- | src/daemon/main.cpp | 8 | ||||
-rw-r--r-- | src/daemon/rpc.h | 4 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 6 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.h | 2 |
8 files changed, 74 insertions, 40 deletions
diff --git a/src/daemon/command_line_args.h b/src/daemon/command_line_args.h index efbae488c..add752029 100644 --- a/src/daemon/command_line_args.h +++ b/src/daemon/command_line_args.h @@ -37,27 +37,33 @@ namespace daemon_args { std::string const WINDOWS_SERVICE_NAME = "Monero Daemon"; - const command_line::arg_descriptor<std::string, false, true> arg_config_file = { + const command_line::arg_descriptor<std::string, false, true, 2> arg_config_file = { "config-file" , "Specify configuration file" , (daemonizer::get_default_data_dir() / std::string(CRYPTONOTE_NAME ".conf")).string() - , cryptonote::arg_testnet_on - , [](bool testnet, bool defaulted, std::string val) { - if (testnet && defaulted) + , {{ &cryptonote::arg_testnet_on, &cryptonote::arg_stagenet_on }} + , [](std::array<bool, 2> testnet_stagenet, bool defaulted, std::string val) { + if (testnet_stagenet[0] && defaulted) return (daemonizer::get_default_data_dir() / "testnet" / std::string(CRYPTONOTE_NAME ".conf")).string(); + else if (testnet_stagenet[1] && defaulted) + return (daemonizer::get_default_data_dir() / "stagenet" / + std::string(CRYPTONOTE_NAME ".conf")).string(); return val; } }; - const command_line::arg_descriptor<std::string, false, true> arg_log_file = { + const command_line::arg_descriptor<std::string, false, true, 2> arg_log_file = { "log-file" , "Specify log file" , (daemonizer::get_default_data_dir() / std::string(CRYPTONOTE_NAME ".log")).string() - , cryptonote::arg_testnet_on - , [](bool testnet, bool defaulted, std::string val) { - if (testnet && defaulted) + , {{ &cryptonote::arg_testnet_on, &cryptonote::arg_stagenet_on }} + , [](std::array<bool, 2> testnet_stagenet, bool defaulted, std::string val) { + if (testnet_stagenet[0] && defaulted) return (daemonizer::get_default_data_dir() / "testnet" / std::string(CRYPTONOTE_NAME ".log")).string(); + else if (testnet_stagenet[1] && defaulted) + return (daemonizer::get_default_data_dir() / "stagenet" / + std::string(CRYPTONOTE_NAME ".log")).string(); return val; } }; @@ -91,14 +97,16 @@ namespace daemon_args , "127.0.0.1" }; - const command_line::arg_descriptor<std::string, false, true> arg_zmq_rpc_bind_port = { + const command_line::arg_descriptor<std::string, false, true, 2> arg_zmq_rpc_bind_port = { "zmq-rpc-bind-port" , "Port for ZMQ RPC server to listen on" , std::to_string(config::ZMQ_RPC_DEFAULT_PORT) - , cryptonote::arg_testnet_on - , [](bool testnet, bool defaulted, std::string val) { - if (testnet && defaulted) + , {{ &cryptonote::arg_testnet_on, &cryptonote::arg_stagenet_on }} + , [](std::array<bool, 2> testnet_stagenet, bool defaulted, std::string val) { + if (testnet_stagenet[0] && defaulted) return std::to_string(config::testnet::ZMQ_RPC_DEFAULT_PORT); + if (testnet_stagenet[1] && defaulted) + return std::to_string(config::stagenet::ZMQ_RPC_DEFAULT_PORT); return val; } }; diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 09e425dd1..7a89ebc0c 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -268,30 +268,44 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg } cryptonote::address_parse_info info; - bool testnet = false; - if(!cryptonote::get_account_address_from_str(info, false, args.front())) + cryptonote::network_type nettype = cryptonote::MAINNET; + if(!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, args.front())) { - if(!cryptonote::get_account_address_from_str(info, true, args.front())) + if(!cryptonote::get_account_address_from_str(info, cryptonote::TESTNET, args.front())) { - bool dnssec_valid; - std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(args.front(), dnssec_valid, - [](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid){return addresses[0];}); - if(!cryptonote::get_account_address_from_str(info, false, address_str)) + if(!cryptonote::get_account_address_from_str(info, cryptonote::STAGENET, args.front())) { - if(!cryptonote::get_account_address_from_str(info, true, address_str)) + bool dnssec_valid; + std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(args.front(), dnssec_valid, + [](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid){return addresses[0];}); + if(!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, address_str)) { - std::cout << "target account address has wrong format" << std::endl; - return true; - } - else - { - testnet = true; + if(!cryptonote::get_account_address_from_str(info, cryptonote::TESTNET, address_str)) + { + if(!cryptonote::get_account_address_from_str(info, cryptonote::STAGENET, address_str)) + { + std::cout << "target account address has wrong format" << std::endl; + return true; + } + else + { + nettype = cryptonote::STAGENET; + } + } + else + { + nettype = cryptonote::TESTNET; + } } } + else + { + nettype = cryptonote::STAGENET; + } } else { - testnet = true; + nettype = cryptonote::TESTNET; } } if (info.is_subaddress) @@ -299,8 +313,8 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg tools::fail_msg_writer() << "subaddress for mining reward is not yet supported!" << std::endl; return true; } - if(testnet) - std::cout << "Mining to a testnet address, make sure this is intentional!" << std::endl; + if(nettype != cryptonote::MAINNET) + std::cout << "Mining to a " << (nettype == cryptonote::TESTNET ? "testnet" : "stagenet") << "address, make sure this is intentional!" << std::endl; uint64_t threads_count = 1; bool do_background_mining = false; bool ignore_battery = false; @@ -325,7 +339,7 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg threads_count = (ok && 0 < threads_count) ? threads_count : 1; } - m_executor.start_mining(info.address, threads_count, testnet, do_background_mining, ignore_battery); + m_executor.start_mining(info.address, threads_count, nettype, do_background_mining, ignore_battery); return true; } diff --git a/src/daemon/core.h b/src/daemon/core.h index 1ff696bef..475f418d6 100644 --- a/src/daemon/core.h +++ b/src/daemon/core.h @@ -69,9 +69,12 @@ public: std::string get_config_subdir() const { bool testnet = command_line::get_arg(m_vm_HACK, cryptonote::arg_testnet_on); + bool stagenet = command_line::get_arg(m_vm_HACK, cryptonote::arg_stagenet_on); + bool mainnet = !testnet && !stagenet; std::string port = command_line::get_arg(m_vm_HACK, nodetool::arg_p2p_bind_port); - if ((!testnet && port != std::to_string(::config::P2P_DEFAULT_PORT)) - || (testnet && port != std::to_string(::config::testnet::P2P_DEFAULT_PORT))) { + if ((mainnet && port != std::to_string(::config::P2P_DEFAULT_PORT)) + || (testnet && port != std::to_string(::config::testnet::P2P_DEFAULT_PORT)) + || (stagenet && port != std::to_string(::config::stagenet::P2P_DEFAULT_PORT))) { return port; } return std::string(); diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 8053932fe..48671f190 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -76,15 +76,16 @@ public: core.set_protocol(protocol.get()); const auto testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); + const auto stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on); const auto restricted = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_restricted_rpc); const auto main_rpc_port = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port); - rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, testnet, main_rpc_port, "core"}); + rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, testnet ? cryptonote::TESTNET : stagenet ? cryptonote::STAGENET : cryptonote::MAINNET, main_rpc_port, "core"}); auto restricted_rpc_port_arg = cryptonote::core_rpc_server::arg_rpc_restricted_bind_port; if(!command_line::is_arg_defaulted(vm, restricted_rpc_port_arg)) { auto restricted_rpc_port = command_line::get_arg(vm, restricted_rpc_port_arg); - rpcs.emplace_back(new t_rpc{vm, core, p2p, true, testnet, restricted_rpc_port, "restricted"}); + rpcs.emplace_back(new t_rpc{vm, core, p2p, true, testnet ? cryptonote::TESTNET : stagenet ? cryptonote::STAGENET : cryptonote::MAINNET, restricted_rpc_port, "restricted"}); } } }; diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index 752a92ba4..50384b2a6 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -138,6 +138,14 @@ int main(int argc, char const * argv[]) return 0; } + const bool testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); + const bool stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on); + if (testnet && stagenet) + { + std::cerr << "Can't specify more than one of --tesnet and --stagenet" << ENDL; + return 1; + } + std::string db_type = command_line::get_arg(vm, cryptonote::arg_db_type); // verify that blockchaindb type is valid diff --git a/src/daemon/rpc.h b/src/daemon/rpc.h index 17f6c7f67..9621b0d01 100644 --- a/src/daemon/rpc.h +++ b/src/daemon/rpc.h @@ -54,7 +54,7 @@ public: , t_core & core , t_p2p & p2p , const bool restricted - , const bool testnet + , const cryptonote::network_type nettype , const std::string & port , const std::string & description ) @@ -62,7 +62,7 @@ public: { MGINFO("Initializing " << m_description << " RPC server..."); - if (!m_server.init(vm, restricted, testnet, port)) + if (!m_server.init(vm, restricted, nettype, port)) { throw std::runtime_error("Failed to initialize " + m_description + " RPC server."); } diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 5ef799d40..73b8d1a18 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -442,7 +442,7 @@ bool t_rpc_command_executor::show_status() { % (unsigned long long)ires.height % (unsigned long long)net_height % get_sync_percentage(ires) - % (ires.testnet ? "testnet" : "mainnet") + % (ires.testnet ? "testnet" : ires.stagenet ? "stagenet" : "mainnet") % bootstrap_msg % (!has_mining_info ? "mining info unavailable" : mining_busy ? "syncing" : mres.active ? ( ( mres.is_background_mining_enabled ? "smart " : "" ) + std::string("mining at ") + get_mining_speed(mres.speed) ) : "not mining") % get_mining_speed(ires.difficulty / ires.target) @@ -1036,10 +1036,10 @@ bool t_rpc_command_executor::print_transaction_pool_stats() { return true; } -bool t_rpc_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads, bool testnet, bool do_background_mining, bool ignore_battery) { +bool t_rpc_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining, bool ignore_battery) { cryptonote::COMMAND_RPC_START_MINING::request req; cryptonote::COMMAND_RPC_START_MINING::response res; - req.miner_address = cryptonote::get_account_address_as_str(testnet, false, address); + req.miner_address = cryptonote::get_account_address_as_str(nettype, false, address); req.threads_count = num_threads; req.do_background_mining = do_background_mining; req.ignore_battery = ignore_battery; diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index fa83d8988..46168c93b 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -105,7 +105,7 @@ public: bool print_transaction_pool_stats(); - bool start_mining(cryptonote::account_public_address address, uint64_t num_threads, bool testnet, bool do_background_mining = false, bool ignore_battery = false); + bool start_mining(cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining = false, bool ignore_battery = false); bool stop_mining(); |