diff --git a/jmclient/jmclient/wallet_utils.py b/jmclient/jmclient/wallet_utils.py index d175c76..649541f 100644 --- a/jmclient/jmclient/wallet_utils.py +++ b/jmclient/jmclient/wallet_utils.py @@ -1368,8 +1368,7 @@ def open_test_wallet_maybe(path, seed, max_mixdepth, return test_wallet_cls(storage, **kwargs) if wallet_password_stdin is True: - stdin = sys.stdin.read() - password = stdin.encode('utf-8') + password = read_password_stdin() return open_wallet(path, ask_for_password=False, password=password, mixdepth=max_mixdepth, **kwargs) return open_wallet(path, mixdepth=max_mixdepth, **kwargs) @@ -1444,6 +1443,10 @@ def get_wallet_path(file_name, wallet_dir=None): return os.path.join(wallet_dir, file_name) +def read_password_stdin(): + return sys.stdin.read().encode('utf-8') + + def wallet_tool_main(wallet_root_path): """Main wallet tool script function; returned is a string (output or error) """ diff --git a/scripts/genwallet.py b/scripts/genwallet.py index ebdf584..c1d760c 100755 --- a/scripts/genwallet.py +++ b/scripts/genwallet.py @@ -3,7 +3,6 @@ # A script for noninteractively creating wallets. # The implementation is similar to wallet_generate_recover_bip39 in jmclient/wallet_utils.py -import sys import os from optparse import OptionParser from jmclient import ( @@ -23,7 +22,7 @@ def main(): (options, args) = parser.parse_args() wallet_name = args[0] if options.wallet_password_stdin: - password = sys.stdin.read().encode("utf-8") + password = wallet_utils.read_password_stdin() else: assert len(args) > 1, "must provide password via stdin (see --help), or as second argument." password = args[1].encode("utf-8")