CLI wallet_import force wallet creation if requested (#1357)

This commit is contained in:
Russel Waters 2018-11-08 14:34:17 -05:00 committed by Roy Keene
commit d59d36f24f

View file

@ -51,7 +51,8 @@ void rai::add_node_options (boost::program_options::options_description & descri
("file", boost::program_options::value<std::string> (), "Defines <file> for other commands")
("key", boost::program_options::value<std::string> (), "Defines the <key> for other commands, hex")
("password", boost::program_options::value<std::string> (), "Defines <password> for other commands")
("wallet", boost::program_options::value<std::string> (), "Defines <wallet> for other commands");
("wallet", boost::program_options::value<std::string> (), "Defines <wallet> for other commands")
("force", boost::program_options::value<bool>(), "Bool to force command if allowed");
// clang-format on
}
@ -525,6 +526,7 @@ std::error_code rai::handle_node_options (boost::program_options::variables_map
{
if (vm.count ("file") == 1)
{
bool forced (false);
std::string filename (vm["file"].as<std::string> ());
std::ifstream stream;
stream.open (filename.c_str ());
@ -537,6 +539,10 @@ std::error_code rai::handle_node_options (boost::program_options::variables_map
{
password = vm["password"].as<std::string> ();
}
if (vm.count ("force") == 1)
{
forced = vm["force"].as<bool> ();
}
if (vm.count ("wallet") == 1)
{
rai::uint256_union wallet_id;
@ -554,8 +560,21 @@ std::error_code rai::handle_node_options (boost::program_options::variables_map
}
else
{
std::cerr << "Wallet doesn't exist\n";
ec = rai::error_cli::invalid_arguments;
if (!forced)
{
std::cerr << "Wallet doesn't exist\n";
ec = rai::error_cli::invalid_arguments;
}
else
{
node.node->wallets.create (wallet_id);
auto existing (node.node->wallets.items.find (wallet_id));
if (existing->second->import (contents.str (), password))
{
std::cerr << "Unable to import wallet\n";
ec = rai::error_cli::invalid_arguments;
}
}
}
}
else