Skip to content

Commit

Permalink
Add new beempy command customjson
Browse files Browse the repository at this point in the history
* with beempy customjson sending of custom_json operation is easily possible
* Changelog adapted to 0.20.19
  • Loading branch information
holgern committed Mar 1, 2019
1 parent 360f3e7 commit ec75681
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Changelog
=========
0.20.19
-------
* Fix pyinstaller for windows
* Improve derive_permlink and allow replies of comments with permlink lenght > 235
* Broadcast custom_json with active authority
* Add new beempy command customjson

0.20.18
-------
* get_blog, get_followers and get_following works with api.steemit.com (issue #146)
Expand Down
60 changes: 60 additions & 0 deletions beem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,66 @@ def claimreward(account, reward_steem, reward_sbd, reward_vests, claim_all_steem
print(tx)


@cli.command()
@click.argument('jsonid', nargs=1)
@click.argument('json_data', nargs=-1)
@click.option('--account', '-a', help='The account which broadcasts the custom_json')
@click.option('--active', '-t', help='When set, the active key is used for broadcasting', is_flag=True, default=False)
def customjson(jsonid, json_data, account, active):
"""Broadcasts a custom json
First parameter is the cusom json id, the second field is a json file or a json key value combination
e.g. beempy customjson -a holger80 dw-heist username holger80 amount 100
"""
if jsonid is None:
print("First argument must be the custom_json id")
if json_data is None:
print("Second argument must be the json_data, can be a string or a file name.")
if isinstance(json_data, tuple) and len(json_data) > 1:
data = {}
key = None
for j in json_data:
if key is None:
key = j
else:
data[key] = j
key = None
if key is not None:
print("Value is missing for key: %s" % key)
return
else:
try:
with open(json_data[0], 'r') as f:
data = json.load(f)
except:
print("%s is not a valid file or json field" % json_data)
return
for d in data:
if isinstance(data[d], str) and data[d][0] == "{" and data[d][-1] == "}":
field = {}
for keyvalue in data[d][1:-1].split(","):
key = keyvalue.split(":")[0].strip()
value = keyvalue.split(":")[1].strip()
if jsonid == "ssc-mainnet1" and key == "quantity":
value = float(value)
field[key] = value
data[d] = field
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
if not account:
account = stm.config["default_account"]
if not unlock_wallet(stm):
return
acc = Account(account, steem_instance=stm)
if active:
tx = stm.custom_json(jsonid, data, required_auths=[account])
else:
tx = stm.custom_json(jsonid, data, required_posting_auths=[account])
tx = json.dumps(tx, indent=4)
print(tx)


@cli.command()
@click.argument('blocknumber', nargs=1, required=False)
@click.option('--trx', '-t', help='Show only one transaction number', default=None)
Expand Down

0 comments on commit ec75681

Please sign in to comment.