From 3da9b480a84986cd31fbb1e5d54b3ee95959a3bc Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Sun, 24 Feb 2019 20:56:25 +0300 Subject: [PATCH] Add "seed" option to CLI (#1772) Supported in wallet_change_seed & wallet_create --- nano/node/cli.cpp | 50 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 7f3d3c4e..b250e459 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -53,6 +53,7 @@ void nano::add_node_options (boost::program_options::options_description & descr ("account", boost::program_options::value (), "Defines for other commands") ("file", boost::program_options::value (), "Defines for other commands") ("key", boost::program_options::value (), "Defines the for other commands, hex") + ("seed", boost::program_options::value (), "Defines the for other commands, hex") ("password", boost::program_options::value (), "Defines for other commands") ("wallet", boost::program_options::value (), "Defines for other commands") ("force", boost::program_options::value(), "Bool to force command if allowed"); @@ -424,7 +425,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map } else if (vm.count ("wallet_change_seed")) { - if (vm.count ("wallet") == 1 && vm.count ("key") == 1) + if (vm.count ("wallet") == 1 && (vm.count ("seed") == 1 || vm.count ("key") == 1)) { nano::uint256_union wallet_id; if (!wallet_id.decode_hex (vm["wallet"].as ())) @@ -441,16 +442,24 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map auto transaction (wallet->wallets.tx_begin_write ()); if (!wallet->enter_password (transaction, password)) { - nano::raw_key key; - if (!key.data.decode_hex (vm["key"].as ())) + nano::raw_key seed; + if (vm.count ("seed")) + { + if (seed.data.decode_hex (vm["seed"].as ())) + { + std::cerr << "Invalid seed\n"; + ec = nano::error_cli::invalid_arguments; + } + } + else if (seed.data.decode_hex (vm["key"].as ())) + { + std::cerr << "Invalid key seed\n"; + ec = nano::error_cli::invalid_arguments; + } + if (!ec) { std::cout << "Changing seed and caching work. Please wait..." << std::endl; - wallet->change_seed (transaction, key); - } - else - { - std::cerr << "Invalid key\n"; - ec = nano::error_cli::invalid_arguments; + wallet->change_seed (transaction, seed); } } else @@ -473,24 +482,37 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map } else { - std::cerr << "wallet_change_seed command requires one option and one option and optionally one option\n"; + std::cerr << "wallet_change_seed command requires one option and one option and optionally one option\n"; ec = nano::error_cli::invalid_arguments; } } else if (vm.count ("wallet_create")) { nano::raw_key seed_key; - if (vm.count ("key") == 1) + if (vm.count ("seed") == 1) + { + if (seed_key.data.decode_hex (vm["seed"].as ())) + { + std::cerr << "Invalid seed\n"; + ec = nano::error_cli::invalid_arguments; + } + } + else if (vm.count ("seed") > 1) + { + std::cerr << "wallet_create command allows one optional parameter\n"; + ec = nano::error_cli::invalid_arguments; + } + else if (vm.count ("key") == 1) { if (seed_key.data.decode_hex (vm["key"].as ())) { - std::cerr << "Invalid key\n"; + std::cerr << "Invalid seed key\n"; ec = nano::error_cli::invalid_arguments; } } else if (vm.count ("key") > 1) { - std::cerr << "wallet_create command allows one optional parameter\n"; + std::cerr << "wallet_create command allows one optional seed parameter\n"; ec = nano::error_cli::invalid_arguments; } if (!ec) @@ -511,7 +533,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map ec = nano::error_cli::invalid_arguments; } } - if (vm.count ("key")) + if (vm.count ("seed") || vm.count ("key")) { auto transaction (wallet->wallets.tx_begin_write ()); wallet->change_seed (transaction, seed_key);