From b83e27c3916038634ceea36cdefd790c4719e494 Mon Sep 17 00:00:00 2001 From: cindiv Date: Thu, 31 Oct 2019 20:00:20 +0000 Subject: [PATCH] Add --wallet-password-stdin Related: Issue #409 --- jmclient/jmclient/wallet_utils.py | 16 ++++++++++++++-- jmclient/jmclient/yieldgenerator.py | 6 ++++++ scripts/cli_options.py | 5 +++++ scripts/receive-payjoin.py | 7 +++++++ scripts/sendpayment.py | 4 +++- scripts/tumbler.py | 2 +- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/jmclient/jmclient/wallet_utils.py b/jmclient/jmclient/wallet_utils.py index cccd069..ecc9376 100644 --- a/jmclient/jmclient/wallet_utils.py +++ b/jmclient/jmclient/wallet_utils.py @@ -101,6 +101,13 @@ def get_wallettool_parser(): "if your address starts with '3' use 'segwit-p2sh.\n" "Native segwit addresses (starting with 'bc') are" "not yet supported.")) + parser.add_option('--wallet-password-stdin', + action='store_true', + default=False, + dest='wallet_password_stdin', + help='Read wallet password from stdin') + + return parser @@ -1072,7 +1079,7 @@ def create_wallet(path, password, max_mixdepth, wallet_cls=None, **kwargs): def open_test_wallet_maybe(path, seed, max_mixdepth, - test_wallet_cls=SegwitLegacyWallet, **kwargs): + test_wallet_cls=SegwitLegacyWallet, wallet_password_stdin=False, **kwargs): """ Create a volatile test wallet if path is a hex-encoded string of length 64, otherwise run open_wallet(). @@ -1114,6 +1121,11 @@ def open_test_wallet_maybe(path, seed, max_mixdepth, del kwargs['read_only'] return test_wallet_cls(storage, **kwargs) + if wallet_password_stdin is True: + stdin = sys.stdin.read() + password = stdin.encode('utf-8') + return open_wallet(path, ask_for_password=False, password=password, mixdepth=max_mixdepth, **kwargs) + return open_wallet(path, mixdepth=max_mixdepth, **kwargs) @@ -1220,7 +1232,7 @@ def wallet_tool_main(wallet_root_path): wallet = open_test_wallet_maybe( wallet_path, seed, options.mixdepth, read_only=read_only, - gap_limit=options.gaplimit) + wallet_password_stdin=options.wallet_password_stdin, gap_limit=options.gaplimit) # this object is only to respect the layering, # the service will not be started since this is a synchronous script: diff --git a/jmclient/jmclient/yieldgenerator.py b/jmclient/jmclient/yieldgenerator.py index 5b2d05e..019cc92 100644 --- a/jmclient/jmclient/yieldgenerator.py +++ b/jmclient/jmclient/yieldgenerator.py @@ -220,6 +220,11 @@ def ygmain(ygclass, txfee=1000, cjfee_a=200, cjfee_r=0.002, ordertype='swreloffe parser.add_option('-m', '--mixdepth', action='store', type='int', dest='mixdepth', default=None, help="highest mixdepth to use") + parser.add_option('--wallet-password-stdin', + action='store_true', + default=False, + dest='wallet_password_stdin', + help='Read wallet password from stdin') (options, args) = parser.parse_args() if len(args) < 1: parser.error('Needs a wallet') @@ -248,6 +253,7 @@ def ygmain(ygclass, txfee=1000, cjfee_a=200, cjfee_r=0.002, ordertype='swreloffe wallet_path = get_wallet_path(wallet_name, 'wallets') wallet = open_test_wallet_maybe( wallet_path, wallet_name, options.mixdepth, + wallet_password_stdin=options.wallet_password_stdin, gap_limit=options.gaplimit) wallet_service = WalletService(wallet) diff --git a/scripts/cli_options.py b/scripts/cli_options.py index 3adad11..aa8b1ee 100644 --- a/scripts/cli_options.py +++ b/scripts/cli_options.py @@ -72,6 +72,11 @@ def add_common_options(parser): .format('random_under_max_order_choose', ', '.join(order_choose_algorithms.keys())), dest='order_choose_fn') + parser.add_option('--wallet-password-stdin', + action='store_true', + default=False, + dest='wallet_password_stdin', + help='Read wallet password from stdin') add_order_choose_short_options(parser) diff --git a/scripts/receive-payjoin.py b/scripts/receive-payjoin.py index 7eba1c6..e5006f1 100644 --- a/scripts/receive-payjoin.py +++ b/scripts/receive-payjoin.py @@ -36,6 +36,12 @@ def receive_payjoin_main(makerclass): dest='amtmixdepths', help='number of mixdepths in wallet, default 5', default=5) + parser.add_option('--wallet-password-stdin', + action='store_true', + default=False, + dest='wallet_password_stdin', + help='Read wallet password from stdin') + (options, args) = parser.parse_args() if len(args) < 2: parser.error('Needs a wallet, and a receiving amount in satoshis') @@ -62,6 +68,7 @@ def receive_payjoin_main(makerclass): max_mix_depth = max([options.mixdepth, options.amtmixdepths - 1]) wallet = open_test_wallet_maybe( wallet_path, wallet_name, max_mix_depth, + wallet_password_stdin=options.wallet_password_stdin, gap_limit=options.gaplimit) if jm_single().config.get("BLOCKCHAIN", "blockchain_source") == "electrum-server": diff --git a/scripts/sendpayment.py b/scripts/sendpayment.py index bd5502b..3f5eb87 100644 --- a/scripts/sendpayment.py +++ b/scripts/sendpayment.py @@ -131,7 +131,9 @@ def main(): wallet_path = get_wallet_path(wallet_name, None) wallet = open_test_wallet_maybe( - wallet_path, wallet_name, max_mix_depth, gap_limit=options.gaplimit) + wallet_path, wallet_name, max_mix_depth, + wallet_password_stdin=options.wallet_password_stdin, + gap_limit=options.gaplimit) wallet_service = WalletService(wallet) # in this script, we need the wallet synced before # logic processing for some paths, so do it now: diff --git a/scripts/tumbler.py b/scripts/tumbler.py index f0604bb..be2b191 100644 --- a/scripts/tumbler.py +++ b/scripts/tumbler.py @@ -41,7 +41,7 @@ def main(): if options['amtmixdepths'] > max_mix_depth: max_mix_depth = options['amtmixdepths'] wallet_path = get_wallet_path(wallet_name, None) - wallet = open_test_wallet_maybe(wallet_path, wallet_name, max_mix_depth) + wallet = open_test_wallet_maybe(wallet_path, wallet_name, max_mix_depth, wallet_password_stdin=options_org.wallet_password_stdin) wallet_service = WalletService(wallet) # in this script, we need the wallet synced before # logic processing for some paths, so do it now: