Skip to content

Commit

Permalink
Add quit command to cli_wallet steemit#484
Browse files Browse the repository at this point in the history
  • Loading branch information
zxcat committed Apr 6, 2018
1 parent 6d30ebb commit 18d5359
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions libraries/wallet/include/golos/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ namespace golos { namespace wallet {
*/
void save_wallet_file(string wallet_filename = "");

/**
* Quits wallet.
*/
void quit();

/** Sets the wallet filename used for future writes.
*
* This does not trigger a save, it only changes the default filename
Expand Down Expand Up @@ -916,6 +921,7 @@ namespace golos { namespace wallet {
std::map<string,std::function<string(fc::variant,const fc::variants&)>> get_result_formatters() const;

fc::signal<void(bool)> lock_changed;
fc::signal<void(void)> quit_command;
std::shared_ptr<detail::wallet_api_impl> my;
void encrypt_keys();

Expand Down Expand Up @@ -970,6 +976,7 @@ FC_API( golos::wallet::wallet_api,
(help)(gethelp)
(about)(is_new)(is_locked)(lock)(unlock)(set_password)
(load_wallet_file)(save_wallet_file)
(quit)

/// key api
(import_key)
Expand Down
4 changes: 4 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,10 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
my->encrypt_keys();
}

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

void wallet_api::lock() {
try {
FC_ASSERT( !is_locked() );
Expand Down
13 changes: 8 additions & 5 deletions programs/cli_wallet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ using namespace std;
void daemon_mode();

void non_daemon_mode(
const bpo::variables_map& options,
const vector<string>& commands,
const bool interactive,
std::shared_ptr<fc::rpc::cli> wallet_cli,
Expand Down Expand Up @@ -182,9 +181,13 @@ int unsafe_main(int argc, char** argv) {
cerr << "Server has disconnected us.\n";
wallet_cli->stop();
}));
(void)(closed_connection);

if( wapiptr->is_new() ) {
boost::signals2::scoped_connection quit_connection(wapiptr->quit_command.connect([=]{
cout << "Bye.\n";
wallet_cli->stop();
}));

if (wapiptr->is_new()) {
cout << "Please use the set_password method to initialize a new wallet before continuing\n";
wallet_cli->set_prompt( "new >>> " );
} else
Expand Down Expand Up @@ -257,18 +260,18 @@ int unsafe_main(int argc, char** argv) {
if (options.count("daemon")) {
daemon_mode();
} else {
non_daemon_mode(options, commands, interactive, wallet_cli, wapi);
non_daemon_mode(commands, interactive, wallet_cli, wapi);
}

wapi->save_wallet_file(wallet_file.generic_string());
locked_connection.disconnect();
quit_connection.disconnect();
closed_connection.disconnect();

return 0;
}

void non_daemon_mode (
const bpo::variables_map& options,
const vector<string>& commands,
const bool interactive,
std::shared_ptr<fc::rpc::cli> wallet_cli,
Expand Down

0 comments on commit 18d5359

Please sign in to comment.