From 410fef27bc84dbb0a8c174185aa68dc989725211 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Mon, 31 Aug 2015 16:49:47 -0500 Subject: [PATCH] Adding command line switch to insert a key in to a wallet. --- rai/cli/entry.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/rai/cli/entry.cpp b/rai/cli/entry.cpp index 713f6cf7..c3f09cff 100644 --- a/rai/cli/entry.cpp +++ b/rai/cli/entry.cpp @@ -119,6 +119,9 @@ int main (int argc, char * const * argv) ("expand_key", boost::program_options::value (), "Derive public key and account number from private key") ("get_account", boost::program_options::value (), "Get base58check encoded account from public key") ("get_key", boost::program_options::value (), "Get the public key for the base58check encoded account number") + ("wallet", boost::program_options::value (), "Wallet to operate on") + ("password", boost::program_options::value (), "Wallet password") + ("insert_key", boost::program_options::value (), "Insert key in to wallet") ("xorshift_profile", "Profile xorshift algorithms") ("verify_profile", "Profile signature verification"); boost::program_options::variables_map vm; @@ -209,6 +212,55 @@ int main (int argc, char * const * argv) account.decode_base58check (vm ["get_key"].as ()); std::cout << "Hex: " << account.to_string () << std::endl; } + else if (vm.count ("insert_key")) + { + if (vm.count ("wallet") > 0) + { + 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 (); + } + rai::node_init init; + rai::node_config config; + rai::work_pool work; + rai::processor_service processor; + auto service (boost::make_shared ()); + auto working (rai::working_path ()); + boost::filesystem::create_directories (working); + auto node (std::make_shared (init, service, working, processor, config, work)); + auto wallet (node->wallets.open (wallet_id)); + if (wallet != nullptr) + { + rai::transaction transaction (wallet->store.environment, nullptr, true); + wallet->store.enter_password (transaction, password); + if (wallet->store.valid_password (transaction)) + { + wallet->store.insert (transaction, vm ["insert_key"].as ()); + } + else + { + std::cerr << "Invalid password\n"; + } + } + else + { + std::cerr << "Wallet doesn't exist\n"; + } + } + else + { + std::cerr << "Invalid wallet id\n"; + } + } + else + { + std::cerr << "Wallet needs to be specified\n"; + } + } else if (vm.count ("profile_work")) { rai::work_pool work;