This commit is contained in:
stoffu 2018-02-16 20:04:04 +09:00
parent cc9a0bee04
commit af773211cb
No known key found for this signature in database
GPG key ID: 41DAB8343A9EC012
58 changed files with 566 additions and 357 deletions

View file

@ -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;
}
};

View file

@ -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;
}

View file

@ -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();

View file

@ -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"});
}
}
};

View file

@ -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

View file

@ -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.");
}

View file

@ -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;

View file

@ -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();