Skip to content

Commit

Permalink
confirmation_height_clear cli account param (nanocurrency#3836)
Browse files Browse the repository at this point in the history
* confirmation_height_clear cli account param

* Add back missing password option

* Improve the error/help messages to the required account option

- Improve the error message to say the account can be 'all'
- Improve the confirmation_height_clear help message to inform the value
'all' can be passed to clear all accounts

Co-authored-by: Thiago Silva <thiago@nano.org>
  • Loading branch information
2 people authored and gr0vity committed Jul 9, 2022
1 parent 7c07474 commit a21caaf
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void nano::add_node_options (boost::program_options::options_description & descr
("online_weight_clear", "Clear online weight history records")
("peer_clear", "Clear online peers database dump")
("unchecked_clear", "Clear unchecked blocks")
("confirmation_height_clear", "Clear confirmation height")
("confirmation_height_clear", "Clear confirmation height. Requires an <account> option that can be 'all' to clear all accounts")
("final_vote_clear", "Clear final votes")
("rebuild_database", "Rebuild LMDB database with vacuum for best compaction")
("migrate_database_lmdb_to_rocksdb", "Migrates LMDB database to RocksDB")
Expand Down Expand Up @@ -321,7 +321,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
}
else
{
std::cerr << "wallet_add command requires one <wallet> option and one <key> option and optionally one <password> option\n";
std::cerr << "account_create command requires one <wallet> option and optionally one <password> option\n";
ec = nano::error_cli::invalid_arguments;
}
}
Expand Down Expand Up @@ -579,10 +579,9 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
nano::inactive_node node (data_path, node_flags);
if (!node.node->init_error ())
{
auto account_it = vm.find ("account");
if (account_it != vm.cend ())
if (vm.count ("account") == 1)
{
auto account_str = account_it->second.as<std::string> ();
auto account_str = vm["account"].as<std::string> ();
nano::account account;
if (!account.decode_account (account_str))
{
Expand All @@ -609,17 +608,22 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
ec = nano::error_cli::generic;
}
}
else if (account_str == "all")
{
auto transaction (node.node->store.tx_begin_write ());
reset_confirmation_heights (transaction, node.node->network_params.ledger, node.node->store);
std::cout << "Confirmation heights of all accounts (except genesis which is set to 1) are set to 0" << std::endl;
}
else
{
std::cerr << "Invalid account id\n";
std::cerr << "Specify either valid account id or 'all'\n";
ec = nano::error_cli::invalid_arguments;
}
}
else
{
auto transaction (node.node->store.tx_begin_write ());
reset_confirmation_heights (transaction, node.node->network_params.ledger, node.node->store);
std::cout << "Confirmation heights of all accounts (except genesis which is set to 1) are set to 0" << std::endl;
std::cerr << "confirmation_height_clear command requires one <account> option that may contain an account or the value 'all'\n";
ec = nano::error_cli::invalid_arguments;
}
}
else
Expand Down

0 comments on commit a21caaf

Please sign in to comment.