From 994acf0106a5b3ad14ae1d74972a34c0a595b3eb Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Sun, 1 Jul 2018 10:03:04 +0300 Subject: [PATCH] fixed issue #1050 - added exit_wallet method --- .../wallet/include/graphene/wallet/wallet.hpp | 7 +++++ libraries/wallet/wallet.cpp | 14 ++++++++++ tests/cli/main.cpp | 27 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 85b069c900..fe4540115d 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -632,6 +632,12 @@ class wallet_api */ bool load_wallet_file(string wallet_filename = ""); + /** Exits from Graphene wallet. + * + * The current wallet will be closed. + */ + void exit_wallet(); + /** Saves the current wallet to the given filename. * * @warning This does not change the wallet filename that will be used for future @@ -1815,4 +1821,5 @@ FC_API( graphene::wallet::wallet_api, (blind_history) (receive_blind_transfer) (get_order_book) + (exit_wallet) ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 1347a26e8f..8c71fe8abd 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -770,6 +770,15 @@ class wallet_api_impl return true; } + + void exit_wallet() + { + ilog( "exiting wallet ..." ); + save_wallet_file(); + ilog( "closed wallet successfully" ); + exit(0); + } + void save_wallet_file(string wallet_filename = "") { // @@ -3762,6 +3771,11 @@ bool wallet_api::load_wallet_file( string wallet_filename ) return my->load_wallet_file( wallet_filename ); } +void wallet_api::exit_wallet() +{ + my->exit_wallet(); +} + void wallet_api::save_wallet_file( string wallet_filename ) { my->save_wallet_file( wallet_filename ); diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 53f702aea1..2c541f609f 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -388,3 +388,30 @@ BOOST_AUTO_TEST_CASE( cli_set_voting_proxy ) } app1->shutdown(); } + +/////////////// +// Start a server and connect using the same calls as the CLI +// Testing exit_wallet method +//////////////// +BOOST_AUTO_TEST_CASE( cli_exit ) +{ + using namespace graphene::chain; + using namespace graphene::app; + std::shared_ptr app1; + try { + BOOST_TEST_MESSAGE("Connecting and exiting wallet test."); + fc::temp_directory app_dir ( graphene::utilities::temp_directory_path() ); + + int server_port_number = 0; + app1 = start_application(app_dir, server_port_number); + + // connect to the server + client_connection con(app1, app_dir, server_port_number); + + con.wallet_api_ptr->exit_wallet(); + } catch( fc::exception& e ) { + edump((e.to_detail_string())); + throw; + } + app1->shutdown(); +} \ No newline at end of file