Skip to content

Commit

Permalink
fixed issue #1050
Browse files Browse the repository at this point in the history
  • Loading branch information
nanomobile committed Jul 10, 2018
1 parent 7fb2c86 commit da4fec3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libraries/wallet/include/graphene/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,16 @@ class wallet_api
*/
bool load_wallet_file(string wallet_filename = "");

/** Exits from BitShares wallet.
*
* @param wallet_filename the filename of the wallet JSON file to load.
* If \c wallet_filename is empty, it reloads the
* existing wallet file
*
* The current wallet will be closed.
*/
void quit();

/** Saves the current wallet to the given filename.
*
* @warning This does not change the wallet filename that will be used for future
Expand Down Expand Up @@ -1815,4 +1825,5 @@ FC_API( graphene::wallet::wallet_api,
(blind_history)
(receive_blind_transfer)
(get_order_book)
(quit)
)
19 changes: 19 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,20 @@ class wallet_api_impl

return true;
}

void quit()
{
ilog( "Exiting Wallet ..." );

try {
save_wallet_file();
} catch (...) {
FC_THROW("Got error while saving wallet file in quit command.");
}

exit(0);
}

void save_wallet_file(string wallet_filename = "")
{
//
Expand Down Expand Up @@ -3762,6 +3776,11 @@ bool wallet_api::load_wallet_file( string wallet_filename )
return my->load_wallet_file( wallet_filename );
}

void wallet_api::quit()
{
my->quit();
}

void wallet_api::save_wallet_file( string wallet_filename )
{
my->save_wallet_file( wallet_filename );
Expand Down
28 changes: 28 additions & 0 deletions tests/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,31 @@ BOOST_AUTO_TEST_CASE( cli_set_voting_proxy )
}
app1->shutdown();
}

////////////////
// Start a server and connect using the same calls as the CLI
// Quit wallet and be sure that file was saved correctly
////////////////
BOOST_AUTO_TEST_CASE( cli_quit )
{
using namespace graphene::chain;
using namespace graphene::app;
std::shared_ptr<graphene::app::application> app1;
try {
BOOST_TEST_MESSAGE("Testing wallet connection and quit command.");

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);

BOOST_CHECK_NO_THROW( con.wallet_api_ptr->quit() );
} catch( fc::exception& e ) {
edump((e.to_detail_string()));
throw;
}
app1->shutdown();
}

0 comments on commit da4fec3

Please sign in to comment.