blockchain_utilities: fix --data-dir option

This commit is contained in:
jeffro256
2026-04-22 00:27:53 -05:00
parent 230de37949
commit def9420da1
11 changed files with 37 additions and 40 deletions
@@ -355,6 +355,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir); command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_regtest_on);
command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_txid); command_line::add_arg(desc_cmd_sett, arg_txid);
command_line::add_arg(desc_cmd_sett, arg_output); command_line::add_arg(desc_cmd_sett, arg_output);
@@ -397,9 +398,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting..."); LOG_PRINT_L0("Starting...");
std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir); std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir);
bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); const network_type net_type = core::get_network_type_from_args(vm);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
std::string opt_txid_string = command_line::get_arg(vm, arg_txid); std::string opt_txid_string = command_line::get_arg(vm, arg_txid);
std::string opt_output_string = command_line::get_arg(vm, arg_output); std::string opt_output_string = command_line::get_arg(vm, arg_output);
uint64_t opt_height = command_line::get_arg(vm, arg_height); uint64_t opt_height = command_line::get_arg(vm, arg_height);
@@ -63,6 +63,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir); command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_regtest_on);
command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_txid); command_line::add_arg(desc_cmd_sett, arg_txid);
command_line::add_arg(desc_cmd_sett, arg_height); command_line::add_arg(desc_cmd_sett, arg_height);
@@ -99,9 +100,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting..."); LOG_PRINT_L0("Starting...");
std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir); std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir);
bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); const network_type net_type = core::get_network_type_from_args(vm);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
std::string opt_txid_string = command_line::get_arg(vm, arg_txid); std::string opt_txid_string = command_line::get_arg(vm, arg_txid);
uint64_t opt_height = command_line::get_arg(vm, arg_height); uint64_t opt_height = command_line::get_arg(vm, arg_height);
bool opt_include_coinbase = command_line::get_arg(vm, arg_include_coinbase); bool opt_include_coinbase = command_line::get_arg(vm, arg_include_coinbase);
@@ -68,6 +68,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, arg_output_file); command_line::add_arg(desc_cmd_sett, arg_output_file);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_regtest_on);
command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_block_start); command_line::add_arg(desc_cmd_sett, arg_block_start);
command_line::add_arg(desc_cmd_sett, arg_block_stop); command_line::add_arg(desc_cmd_sett, arg_block_stop);
@@ -105,13 +106,6 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting..."); LOG_PRINT_L0("Starting...");
bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
if (opt_testnet && opt_stagenet)
{
std::cerr << "Can't specify more than one of --testnet and --stagenet" << std::endl;
return 1;
}
bool opt_blocks_dat = command_line::get_arg(vm, arg_blocks_dat); bool opt_blocks_dat = command_line::get_arg(vm, arg_blocks_dat);
std::string m_config_folder; std::string m_config_folder;
@@ -154,7 +148,8 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Error opening database: " << e.what()); LOG_PRINT_L0("Error opening database: " << e.what());
return 1; return 1;
} }
r = core_storage->blockchain.init(db, opt_testnet ? cryptonote::TESTNET : opt_stagenet ? cryptonote::STAGENET : cryptonote::MAINNET); const network_type net_type = core::get_network_type_from_args(vm);
r = core_storage->blockchain.init(db, net_type);
if (core_storage->blockchain.get_blockchain_pruning_seed() && !opt_blocks_dat) if (core_storage->blockchain.get_blockchain_pruning_seed() && !opt_blocks_dat)
{ {
@@ -667,13 +667,6 @@ int main(int argc, char* argv[])
} }
} }
opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
if (opt_testnet && opt_stagenet)
{
std::cerr << "Error: Can't specify more than one of --testnet and --stagenet" << ENDL;
return 1;
}
m_config_folder = command_line::get_arg(vm, cryptonote::arg_data_dir); m_config_folder = command_line::get_arg(vm, cryptonote::arg_data_dir);
mlog_configure(mlog_get_default_log_path("monero-blockchain-import.log"), true); mlog_configure(mlog_get_default_log_path("monero-blockchain-import.log"), true);
@@ -547,6 +547,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir); command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_regtest_on);
command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_db_sync_mode); command_line::add_arg(desc_cmd_sett, arg_db_sync_mode);
command_line::add_arg(desc_cmd_sett, arg_copy_pruned_database); command_line::add_arg(desc_cmd_sett, arg_copy_pruned_database);
@@ -581,9 +582,7 @@ int main(int argc, char* argv[])
MINFO("Starting..."); MINFO("Starting...");
bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); const network_type net_type = core::get_network_type_from_args(vm);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
bool opt_copy_pruned_database = command_line::get_arg(vm, arg_copy_pruned_database); bool opt_copy_pruned_database = command_line::get_arg(vm, arg_copy_pruned_database);
std::string data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir); std::string data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir);
while (boost::ends_with(data_dir, "/") || boost::ends_with(data_dir, "\\")) while (boost::ends_with(data_dir, "/") || boost::ends_with(data_dir, "\\"))
@@ -112,6 +112,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir); command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_regtest_on);
command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_verbose); command_line::add_arg(desc_cmd_sett, arg_verbose);
command_line::add_arg(desc_cmd_sett, arg_dry_run); command_line::add_arg(desc_cmd_sett, arg_dry_run);
@@ -148,9 +149,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting..."); LOG_PRINT_L0("Starting...");
std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir); std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir);
bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); const network_type net_type = core::get_network_type_from_args(vm);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
bool opt_verbose = command_line::get_arg(vm, arg_verbose); bool opt_verbose = command_line::get_arg(vm, arg_verbose);
bool opt_dry_run = command_line::get_arg(vm, arg_dry_run); bool opt_dry_run = command_line::get_arg(vm, arg_dry_run);
@@ -145,6 +145,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir); command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_regtest_on);
command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_block_start); command_line::add_arg(desc_cmd_sett, arg_block_start);
command_line::add_arg(desc_cmd_sett, arg_block_stop); command_line::add_arg(desc_cmd_sett, arg_block_stop);
@@ -187,9 +188,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting..."); LOG_PRINT_L0("Starting...");
std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir); std::string opt_data_dir = command_line::get_arg(vm, cryptonote::arg_data_dir);
bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); const network_type net_type = core::get_network_type_from_args(vm);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
block_start = command_line::get_arg(vm, arg_block_start); block_start = command_line::get_arg(vm, arg_block_start);
block_stop = command_line::get_arg(vm, arg_block_stop); block_stop = command_line::get_arg(vm, arg_block_stop);
do_inputs = command_line::get_arg(vm, arg_inputs); do_inputs = command_line::get_arg(vm, arg_inputs);
@@ -93,6 +93,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on); command_line::add_arg(desc_cmd_sett, cryptonote::arg_stagenet_on);
command_line::add_arg(desc_cmd_sett, cryptonote::arg_regtest_on);
command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_rct_only); command_line::add_arg(desc_cmd_sett, arg_rct_only);
command_line::add_arg(desc_cmd_sett, arg_input); command_line::add_arg(desc_cmd_sett, arg_input);
@@ -130,9 +131,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting..."); LOG_PRINT_L0("Starting...");
bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); const network_type net_type = core::get_network_type_from_args(vm);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
bool opt_rct_only = command_line::get_arg(vm, arg_rct_only); bool opt_rct_only = command_line::get_arg(vm, arg_rct_only);
// If we wanted to use the memory pool, we would set up a fake_core. // If we wanted to use the memory pool, we would set up a fake_core.
+11 -3
View File
@@ -354,13 +354,21 @@ namespace cryptonote
BlockchainDB::init_options(desc); 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) bool core::handle_command_line(const boost::program_options::variables_map& vm)
{ {
if (m_nettype != FAKECHAIN) if (m_nettype != FAKECHAIN)
{ {
const bool testnet = command_line::get_arg(vm, arg_testnet_on); m_nettype = get_network_type_from_args(vm);
const bool stagenet = command_line::get_arg(vm, arg_stagenet_on);
m_nettype = testnet ? TESTNET : stagenet ? STAGENET : MAINNET;
} }
m_config_folder = command_line::get_arg(vm, arg_data_dir); m_config_folder = command_line::get_arg(vm, arg_data_dir);
+9
View File
@@ -276,6 +276,15 @@ namespace cryptonote
*/ */
static void init_options(boost::program_options::options_description& desc); 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 * @brief initializes the core as needed
* *
+2 -4
View File
@@ -240,10 +240,8 @@ int main(int argc, char const * argv[])
return 1; return 1;
} }
const bool testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); try { cryptonote::core::get_network_type_from_args(vm); }
const bool stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on); catch (const std::runtime_error&)
const bool regtest = command_line::get_arg(vm, cryptonote::arg_regtest_on);
if (testnet + stagenet + regtest > 1)
{ {
std::cerr << "Can't specify more than one of --testnet and --stagenet and --regtest" << ENDL; std::cerr << "Can't specify more than one of --testnet and --stagenet and --regtest" << ENDL;
return 1; return 1;