Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify wallet_create CLI to allow seed & password change #719

Merged
merged 8 commits into from
Jan 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,57 @@ 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 << "wallet_change_seed command requires one <wallet> option and one <key> option and optionally one <password> option\n";
ec = nano::error_cli::invalid_arguments;
}
}
else if (vm.count ("wallet_create"))
{
inactive_node node (data_path);
nano::keypair key;
std::cout << key.pub.to_string () << std::endl;
auto wallet (node.node->wallets.create (key.pub));
nano::raw_key seed_key;
if (vm.count ("key") == 1)
{
if (seed_key.data.decode_hex (vm["key"].as<std::string> ()))
{
std::cerr << "Invalid key\n";
ec = nano::error_cli::invalid_arguments;
}
}
else if (vm.count ("key") > 1)
{
std::cerr << "wallet_create command allows one optional <key> parameter\n";
ec = nano::error_cli::invalid_arguments;
}
if (!ec)
{
inactive_node node (data_path);
nano::keypair wallet_key;
auto wallet (node.node->wallets.create (wallet_key.pub));
if (wallet != nullptr)
{
if (vm.count ("password") > 0)
{
std::string password (vm["password"].as<std::string> ());
auto transaction (wallet->wallets.tx_begin_write ());
auto error (wallet->store.rekey (transaction, password));
if (error)
{
std::cerr << "Password change error\n";
ec = nano::error_cli::invalid_arguments;
}
}
if (vm.count ("key"))
{
auto transaction (wallet->wallets.tx_begin_write ());
wallet->change_seed (transaction, seed_key);
}
std::cout << wallet_key.pub.to_string () << std::endl;
}
else
{
std::cerr << "Wallet creation error\n";
ec = nano::error_cli::invalid_arguments;
}
}
}
else if (vm.count ("wallet_decrypt_unsafe"))
{
Expand Down