diff options
Diffstat (limited to 'src/cryptonote_core')
| -rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 14 | ||||
| -rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 9 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 4bada999f..18625de98 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -346,13 +346,21 @@ namespace cryptonote BlockchainDB::init_options(desc); } //----------------------------------------------------------------------------------------------- + network_type core::get_network_type_from_args(const boost::program_options::variables_map& vm) + { + const bool testnet = command_line::get_arg(vm, arg_testnet_on); + const bool stagenet = command_line::get_arg(vm, arg_stagenet_on); + const bool regtest = command_line::get_arg(vm, arg_regtest_on); + if (testnet + stagenet + regtest > 1) + throw std::runtime_error("More than one network type argument was specified"); + return testnet ? TESTNET : stagenet ? STAGENET : regtest ? FAKECHAIN : MAINNET; + } + //----------------------------------------------------------------------------------------------- bool core::handle_command_line(const boost::program_options::variables_map& vm) { if (m_nettype != FAKECHAIN) { - const bool testnet = command_line::get_arg(vm, arg_testnet_on); - const bool stagenet = command_line::get_arg(vm, arg_stagenet_on); - m_nettype = testnet ? TESTNET : stagenet ? STAGENET : MAINNET; + m_nettype = get_network_type_from_args(vm); } m_config_folder = command_line::get_arg(vm, arg_data_dir); diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 7806fe495..777de3319 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -277,6 +277,15 @@ namespace cryptonote static void init_options(boost::program_options::options_description& desc); /** + * @brief resolves the network type based on command line arguments + * @param vm variables map + * @return network type corresponding to arg_{testnet,stagenet,regtest}_on, defaulting to MAINNET + * @throw std::runtime_error if more than 1 of arg_{testnet,stagenet,regtest}_on is present + * @throw boost::bad_any_cast if arg_{testnet,stagenet,regtest}_on weren't added to vm + */ + static network_type get_network_type_from_args(const boost::program_options::variables_map& vm); + + /** * @brief initializes the core as needed * * This function initializes the transaction pool, the Blockchain, and |
