Skip to content

Commit

Permalink
Release 0.20.12
Browse files Browse the repository at this point in the history
* pep8 formating improved
* Too Many Requests error handled
* different limit handling in WLS fixed for account history
* percent-steem-dollars and max-accepted-payout added to beempy post
  • Loading branch information
holgern committed Nov 15, 2018
1 parent 51b0322 commit 49a8db8
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 54 deletions.
43 changes: 21 additions & 22 deletions beem/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,10 @@ def total_balances(self):
symbols.append(balance["symbol"])
ret = []
for i in range(len(symbols)):
ret.append(self.get_balance(self.available_balances, symbols[i]) + self.get_balance(self.saving_balances, symbols[i]) +
self.get_balance(self.reward_balances, symbols[i]))
balance_sum = self.get_balance(self.available_balances, symbols[i])
balance_sum += self.get_balance(self.saving_balances, symbols[i])
balance_sum += self.get_balance(self.reward_balances, symbols[i])
ret.append(balance_sum)
return ret

@property
Expand Down Expand Up @@ -1449,6 +1451,8 @@ def _get_account_history(self, account=None, start=-1, limit=0):
ret = self.steem.rpc.get_account_history(account["name"], start, limit, api="condenser")
else:
ret = self.steem.rpc.get_account_history(account["name"], start, limit, api="database")
if len(ret) == 0 and limit == 0:
ret = self.steem.rpc.get_account_history(account["name"], start, limit + 1, api="database")
return ret

def estimate_virtual_op_num(self, blocktime, stop_diff=0, max_count=100):
Expand Down Expand Up @@ -1544,9 +1548,7 @@ def get_blocknum(index):
# linear approximation between the known upper and
# lower bounds for the first iteration
if cnt < 1:
op_num = int((target_blocknum - block_lower) /
(block_upper - block_lower) *
(op_upper - op_lower) + op_lower)
op_num = int((target_blocknum - block_lower) / (block_upper - block_lower) * (op_upper - op_lower) + op_lower)
else:
# divide and conquer for the following iterations
op_num = int((op_upper + op_lower) / 2)
Expand Down Expand Up @@ -2234,25 +2236,22 @@ def update_account_keys(self, new_password, account=None, **kwargs):
key_auths = {}
for role in ['owner', 'active', 'posting', 'memo']:
pk = PasswordKey(account['name'], new_password, role=role)
key_auths[role] = format(pk.get_public_key(), self.steem.prefix)
key_auths[role] = format(pk.get_public_key(), self.steem.prefix)

op = operations.Account_update(**{
"account": account["name"],
'owner': {
'account_auths': [],
'key_auths': [[key_auths['owner'], 1]],
"address_auths": [],
'weight_threshold': 1},
'active': {
'account_auths': [],
'key_auths': [[key_auths['active'], 1]],
"address_auths": [],
'weight_threshold': 1},
'posting': {
'account_auths': account['posting']['account_auths'],
'key_auths': [[key_auths['posting'], 1]],
"address_auths": [],
'weight_threshold': 1},
'owner': {'account_auths': [],
'key_auths': [[key_auths['owner'], 1]],
"address_auths": [],
'weight_threshold': 1},
'active': {'account_auths': [],
'key_auths': [[key_auths['active'], 1]],
"address_auths": [],
'weight_threshold': 1},
'posting': {'account_auths': account['posting']['account_auths'],
'key_auths': [[key_auths['posting'], 1]],
"address_auths": [],
'weight_threshold': 1},
'memo_key': key_auths['memo'],
"json_metadata": account['json_metadata'],
"prefix": self.steem.prefix,
Expand Down Expand Up @@ -2527,7 +2526,7 @@ def claim_reward_balance(self,
"reward_sbd": reward_sbd,
"reward_vests": reward_vests,
"prefix": self.steem.prefix,
})
})
else:
reward_steem = account.balances["rewards"][0]
reward_vests = account.balances["rewards"][1]
Expand Down
10 changes: 2 additions & 8 deletions beem/amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,12 @@ def __init__(self, amount, asset=None, new_appbase_format=True, steem_instance=N
self["amount"], self["symbol"] = amount.split(" ")
self["asset"] = Asset(self["symbol"], steem_instance=self.steem)

elif (amount and asset is None and
isinstance(amount, dict) and
"amount" in amount and
"asset_id" in amount):
elif (amount and asset is None and isinstance(amount, dict) and "amount" in amount and "asset_id" in amount):
self["asset"] = Asset(amount["asset_id"], steem_instance=self.steem)
self["symbol"] = self["asset"]["symbol"]
self["amount"] = int(amount["amount"]) / 10 ** self["asset"]["precision"]

elif (amount and asset is None and
isinstance(amount, dict) and
"amount" in amount and
"asset" in amount):
elif (amount and asset is None and isinstance(amount, dict) and "amount" in amount and "asset" in amount):
self["asset"] = Asset(amount["asset"], steem_instance=self.steem)
self["symbol"] = self["asset"]["symbol"]
self["amount"] = int(amount["amount"]) / 10 ** self["asset"]["precision"]
Expand Down
43 changes: 35 additions & 8 deletions beem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,8 +1520,10 @@ def beneficiaries(authorperm, beneficiaries):
@click.option('--reply_identifier', help=' Identifier of the parent post/comment, when set a comment is broadcasted')
@click.option('--community', help=' Name of the community (optional)')
@click.option('--beneficiaries', '-b', help='Post beneficiaries (komma separated, e.g. a:10%,b:20%)')
@click.option('--percent-steem-dollars', '-b', help='50% SBD /50% SP is 10000 (default), 100% SP is 0')
@click.option('--max-accepted-payout', '-b', help='Default is 1000000.000 [SBD]')
@click.option('--no-parse-body', help='Disable parsing of links, tags and images', is_flag=True, default=False)
def post(body, account, title, permlink, tags, reply_identifier, community, beneficiaries, no_parse_body):
def post(body, account, title, permlink, tags, reply_identifier, community, beneficiaries, percent_steem_dollars, max_accepted_payout, no_parse_body):
"""broadcasts a post/comment"""
stm = shared_steem_instance()
if stm.rpc is not None:
Expand All @@ -1539,9 +1541,9 @@ def post(body, account, title, permlink, tags, reply_identifier, community, bene
if len(content.split("---")) > 1:
body = content.split("---")[-1]
docs = yaml.load_all(content.split("---")[-2])

for doc in docs:
for k,v in doc.items():
for k, v in doc.items():
parameter[k] = v
else:
body = content
Expand All @@ -1555,6 +1557,14 @@ def post(body, account, title, permlink, tags, reply_identifier, community, bene
parameter["beneficiaries"] = beneficiaries
if reply_identifier is not None:
parameter["reply_identifier"] = reply_identifier
if percent_steem_dollars is not None:
parameter["percent_steem_dollars"] = percent_steem_dollars
elif "percent-steem-dollars" in parameter:
parameter["percent_steem_dollars"] = parameter["percent-steem-dollars"]
if max_accepted_payout is not None:
parameter["max_accepted_payout"] = max_accepted_payout
elif "max-accepted-payout" in parameter:
parameter["max_accepted_payout"] = parameter["max-accepted-payout"]
tags = None
if "tags" in parameter:
tags = []
Expand Down Expand Up @@ -1582,6 +1592,23 @@ def post(body, account, title, permlink, tags, reply_identifier, community, bene
parse_body = bool(parameter["parse_body"])
else:
parse_body = not no_parse_body
max_accepted_payout = None

percent_steem_dollars = None
if "percent_steem_dollars" in parameter:
percent_steem_dollars = parameter["percent_steem_dollars"]
max_accepted_payout = None
if "max_accepted_payout" in parameter:
max_accepted_payout = parameter["max_accepted_payout"]
comment_options = None
if max_accepted_payout is not None or percent_steem_dollars is not None:
comment_options = {}
if max_accepted_payout is not None:
if stm.sbd_symbol not in max_accepted_payout:
max_accepted_payout = str(Amount(float(max_accepted_payout), stm.sbd_symbol, steem_instance=stm))
comment_options["max_accepted_payout"] = max_accepted_payout
if percent_steem_dollars is not None:
comment_options["percent_steem_dollars"] = percent_steem_dollars
beneficiaries = None
if "beneficiaries" in parameter:
beneficiaries_list = []
Expand All @@ -1604,7 +1631,7 @@ def post(body, account, title, permlink, tags, reply_identifier, community, bene
beneficiaries_sum += percentage
beneficiaries_list.append({"account": a["name"], "weight": int(percentage * 100)})
beneficiaries_accounts.append(a["name"])

missing = 0
for bene in beneficiaries_list:
if bene["weight"] < 0:
Expand All @@ -1615,8 +1642,9 @@ def post(body, account, title, permlink, tags, reply_identifier, community, bene
beneficiaries_list[index]["weight"] = int((int(100 * 100) - int(beneficiaries_sum * 100)) / missing)
index += 1
beneficiaries = sorted(beneficiaries_list, key=lambda beneficiaries_list: beneficiaries_list["account"])

tx = stm.post(title, body, author=author, permlink=permlink, reply_identifier=reply_identifier, community=community,
tags=tags, beneficiaries=beneficiaries, parse_body=parse_body)
tags=tags, comment_options=comment_options, beneficiaries=beneficiaries, parse_body=parse_body)
if stm.unsigned and stm.nobroadcast and stm.steemconnect is not None:
tx = stm.steemconnect.url_from_tx(tx)
tx = json.dumps(tx, indent=4)
Expand Down Expand Up @@ -1645,7 +1673,7 @@ def reply(authorperm, body, account, title):
if stm.unsigned and stm.nobroadcast and stm.steemconnect is not None:
tx = stm.steemconnect.url_from_tx(tx)
tx = json.dumps(tx, indent=4)
print(tx)
print(tx)


@cli.command()
Expand Down Expand Up @@ -3203,8 +3231,7 @@ def info(objects):
median_price = stm.get_current_median_history()
steem_per_mvest = stm.get_steem_per_mvest()
chain_props = stm.get_chain_properties()
price = (Amount(median_price["base"], steem_instance=stm).amount / Amount(
median_price["quote"], steem_instance=stm).amount)
price = (Amount(median_price["base"], steem_instance=stm).amount / Amount(median_price["quote"], steem_instance=stm).amount)
for key in info:
t.add_row([key, info[key]])
t.add_row(["steem per mvest", steem_per_mvest])
Expand Down
3 changes: 1 addition & 2 deletions beem/conveyor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def prehash_message(self, timestamp, account, method, params, nonce):
:param bytes nonce: random 8 bytes
"""
first = hashlib.sha256(py23_bytes(timestamp + account + method +
params, self.ENCODING))
first = hashlib.sha256(py23_bytes(timestamp + account + method + params, self.ENCODING))
return self.K + first.digest() + nonce

def _request(self, account, method, params, key):
Expand Down
2 changes: 1 addition & 1 deletion beem/nodelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def __init__(self):
"type": "appbase",
"owner": "anyx",
"score": 50
},
},
{
"url": "https://rpc.curiesteem.com",
"version": "0.20.2",
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.20.11'
version = '0.20.12'
3 changes: 1 addition & 2 deletions beem/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ def unlock(self, pwd=None):
if not pwd:
self.tryUnlockFromEnv()
else:
if (self.masterpassword is None and
config[self.MasterPassword.config_key]):
if (self.masterpassword is None and config[self.MasterPassword.config_key]):
self.masterpwd = self.MasterPassword(pwd)
self.masterpassword = self.masterpwd.decrypted_master

Expand Down
2 changes: 2 additions & 0 deletions beemapi/graphenerpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ def _check_for_server_error(self, reply):
raise RPCError("Not Implemented")
elif re.search("Bad Gateway", reply) or re.search("502", reply):
raise RPCErrorDoRetry("Bad Gateway")
elif re.search("Too Many Requests", reply) or re.search("429", reply):
raise RPCErrorDoRetry("Too Many Requests")
elif re.search("Service Temporarily Unavailable", reply) or re.search("Service Unavailable", reply) or re.search("503", reply):
raise RPCErrorDoRetry("Service Temporarily Unavailable")
elif re.search("Gateway Time-out", reply) or re.search("Gateway Timeout", reply) or re.search("504", reply):
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.20.11'
version = '0.20.12'
9 changes: 3 additions & 6 deletions beemapi/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ def on_message(self, ws, reply, *args):
# print(data)

if id >= len(self.__events__):
log.critical(
"Received an id that is out of range\n\n" +
str(data)
)
log.critical("Received an id that is out of range\n\n" + str(data))
return

# This is a "general" object change notification
Expand Down Expand Up @@ -241,10 +238,10 @@ def run_forever(self):
on_open=self.on_open,
)
self.ws.run_forever()
except websocket.WebSocketException as exc:
except websocket.WebSocketException:
self.nodes.increase_error_cnt()
self.nodes.sleep_and_check_retries()
except websocket.WebSocketTimeoutException as exc:
except websocket.WebSocketTimeoutException:
self.nodes.increase_error_cnt()
self.nodes.sleep_and_check_retries()
except KeyboardInterrupt:
Expand Down
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.20.11'
version = '0.20.12'
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.20.11'
version = '0.20.12'
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.20.11'
VERSION = '0.20.12'

tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']

Expand Down

0 comments on commit 49a8db8

Please sign in to comment.