Skip to content

Commit

Permalink
Allow to load keys from file in beempy
Browse files Browse the repository at this point in the history
  • Loading branch information
holgern committed May 10, 2020
1 parent 00e891d commit b05914b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 27 additions & 4 deletions beem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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__)
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion beem/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.5'
version = '0.23.6'
2 changes: 1 addition & 1 deletion beem/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion beemapi/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.5'
version = '0.23.6'
2 changes: 1 addition & 1 deletion beembase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.5'
version = '0.23.6'
2 changes: 1 addition & 1 deletion beemgraphenebase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.5'
version = '0.23.6'
19 changes: 19 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ To bypass password entry, you can set an environment variable ``UNLOCK``.

UNLOCK=mysecretpassword beempy transfer <recipient_name> 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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down

0 comments on commit b05914b

Please sign in to comment.