Can call node operations from the rai_wallet.
This commit is contained in:
parent
18fbe9bc08
commit
d115013263
5 changed files with 334 additions and 281 deletions
|
@ -182,19 +182,19 @@ else (WIN32)
|
|||
set (PLATFORM_WALLET_LIBS)
|
||||
endif (WIN32)
|
||||
|
||||
target_link_libraries (core_test node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
target_link_libraries (core_test node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
|
||||
target_link_libraries (slow_test node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${CRYPTOPP_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
target_link_libraries (slow_test node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${CRYPTOPP_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
|
||||
target_link_libraries (rai_node node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
target_link_libraries (rai_node node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
|
||||
target_link_libraries (landing node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
target_link_libraries (landing node secure lmdb xxhash ed25519 argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_THREAD_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS})
|
||||
|
||||
target_link_libraries (qt_test node secure lmdb xxhash ed25519 qt argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS})
|
||||
target_link_libraries (qt_test node secure lmdb xxhash ed25519 qt argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS})
|
||||
|
||||
target_link_libraries (rai_wallet node secure lmdb xxhash ed25519 qt argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${PLATFORM_WALLET_LIBS})
|
||||
target_link_libraries (rai_wallet node secure lmdb xxhash ed25519 qt argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${PLATFORM_WALLET_LIBS})
|
||||
|
||||
target_link_libraries (qt_system node secure lmdb xxhash ed25519 qt argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS})
|
||||
target_link_libraries (qt_system node secure lmdb xxhash ed25519 qt argon2 blake2 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS})
|
||||
|
||||
if (APPLE)
|
||||
get_filename_component (Qt5Core_framework_DIR ${Qt5_DIR}/../../QtCore.framework ABSOLUTE)
|
||||
|
|
|
@ -8,9 +8,12 @@
|
|||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/utility/setup/console.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
#include <ed25519-donna/ed25519.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
rai::message_parser::message_parser (rai::message_visitor & visitor_a, rai::work_pool & pool_a) :
|
||||
|
@ -4046,3 +4049,278 @@ void rai::thread_runner::join ()
|
|||
i.join ();
|
||||
}
|
||||
}
|
||||
|
||||
void rai::add_node_options (boost::program_options::options_description & description_a)
|
||||
{
|
||||
description_a.add_options ()
|
||||
("account_base58", boost::program_options::value <std::string> (), "Get base58 account number for the <key>")
|
||||
("account_key", "Get the public key for the <account>")
|
||||
("key_create", "Generates a random keypair")
|
||||
("key_expand", "Derive public key and account number from <key>")
|
||||
("wallet_add", "Insert <key> in to <wallet>")
|
||||
("wallet_list", "Dumps wallet IDs and public keys")
|
||||
("wallet_remove", "Remove <account> from <wallet>")
|
||||
("wallet_representative_get", "Prints default representative for <wallet>")
|
||||
("wallet_representative_set", "Set <account> as default representative for <wallet>")
|
||||
("account", boost::program_options::value <std::string> (), "Defines <account> for other commands, base58")
|
||||
("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");
|
||||
}
|
||||
|
||||
bool rai::handle_node_options (boost::program_options::variables_map & vm)
|
||||
{
|
||||
auto result (false);
|
||||
if (vm.count ("account_base58") > 0)
|
||||
{
|
||||
if (vm.count ("key") == 1)
|
||||
{
|
||||
rai::uint256_union pub;
|
||||
pub.decode_hex (vm ["key"].as <std::string> ());
|
||||
std::cout << "Account: " << pub.to_base58check () << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "account_base58 comand requires one <key> option";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("account_key") > 0)
|
||||
{
|
||||
if (vm.count ("account") == 1)
|
||||
{
|
||||
rai::uint256_union account;
|
||||
account.decode_base58check (vm ["account"].as <std::string> ());
|
||||
std::cout << "Hex: " << account.to_string () << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "account_key command requires one <account> option";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("key_create"))
|
||||
{
|
||||
rai::keypair pair;
|
||||
std::cout << "Private: " << pair.prv.to_string () << std::endl << "Public: " << pair.pub.to_string () << std::endl << "Account: " << pair.pub.to_base58check () << std::endl;
|
||||
}
|
||||
else if (vm.count ("key_expand"))
|
||||
{
|
||||
if (vm.count ("key") == 1)
|
||||
{
|
||||
rai::uint256_union prv;
|
||||
prv.decode_hex (vm ["key"].as <std::string> ());
|
||||
rai::uint256_union pub;
|
||||
ed25519_publickey (prv.bytes.data (), pub.bytes.data ());
|
||||
std::cout << "Private: " << prv.to_string () << std::endl << "Public: " << pub.to_string () << std::endl << "Account: " << pub.to_base58check () << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "key_expand command requires one <key> option";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_add"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1 && vm.count ("key") == 1)
|
||||
{
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
std::string password;
|
||||
if (vm.count ("password") > 0)
|
||||
{
|
||||
password = vm ["password"].as <std::string> ();
|
||||
}
|
||||
inactive_node node;
|
||||
auto wallet (node.node->wallets.open (wallet_id));
|
||||
if (wallet != nullptr)
|
||||
{
|
||||
if (!wallet->enter_password (password))
|
||||
{
|
||||
rai::transaction transaction (wallet->store.environment, nullptr, true);
|
||||
wallet->store.insert (transaction, vm ["key"].as <std::string> ());
|
||||
}
|
||||
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 <wallet> option and one <key> option and optionally one <password> option";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_list"))
|
||||
{
|
||||
inactive_node node;
|
||||
for (auto i (node.node->wallets.items.begin ()), n (node.node->wallets.items.end ()); i != n; ++i)
|
||||
{
|
||||
std::cout << boost::str (boost::format ("Wallet ID: %1%\n") % i->first.to_string ());
|
||||
rai::transaction transaction (i->second->store.environment, nullptr, false);
|
||||
for (auto j (i->second->store.begin (transaction)), m (i->second->store.end ()); j != m; ++j)
|
||||
{
|
||||
std::cout << rai::uint256_union (j->first).to_base58check () << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_remove"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1 && vm.count ("account") == 1)
|
||||
{
|
||||
inactive_node node;
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
auto wallet (node.node->wallets.items.find (wallet_id));
|
||||
if (wallet != node.node->wallets.items.end ())
|
||||
{
|
||||
rai::account account_id;
|
||||
if (!account_id.decode_base58check (vm ["account"].as <std::string> ()))
|
||||
{
|
||||
rai::transaction transaction (wallet->second->store.environment, nullptr, true);
|
||||
auto account (wallet->second->store.find (transaction, account_id));
|
||||
if (account != wallet->second->store.end ())
|
||||
{
|
||||
wallet->second->store.erase (transaction, account_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Account not found in wallet\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid account id\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wallet not found\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid wallet id\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_remove command requires one <wallet> and one <account> option\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_representative_get"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
inactive_node node;
|
||||
auto wallet (node.node->wallets.items.find (wallet_id));
|
||||
if (wallet != node.node->wallets.items.end ())
|
||||
{
|
||||
rai::transaction transaction (wallet->second->store.environment, nullptr, false);
|
||||
auto representative (wallet->second->store.representative (transaction));
|
||||
std::cout << boost::str (boost::format ("Representative: %1%\n") % representative.to_base58check ());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wallet not found\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid wallet id\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_representative_get requires one <wallet> option\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_representative_set"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
if (vm.count ("account") == 1)
|
||||
{
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
rai::account account;
|
||||
if (!account.decode_base58check (vm ["account"].as <std::string> ()))
|
||||
{
|
||||
inactive_node node;
|
||||
auto wallet (node.node->wallets.items.find (wallet_id));
|
||||
if (wallet != node.node->wallets.items.end ())
|
||||
{
|
||||
rai::transaction transaction (wallet->second->store.environment, nullptr, true);
|
||||
wallet->second->store.representative_set (transaction, account);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wallet not found\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid account\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid wallet id\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_representative_set requires one <account> option\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_representative_set requires one <wallet> option\n";
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
rai::inactive_node::inactive_node ()
|
||||
{
|
||||
auto working (rai::working_path ());
|
||||
boost::filesystem::create_directories (working);
|
||||
auto service (boost::make_shared <boost::asio::io_service> ());
|
||||
node = std::make_shared <rai::node> (init, service, 24000, working, processor, logging, work);
|
||||
}
|
|
@ -93,6 +93,11 @@ struct hash <rai::endpoint>
|
|||
return hash (endpoint_a);
|
||||
}
|
||||
};
|
||||
namespace program_options
|
||||
{
|
||||
class options_description;
|
||||
class variables_map;
|
||||
}
|
||||
}
|
||||
|
||||
namespace rai
|
||||
|
@ -734,5 +739,17 @@ public:
|
|||
void join ();
|
||||
std::vector <std::thread> threads;
|
||||
};
|
||||
void add_node_options (boost::program_options::options_description &);
|
||||
bool handle_node_options (boost::program_options::variables_map &);
|
||||
class inactive_node
|
||||
{
|
||||
public:
|
||||
inactive_node ();
|
||||
rai::processor_service processor;
|
||||
rai::logging logging;
|
||||
rai::node_init init;
|
||||
rai::work_pool work;
|
||||
std::shared_ptr <rai::node> node;
|
||||
};
|
||||
extern std::chrono::milliseconds const confirm_wait;
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
#include <emmintrin.h>
|
||||
|
||||
#include <ed25519-donna/ed25519.h>
|
||||
|
||||
class xorshift128
|
||||
{
|
||||
public:
|
||||
|
@ -108,297 +106,32 @@ void fill_zero (void * data)
|
|||
}
|
||||
#endif // 0
|
||||
|
||||
class inactive_node
|
||||
{
|
||||
public:
|
||||
inactive_node ()
|
||||
{
|
||||
auto working (rai::working_path ());
|
||||
boost::filesystem::create_directories (working);
|
||||
auto service (boost::make_shared <boost::asio::io_service> ());
|
||||
node = std::make_shared <rai::node> (init, service, 24000, working, processor, logging, work);
|
||||
}
|
||||
rai::processor_service processor;
|
||||
rai::logging logging;
|
||||
rai::node_init init;
|
||||
rai::work_pool work;
|
||||
std::shared_ptr <rai::node> node;
|
||||
};
|
||||
|
||||
int main (int argc, char * const * argv)
|
||||
{
|
||||
boost::program_options::options_description description ("Command line options");
|
||||
rai::add_node_options (description);
|
||||
description.add_options ()
|
||||
("account_base58", boost::program_options::value <std::string> (), "Get base58 account number for the <key>")
|
||||
("account_key", "Get the public key for the <account>")
|
||||
("help", "Print out options")
|
||||
("daemon", "Start node daemon")
|
||||
("key_create", "Generates a random keypair")
|
||||
("key_expand", "Derive public key and account number from <key>")
|
||||
("wallet_add", "Insert <key> in to <wallet>")
|
||||
("wallet_list", "Dumps wallet IDs and public keys")
|
||||
("wallet_remove", "Remove <account> from <wallet>")
|
||||
("wallet_representative_get", "Prints default representative for <wallet>")
|
||||
("wallet_representative_set", "Set <account> as default representative for <wallet>")
|
||||
("account", boost::program_options::value <std::string> (), "Defines <account> for other commands, base58")
|
||||
("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")
|
||||
("debug_bootstrap_generate", "Generate bootstrap sequence of blocks")
|
||||
("debug_mass_activity", "Generates fake debug activity")
|
||||
("debug_profile_generate", "Profile work generation")
|
||||
("debug_profile_verify", "Profile work verification")
|
||||
("debug_profile_kdf", "Profile kdf function")
|
||||
("debug_verify_profile", "Profile signature verification")
|
||||
("debug_xorshift_profile", "Profile xorshift algorithms")
|
||||
("help", "Print out options");
|
||||
("debug_xorshift_profile", "Profile xorshift algorithms");
|
||||
boost::program_options::variables_map vm;
|
||||
boost::program_options::store (boost::program_options::parse_command_line(argc, argv, description), vm);
|
||||
boost::program_options::notify (vm);
|
||||
int result (0);
|
||||
if (vm.count ("account_base58") > 0)
|
||||
{
|
||||
if (vm.count ("key") == 1)
|
||||
{
|
||||
rai::uint256_union pub;
|
||||
pub.decode_hex (vm ["key"].as <std::string> ());
|
||||
std::cout << "Account: " << pub.to_base58check () << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "account_base58 comand requires one <key> option";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("account_key") > 0)
|
||||
if (!rai::handle_node_options (vm))
|
||||
{
|
||||
if (vm.count ("account") == 1)
|
||||
{
|
||||
rai::uint256_union account;
|
||||
account.decode_base58check (vm ["account"].as <std::string> ());
|
||||
std::cout << "Hex: " << account.to_string () << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "account_key command requires one <account> option";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("daemon") > 0)
|
||||
{
|
||||
rai_daemon::daemon daemon;
|
||||
daemon.run ();
|
||||
}
|
||||
else if (vm.count ("key_create"))
|
||||
{
|
||||
rai::keypair pair;
|
||||
std::cout << "Private: " << pair.prv.to_string () << std::endl << "Public: " << pair.pub.to_string () << std::endl << "Account: " << pair.pub.to_base58check () << std::endl;
|
||||
}
|
||||
else if (vm.count ("key_expand"))
|
||||
{
|
||||
if (vm.count ("key") == 1)
|
||||
{
|
||||
rai::uint256_union prv;
|
||||
prv.decode_hex (vm ["key"].as <std::string> ());
|
||||
rai::uint256_union pub;
|
||||
ed25519_publickey (prv.bytes.data (), pub.bytes.data ());
|
||||
std::cout << "Private: " << prv.to_string () << std::endl << "Public: " << pub.to_string () << std::endl << "Account: " << pub.to_base58check () << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "key_expand command requires one <key> option";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_add"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1 && vm.count ("key") == 1)
|
||||
{
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
std::string password;
|
||||
if (vm.count ("password") > 0)
|
||||
{
|
||||
password = vm ["password"].as <std::string> ();
|
||||
}
|
||||
inactive_node node;
|
||||
auto wallet (node.node->wallets.open (wallet_id));
|
||||
if (wallet != nullptr)
|
||||
{
|
||||
if (!wallet->enter_password (password))
|
||||
{
|
||||
rai::transaction transaction (wallet->store.environment, nullptr, true);
|
||||
wallet->store.insert (transaction, vm ["key"].as <std::string> ());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid password\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wallet doesn't exist\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid wallet id\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_add command requires one <wallet> option and one <key> option and optionally one <password> option";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_list"))
|
||||
{
|
||||
inactive_node node;
|
||||
for (auto i (node.node->wallets.items.begin ()), n (node.node->wallets.items.end ()); i != n; ++i)
|
||||
{
|
||||
std::cout << boost::str (boost::format ("Wallet ID: %1%\n") % i->first.to_string ());
|
||||
rai::transaction transaction (i->second->store.environment, nullptr, false);
|
||||
for (auto j (i->second->store.begin (transaction)), m (i->second->store.end ()); j != m; ++j)
|
||||
{
|
||||
std::cout << rai::uint256_union (j->first).to_base58check () << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_remove"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1 && vm.count ("account") == 1)
|
||||
{
|
||||
inactive_node node;
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
auto wallet (node.node->wallets.items.find (wallet_id));
|
||||
if (wallet != node.node->wallets.items.end ())
|
||||
{
|
||||
rai::account account_id;
|
||||
if (!account_id.decode_base58check (vm ["account"].as <std::string> ()))
|
||||
{
|
||||
rai::transaction transaction (wallet->second->store.environment, nullptr, true);
|
||||
auto account (wallet->second->store.find (transaction, account_id));
|
||||
if (account != wallet->second->store.end ())
|
||||
{
|
||||
wallet->second->store.erase (transaction, account_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Account not found in wallet\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid account id\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wallet not found\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid wallet id\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_remove command requires one <wallet> and one <account> option\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_representative_get"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
inactive_node node;
|
||||
auto wallet (node.node->wallets.items.find (wallet_id));
|
||||
if (wallet != node.node->wallets.items.end ())
|
||||
{
|
||||
rai::transaction transaction (wallet->second->store.environment, nullptr, false);
|
||||
auto representative (wallet->second->store.representative (transaction));
|
||||
std::cout << boost::str (boost::format ("Representative: %1%\n") % representative.to_base58check ());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wallet not found\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid wallet id\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_representative_get requires one <wallet> option\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("wallet_representative_set"))
|
||||
{
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
if (vm.count ("account") == 1)
|
||||
{
|
||||
rai::uint256_union wallet_id;
|
||||
if (!wallet_id.decode_hex (vm ["wallet"].as <std::string> ()))
|
||||
{
|
||||
rai::account account;
|
||||
if (!account.decode_base58check (vm ["account"].as <std::string> ()))
|
||||
{
|
||||
inactive_node node;
|
||||
auto wallet (node.node->wallets.items.find (wallet_id));
|
||||
if (wallet != node.node->wallets.items.end ())
|
||||
{
|
||||
rai::transaction transaction (wallet->second->store.environment, nullptr, true);
|
||||
wallet->second->store.representative_set (transaction, account);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wallet not found\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid account\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Invalid wallet id\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_representative_set requires one <account> option\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "wallet_representative_set requires one <wallet> option\n";
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (vm.count ("debug_bootstrap_generate"))
|
||||
{
|
||||
if (vm.count ("key") == 1)
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <rai/icon.hpp>
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
|
@ -60,7 +62,7 @@ public:
|
|||
rai::node_config node;
|
||||
};
|
||||
|
||||
int main (int argc, char * const * argv)
|
||||
int run_wallet (int argc, char * const * argv)
|
||||
{
|
||||
auto working (rai::working_path ());
|
||||
boost::filesystem::create_directories (working);
|
||||
|
@ -70,6 +72,7 @@ int main (int argc, char * const * argv)
|
|||
std::ifstream config_file;
|
||||
config_file.open (config_path);
|
||||
auto uninitialized (true);
|
||||
int result (0);
|
||||
if (!config_file.fail ())
|
||||
{
|
||||
config = qt_wallet_config (config_error, config_file);
|
||||
|
@ -117,7 +120,6 @@ int main (int argc, char * const * argv)
|
|||
std::unique_ptr <rai_qt::wallet> gui (new rai_qt::wallet (application, *node, wallet, config.account));
|
||||
gui->client_window->show ();
|
||||
rai::thread_runner runner (*service, processor);
|
||||
int result;
|
||||
try
|
||||
{
|
||||
result = application.exec ();
|
||||
|
@ -128,7 +130,6 @@ int main (int argc, char * const * argv)
|
|||
assert (false);
|
||||
}
|
||||
runner.join ();
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -149,4 +150,28 @@ int main (int argc, char * const * argv)
|
|||
{
|
||||
std::cerr << "Error in config file\n";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main (int argc, char * const * argv)
|
||||
{
|
||||
boost::program_options::options_description description ("Command line options");
|
||||
description.add_options () ("help", "Print out options");
|
||||
rai::add_node_options (description);
|
||||
boost::program_options::variables_map vm;
|
||||
boost::program_options::store (boost::program_options::parse_command_line(argc, argv, description), vm);
|
||||
boost::program_options::notify (vm);
|
||||
int result (0);
|
||||
if (!rai::handle_node_options (vm))
|
||||
{
|
||||
}
|
||||
else if (vm.count ("help") != 0)
|
||||
{
|
||||
std::cout << description << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = run_wallet (argc, argv);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue