Skip to content

Commit f823329

Browse files
authored
simplewallet: add option to enable usage inside shell script (#33)
2 parents a39cc81 + daf696b commit f823329

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,5 @@ cmake-build-debug/
9191
__pycache__/
9292
*.pyc
9393
*.log
94+
95+
builder/output/

src/simplewallet/simplewallet.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace
157157
const command_line::arg_descriptor<bool> arg_long_payment_id_support = {"long-payment-id-support", sw::tr("Support obsolete long (unencrypted) payment ids (using them harms your privacy)"), false};
158158

159159
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
160+
const command_line::arg_descriptor<bool> arg_non_interactive = {"non-interactive", sw::tr("run the command in non interactive mode"), false};
160161

161162
const char* USAGE_START_MINING("start_mining [<number_of_threads>] [bg_mining] [ignore_battery]");
162163
const char* USAGE_SET_DONATE_LEVEL("donate_level [<number_of_blocks>]");
@@ -3624,6 +3625,11 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
36243625

36253626
bool welcome = false;
36263627

3628+
if (m_non_interactive && command_line::is_arg_defaulted(vm, arg_command)) {
3629+
fail_msg_writer() << tr("Cannot specify non interactive mode when there is no command given");
3630+
return false;
3631+
}
3632+
36273633
if((!m_generate_new.empty()) + (!m_wallet_file.empty()) + (!m_generate_from_device.empty()) + (!m_generate_from_view_key.empty()) + (!m_generate_from_spend_key.empty()) + (!m_generate_from_keys.empty()) + (!m_generate_from_multisig_keys.empty()) + (!m_generate_from_json.empty()) > 1)
36283634
{
36293635
fail_msg_writer() << tr("can't specify more than one of --generate-new-wallet=\"wallet_name\", --wallet-file=\"wallet_name\", --generate-from-view-key=\"wallet_name\", --generate-from-spend-key=\"wallet_name\", --generate-from-keys=\"wallet_name\", --generate-from-multisig-keys=\"wallet_name\", --generate-from-json=\"jsonfilename\" and --generate-from-device=\"wallet_name\"");
@@ -4270,6 +4276,7 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
42704276
!m_generate_from_device.empty() ||
42714277
m_restore_deterministic_wallet ||
42724278
m_restore_multisig_wallet;
4279+
m_non_interactive = command_line::get_arg(vm, arg_non_interactive);
42734280

42744281
if (!command_line::is_arg_defaulted(vm, arg_restore_date))
42754282
{
@@ -4367,7 +4374,7 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
43674374
const crypto::secret_key& recovery_key, bool recover, bool two_random, const std::string &old_language)
43684375
{
43694376
std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> rc;
4370-
try { rc = tools::wallet2::make_new(vm, false, password_prompter); }
4377+
try { rc = tools::wallet2::make_new(vm, m_non_interactive, password_prompter); }
43714378
catch(const std::exception &e) { fail_msg_writer() << tr("Error creating wallet: ") << e.what(); return {}; }
43724379
m_wallet = std::move(rc.first);
43734380
if (!m_wallet)
@@ -4464,7 +4471,7 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
44644471
const crypto::secret_key& viewkey)
44654472
{
44664473
std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> rc;
4467-
try { rc = tools::wallet2::make_new(vm, false, password_prompter); }
4474+
try { rc = tools::wallet2::make_new(vm, m_non_interactive, password_prompter); }
44684475
catch(const std::exception &e) { fail_msg_writer() << tr("Error creating wallet: ") << e.what(); return {}; }
44694476
m_wallet = std::move(rc.first);
44704477
if (!m_wallet)
@@ -4512,7 +4519,7 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
45124519
boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::program_options::variables_map& vm)
45134520
{
45144521
std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> rc;
4515-
try { rc = tools::wallet2::make_new(vm, false, password_prompter); }
4522+
try { rc = tools::wallet2::make_new(vm, m_non_interactive, password_prompter); }
45164523
catch(const std::exception &e) { fail_msg_writer() << tr("Error creating wallet: ") << e.what(); return {}; }
45174524
m_wallet = std::move(rc.first);
45184525
m_wallet->callback(this);
@@ -4555,7 +4562,7 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
45554562
const epee::wipeable_string &multisig_keys, const std::string &old_language)
45564563
{
45574564
std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> rc;
4558-
try { rc = tools::wallet2::make_new(vm, false, password_prompter); }
4565+
try { rc = tools::wallet2::make_new(vm, m_non_interactive, password_prompter); }
45594566
catch(const std::exception &e) { fail_msg_writer() << tr("Error creating wallet: ") << e.what(); return {}; }
45604567
m_wallet = std::move(rc.first);
45614568
if (!m_wallet)
@@ -9578,6 +9585,7 @@ int main(int argc, char* argv[])
95789585
command_line::add_arg(desc_params, arg_generate_from_json);
95799586
command_line::add_arg(desc_params, arg_mnemonic_language);
95809587
command_line::add_arg(desc_params, arg_command);
9588+
command_line::add_arg(desc_params, arg_non_interactive);
95819589

95829590
command_line::add_arg(desc_params, arg_restore_deterministic_wallet );
95839591
command_line::add_arg(desc_params, arg_restore_from_seed );

src/simplewallet/simplewallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ namespace cryptonote
415415
uint64_t m_restore_height; // optional
416416
bool m_do_not_relay;
417417
bool m_use_english_language_names;
418+
bool m_non_interactive; // is the cli started under a shell script?
418419

419420
epee::console_handlers_binder m_cmd_binder;
420421

0 commit comments

Comments
 (0)