blockchain_utilities: fix --data-dir option

This commit is contained in:
jeffro256
2026-04-22 00:34:02 -05:00
parent 8b6be66bef
commit 8a20fd2bc8
11 changed files with 37 additions and 40 deletions
@@ -358,6 +358,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_testnet_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_txid);
command_line::add_arg(desc_cmd_sett, arg_output);
@@ -400,9 +401,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting...");
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);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
const network_type net_type = core::get_network_type_from_args(vm);
std::string opt_txid_string = command_line::get_arg(vm, arg_txid);
std::string opt_output_string = command_line::get_arg(vm, arg_output);
uint64_t opt_height = command_line::get_arg(vm, arg_height);
@@ -66,6 +66,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_testnet_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_txid);
command_line::add_arg(desc_cmd_sett, arg_height);
@@ -102,9 +103,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting...");
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);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
const network_type net_type = core::get_network_type_from_args(vm);
std::string opt_txid_string = command_line::get_arg(vm, arg_txid);
uint64_t opt_height = command_line::get_arg(vm, arg_height);
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, cryptonote::arg_testnet_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_block_start);
command_line::add_arg(desc_cmd_sett, arg_block_stop);
@@ -105,13 +106,6 @@ int main(int argc, char* argv[])
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);
std::string m_config_folder;
@@ -162,7 +156,8 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Error opening database: " << e.what());
return 1;
}
r = core_storage->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->init(db, net_type);
if (core_storage->get_blockchain_pruning_seed() && !opt_blocks_dat)
{
@@ -668,13 +668,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);
mlog_configure(mlog_get_default_log_path("monero-blockchain-import.log"), true);
@@ -462,6 +462,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_testnet_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_db_sync_mode);
command_line::add_arg(desc_cmd_sett, arg_copy_pruned_database);
@@ -496,9 +497,7 @@ int main(int argc, char* argv[])
MINFO("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);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
const network_type net_type = core::get_network_type_from_args(vm);
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);
while (boost::ends_with(data_dir, "/") || boost::ends_with(data_dir, "\\"))
@@ -115,6 +115,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_testnet_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_verbose);
command_line::add_arg(desc_cmd_sett, arg_dry_run);
@@ -151,9 +152,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting...");
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);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
const network_type net_type = core::get_network_type_from_args(vm);
bool opt_verbose = command_line::get_arg(vm, arg_verbose);
bool opt_dry_run = command_line::get_arg(vm, arg_dry_run);
@@ -147,6 +147,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_testnet_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_block_start);
command_line::add_arg(desc_cmd_sett, arg_block_stop);
@@ -189,9 +190,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting...");
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);
bool opt_stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
const network_type net_type = core::get_network_type_from_args(vm);
block_start = command_line::get_arg(vm, arg_block_start);
block_stop = command_line::get_arg(vm, arg_block_stop);
do_inputs = command_line::get_arg(vm, arg_inputs);
@@ -96,6 +96,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_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_rct_only);
command_line::add_arg(desc_cmd_sett, arg_input);
@@ -133,9 +134,7 @@ int main(int argc, char* argv[])
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);
network_type net_type = opt_testnet ? TESTNET : opt_stagenet ? STAGENET : MAINNET;
const network_type net_type = core::get_network_type_from_args(vm);
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.
+11 -3
View File
@@ -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);
+9
View File
@@ -276,6 +276,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
*
+2 -4
View File
@@ -247,10 +247,8 @@ int main(int argc, char const * argv[])
return 1;
}
const bool testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
const bool stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
const bool regtest = command_line::get_arg(vm, cryptonote::arg_regtest_on);
if (testnet + stagenet + regtest > 1)
try { cryptonote::core::get_network_type_from_args(vm); }
catch (const std::runtime_error&)
{
std::cerr << "Can't specify more than one of --tesnet and --stagenet and --regtest" << ENDL;
return 1;