From 821754cd7b5daa75f72f48fd26f75e29cb980b8b Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sat, 26 Mar 2016 12:37:39 -0500 Subject: [PATCH] Add commands to set wallet seed. --- rai/node/node.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/rai/node/node.cpp b/rai/node/node.cpp index 427b9c35..fdfdd0e1 100644 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -2408,6 +2408,7 @@ void rai::add_node_options (boost::program_options::options_description & descri ("wallet_add_adhoc", "Insert in to ") ("wallet_add_next", "Insert next deterministic key in to ") ("wallet_create", "Creates a new wallet and prints the ID") + ("wallet_change_seed", "Changes seed for to ") ("wallet_decrypt_unsafe", "Decrypts using , !!THIS WILL PRINT YOUR PRIVATE KEY TO STDOUT!!") ("wallet_destroy", "Destroys and all keys it contains") ("wallet_import", "Imports keys in using in to ") @@ -2506,10 +2507,17 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { if (!wallet->enter_password (password)) { - rai::transaction transaction (wallet->store.environment, nullptr, true); rai::raw_key key; - key.data.decode_hex (vm ["key"].as ()); - wallet->store.insert_adhoc (transaction, key); + if (!key.data.decode_hex (vm ["key"].as ())) + { + rai::transaction transaction (wallet->store.environment, nullptr, true); + wallet->store.insert_adhoc (transaction, key); + } + else + { + std::cerr << "Invalid key\n"; + result = true; + } } else { @@ -2581,6 +2589,60 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) result = true; } } + else if (vm.count ("wallet_change_seed")) + { + if (vm.count ("wallet") == 1 && vm.count ("key") == 1) + { + rai::uint256_union wallet_id; + if (!wallet_id.decode_hex (vm ["wallet"].as ())) + { + std::string password; + if (vm.count ("password") > 0) + { + password = vm ["password"].as (); + } + inactive_node node; + auto wallet (node.node->wallets.open (wallet_id)); + if (wallet != nullptr) + { + if (!wallet->enter_password (password)) + { + rai::raw_key key; + if (!key.data.decode_hex (vm ["key"].as ())) + { + rai::transaction transaction (wallet->store.environment, nullptr, true); + wallet->store.seed_set (transaction, key); + } + else + { + std::cerr << "Invalid key\n"; + result = true; + } + } + else + { + std::cerr << "Invalid password\n"; + result = true; + } + } + else + { + std::cerr << "Wallet doesn't exist\n"; + result = true; + } + } + else + { + std::cerr << "Invalid wallet id\n"; + result = true; + } + } + else + { + std::cerr << "wallet_add command requires one option and one option and optionally one option"; + result = true; + } + } else if (vm.count ("wallet_create")) { inactive_node node;