From b05914bd652fb1d723ddac1f657acac84728860c Mon Sep 17 00:00:00 2001 From: Holger Nahrstaedt Date: Sun, 10 May 2020 23:54:46 +0200 Subject: [PATCH] Allow to load keys from file in beempy --- CHANGELOG.rst | 6 +++++- beem/cli.py | 31 +++++++++++++++++++++++++++---- beem/version.py | 2 +- beem/wallet.py | 2 +- beemapi/version.py | 2 +- beembase/version.py | 2 +- beemgraphenebase/version.py | 2 +- docs/cli.rst | 19 +++++++++++++++++++ setup.py | 2 +- 9 files changed, 57 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5eb34561..6dd40c71 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,9 +1,13 @@ Changelog ========= +0.23.6 +------ +* beempy --key key_list.json command can be used to set keys in beempy without using the wallet. + 0.23.5 ------ * Add missing diff_match_patch to requirements -* beempy download with providing a permlink will download all posts +* beempy download without providing a permlink will download all posts * Improve Yaml parsing 0.23.4 diff --git a/beem/cli.py b/beem/cli.py index 317e3970..073d5bf5 100644 --- a/beem/cli.py +++ b/beem/cli.py @@ -109,6 +109,8 @@ def unlock_wallet(stm, password=None, allow_wif=True): return True if not stm.wallet.locked(): return True + if len(stm.wallet.keys) > 0: + return True password_storage = stm.config["password_storage"] if not password and KEYRING_AVAILABLE and password_storage == "keyring": password = keyring.get_password("beem", "wallet") @@ -182,6 +184,8 @@ def node_answer_time(node): '--steem', '-s', is_flag=True, default=False, help="Connect to the Steem blockchain") @click.option( '--hive', '-h', is_flag=True, default=False, help="Connect to the Hive blockchain") +@click.option( + '--keys', '-k', help="JSON file that contains account keys, when set, the wallet cannot be used.") @click.option( '--token', '-t', is_flag=True, default=False, help="Uses a hivesigner/steemconnect token to broadcast (only broadcast operation with posting permission)") @click.option( @@ -190,7 +194,7 @@ def node_answer_time(node): @click.option( '--verbose', '-v', default=3, help='Verbosity') @click.version_option(version=__version__) -def cli(node, offline, no_broadcast, no_wallet, unsigned, create_link, steem, hive, token, expires, verbose): +def cli(node, offline, no_broadcast, no_wallet, unsigned, create_link, steem, hive, keys, token, expires, verbose): # Logging log = logging.getLogger(__name__) @@ -203,7 +207,24 @@ def cli(node, offline, no_broadcast, no_wallet, unsigned, create_link, steem, hi ch.setLevel(getattr(logging, verbosity.upper())) ch.setFormatter(formatter) log.addHandler(ch) - + + keys_list = [] + autoconnect = False + if keys and keys != "": + if not os.path.isfile(keys): + raise Exception("File %s does not exist!" % keys) + with open(keys) as fp: + keyfile = fp.read() + if keyfile.find('\0') > 0: + with open(keys, encoding='utf-16') as fp: + keyfile = fp.read() + keyfile = ast.literal_eval(keyfile) + for account in keyfile: + for role in ["owner", "active", "posting", "memo"]: + if role in keyfile[account]: + keys_list.append(keyfile[account][role]) + if len(keys_list) > 0: + autoconnect = True if create_link: no_broadcast = True unsigned = True @@ -218,6 +239,7 @@ def cli(node, offline, no_broadcast, no_wallet, unsigned, create_link, steem, hi stm = Hive( node=node, nobroadcast=no_broadcast, + keys=keys_list, offline=offline, nowallet=no_wallet, unsigned=unsigned, @@ -228,13 +250,14 @@ def cli(node, offline, no_broadcast, no_wallet, unsigned, create_link, steem, hi num_retries=10, num_retries_call=3, timeout=15, - autoconnect=False + autoconnect=autoconnect ) else: stm = Steem( node=node, nobroadcast=no_broadcast, offline=offline, + keys=keys_list, nowallet=no_wallet, unsigned=unsigned, use_sc2=token, @@ -244,7 +267,7 @@ def cli(node, offline, no_broadcast, no_wallet, unsigned, create_link, steem, hi num_retries=10, num_retries_call=3, timeout=15, - autoconnect=False + autoconnect=autoconnect ) set_shared_blockchain_instance(stm) diff --git a/beem/version.py b/beem/version.py index aeb337e6..0ffc4113 100644 --- a/beem/version.py +++ b/beem/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.23.5' +version = '0.23.6' diff --git a/beem/wallet.py b/beem/wallet.py index f82a9d8b..2fa65481 100644 --- a/beem/wallet.py +++ b/beem/wallet.py @@ -124,7 +124,7 @@ def __init__(self, blockchain_instance=None, *args, **kwargs): if "wif" in kwargs and "keys" not in kwargs: kwargs["keys"] = kwargs["wif"] master_password_set = False - if "keys" in kwargs: + if "keys" in kwargs and len(kwargs["keys"]) > 0: self.setKeys(kwargs["keys"]) else: """ If no keys are provided manually we load the SQLite diff --git a/beemapi/version.py b/beemapi/version.py index aeb337e6..0ffc4113 100644 --- a/beemapi/version.py +++ b/beemapi/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.23.5' +version = '0.23.6' diff --git a/beembase/version.py b/beembase/version.py index aeb337e6..0ffc4113 100644 --- a/beembase/version.py +++ b/beembase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.23.5' +version = '0.23.6' diff --git a/beemgraphenebase/version.py b/beemgraphenebase/version.py index aeb337e6..0ffc4113 100644 --- a/beemgraphenebase/version.py +++ b/beemgraphenebase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.23.5' +version = '0.23.6' diff --git a/docs/cli.rst b/docs/cli.rst index a1dc6ad5..58f54639 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -26,6 +26,25 @@ To bypass password entry, you can set an environment variable ``UNLOCK``. UNLOCK=mysecretpassword beempy transfer 100 STEEM +Using a key json file +--------------------- + +A key_file.json can be used to provide private keys to beempy: +:: + + { + "account_a": {"posting": "5xx", "active": "5xx"}, + "account_b": {"posting": "5xx"], + } + +with + +:: + + beempy --key key_file.json command + +When set, the wallet cannot be used. + Common Commands --------------- First, you may like to import your Steem account: diff --git a/setup.py b/setup.py index 6585cfe3..a80cdcf2 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ ascii = codecs.lookup('ascii') codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs')) -VERSION = '0.23.5' +VERSION = '0.23.6' tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']