Skip to content

Commit

Permalink
Added option to write password returned by "wallet create" to a file.…
Browse files Browse the repository at this point in the history
… GH EOSIO#4554
  • Loading branch information
brianjohnson5972 committed Jul 23, 2018
1 parent 1463d49 commit 7a9b2d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2251,14 +2251,29 @@ int main( int argc, char** argv ) {
wallet->require_subcommand();
// create wallet
string wallet_name = "default";
string password_file;
bool print_console = false;
auto createWallet = wallet->add_subcommand("create", localized("Create a new wallet locally"), false);
createWallet->add_option("-n,--name", wallet_name, localized("The name of the new wallet"), true);
createWallet->set_callback([&wallet_name] {
createWallet->add_option("-f,--file", password_file, localized("Name of file to write wallet password output to. (Must be set, unless \"--console\" is passed"));
createWallet->add_flag( "--to-console", print_console, localized("Print password to console."));
createWallet->set_callback([&wallet_name, &password_file, &print_console] {
if (password_file.empty() && !print_console) {
std::cerr << "ERROR: Either indicate a file using \"--file\" or pass \"--console\"" << std::endl;
return;
}

const auto& v = call(wallet_url, wallet_create, wallet_name);
std::cout << localized("Creating wallet: ${wallet_name}", ("wallet_name", wallet_name)) << std::endl;
std::cout << localized("Save password to use in the future to unlock this wallet.") << std::endl;
std::cout << localized("Without password imported keys will not be retrievable.") << std::endl;
std::cout << fc::json::to_pretty_string(v) << std::endl;
if (print_console) {
std::cout << fc::json::to_pretty_string(v) << std::endl;
} else {
std::cerr << localized("saving password to ${filename}", ("filename", password_file)) << std::endl;
std::ofstream out( password_file.c_str() );
out << fc::json::to_pretty_string(v);
}
});

// open wallet
Expand Down
2 changes: 1 addition & 1 deletion tests/WalletMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create(self, name, accounts=None):
if Utils.Debug: Utils.Print("Wallet \"%s\" already exists. Returning same." % name)
return wallet
p = re.compile(r'\n\"(\w+)\"\n', re.MULTILINE)
cmd="%s %s wallet create --name %s" % (Utils.EosClientPath, self.endpointArgs, name)
cmd="%s %s wallet create --name %s --to-console" % (Utils.EosClientPath, self.endpointArgs, name)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
retStr=Utils.checkOutput(cmd.split())
#Utils.Print("create: %s" % (retStr))
Expand Down

0 comments on commit 7a9b2d9

Please sign in to comment.