From ff34fca6de8e2bc8240cd26159c09606ef0ae525 Mon Sep 17 00:00:00 2001 From: SergiySW Date: Mon, 5 Feb 2018 17:01:05 +0300 Subject: [PATCH] Adding data_path support for CLI operations To resolve issue https://github.com/clemahieu/raiblocks/issues/328 Replacing https://github.com/clemahieu/raiblocks/pull/342 --- rai/node/node.cpp | 29 ++++++++++++++--------------- rai/rai_node/entry.cpp | 16 ++++------------ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/rai/node/node.cpp b/rai/node/node.cpp index 3533d7ec..05fce00a 100644 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -2991,6 +2991,7 @@ void rai::add_node_options (boost::program_options::options_description & descri bool rai::handle_node_options (boost::program_options::variables_map & vm) { auto result (false); + boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : rai::working_path (); if (vm.count ("account_create")) { if (vm.count ("wallet") == 1) @@ -3003,7 +3004,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { password = vm["password"].as (); } - inactive_node node; + inactive_node node (data_path); auto wallet (node.node->wallets.open (wallet_id)); if (wallet != nullptr) { @@ -3069,8 +3070,6 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { try { - boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : rai::working_path (); - auto vacuum_path = data_path / "vacuumed.ldb"; auto source_path = data_path / "data.ldb"; auto backup_path = data_path / "backup.vacuum.ldb"; @@ -3107,7 +3106,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) } else if (vm.count ("diagnostics")) { - inactive_node node; + inactive_node node (data_path); std::cout << "Testing hash function" << std::endl; rai::raw_key key; key.data.clear (); @@ -3170,7 +3169,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { password = vm["password"].as (); } - inactive_node node; + inactive_node node (data_path); auto wallet (node.node->wallets.open (wallet_id)); if (wallet != nullptr) { @@ -3224,7 +3223,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { password = vm["password"].as (); } - inactive_node node; + inactive_node node (data_path); auto wallet (node.node->wallets.open (wallet_id)); if (wallet != nullptr) { @@ -3268,7 +3267,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) } else if (vm.count ("wallet_create")) { - inactive_node node; + inactive_node node (data_path); rai::keypair key; std::cout << key.pub.to_string () << std::endl; auto wallet (node.node->wallets.create (key.pub)); @@ -3286,7 +3285,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) rai::uint256_union wallet_id; if (!wallet_id.decode_hex (vm["wallet"].as ())) { - inactive_node node; + inactive_node node (data_path); auto existing (node.node->wallets.items.find (wallet_id)); if (existing != node.node->wallets.items.end ()) { @@ -3336,7 +3335,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) rai::uint256_union wallet_id; if (!wallet_id.decode_hex (vm["wallet"].as ())) { - inactive_node node; + inactive_node node (data_path); if (node.node->wallets.items.find (wallet_id) != node.node->wallets.items.end ()) { node.node->wallets.destroy (wallet_id); @@ -3380,7 +3379,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) rai::uint256_union wallet_id; if (!wallet_id.decode_hex (vm["wallet"].as ())) { - inactive_node node; + inactive_node node (data_path); auto existing (node.node->wallets.items.find (wallet_id)); if (existing != node.node->wallets.items.end ()) { @@ -3426,7 +3425,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) } else if (vm.count ("wallet_list")) { - inactive_node node; + inactive_node node (data_path); for (auto i (node.node->wallets.items.begin ()), n (node.node->wallets.items.end ()); i != n; ++i) { std::cout << boost::str (boost::format ("Wallet ID: %1%\n") % i->first.to_string ()); @@ -3441,7 +3440,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { if (vm.count ("wallet") == 1 && vm.count ("account") == 1) { - inactive_node node; + inactive_node node (data_path); rai::uint256_union wallet_id; if (!wallet_id.decode_hex (vm["wallet"].as ())) { @@ -3494,7 +3493,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) rai::uint256_union wallet_id; if (!wallet_id.decode_hex (vm["wallet"].as ())) { - inactive_node node; + inactive_node node (data_path); auto wallet (node.node->wallets.items.find (wallet_id)); if (wallet != node.node->wallets.items.end ()) { @@ -3532,7 +3531,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) rai::account account; if (!account.decode_account (vm["account"].as ())) { - inactive_node node; + inactive_node node (data_path); auto wallet (node.node->wallets.items.find (wallet_id)); if (wallet != node.node->wallets.items.end ()) { @@ -3571,7 +3570,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) } else if (vm.count ("vote_dump") == 1) { - inactive_node node; + inactive_node node (data_path); rai::transaction transaction (node.node->store.environment, nullptr, false); for (auto i (node.node->store.vote_begin (transaction)), n (node.node->store.vote_end ()); i != n; ++i) { diff --git a/rai/rai_node/entry.cpp b/rai/rai_node/entry.cpp index de4ab262..f480a688 100644 --- a/rai/rai_node/entry.cpp +++ b/rai/rai_node/entry.cpp @@ -138,26 +138,18 @@ int main (int argc, char * const * argv) boost::program_options::store (boost::program_options::parse_command_line (argc, argv, description), vm); boost::program_options::notify (vm); int result (0); + boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : rai::working_path (); if (!rai::handle_node_options (vm)) { } else if (vm.count ("daemon") > 0) { - boost::filesystem::path data_path; - if (vm.count ("data_path")) - { - data_path = boost::filesystem::path (vm["data_path"].as ()); - } - else - { - data_path = rai::working_path (); - } rai_daemon::daemon daemon; daemon.run (data_path); } else if (vm.count ("debug_block_count")) { - rai::inactive_node node; + rai::inactive_node node (data_path); rai::transaction transaction (node.node->store.environment, nullptr, false); std::cout << boost::str (boost::format ("Block count: %1%\n") % node.node->store.block_count (transaction).sum ()); } @@ -217,7 +209,7 @@ int main (int argc, char * const * argv) } else if (vm.count ("debug_dump_representatives")) { - rai::inactive_node node; + rai::inactive_node node (data_path); rai::transaction transaction (node.node->store.environment, nullptr, false); rai::uint128_t total; for (auto i (node.node->store.representation_begin (transaction)), n (node.node->store.representation_end ()); i != n; ++i) @@ -245,7 +237,7 @@ int main (int argc, char * const * argv) } else if (vm.count ("debug_frontier_count")) { - rai::inactive_node node; + rai::inactive_node node (data_path); rai::transaction transaction (node.node->store.environment, nullptr, false); std::cout << boost::str (boost::format ("Frontier count: %1%\n") % node.node->store.frontier_count (transaction)); }