From 49a8db878bff1a503b2e9acc9cd38f337efe9ba5 Mon Sep 17 00:00:00 2001 From: Holger Date: Thu, 15 Nov 2018 15:34:56 +0100 Subject: [PATCH] Release 0.20.12 * 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 --- beem/account.py | 43 ++++++++++++++++++------------------- beem/amount.py | 10 ++------- beem/cli.py | 43 ++++++++++++++++++++++++++++++------- beem/conveyor.py | 3 +-- beem/nodelist.py | 2 +- beem/version.py | 2 +- beem/wallet.py | 3 +-- beemapi/graphenerpc.py | 2 ++ beemapi/version.py | 2 +- beemapi/websocket.py | 9 +++----- beembase/version.py | 2 +- beemgraphenebase/version.py | 2 +- setup.py | 2 +- 13 files changed, 71 insertions(+), 54 deletions(-) diff --git a/beem/account.py b/beem/account.py index c7f87d24..18d82001 100644 --- a/beem/account.py +++ b/beem/account.py @@ -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 @@ -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): @@ -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) @@ -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, @@ -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] diff --git a/beem/amount.py b/beem/amount.py index fc1b047a..873b76dd 100644 --- a/beem/amount.py +++ b/beem/amount.py @@ -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"] diff --git a/beem/cli.py b/beem/cli.py index cd455836..a8a71413 100644 --- a/beem/cli.py +++ b/beem/cli.py @@ -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: @@ -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 @@ -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 = [] @@ -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 = [] @@ -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: @@ -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) @@ -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() @@ -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]) diff --git a/beem/conveyor.py b/beem/conveyor.py index cdabe01f..eceec5fe 100644 --- a/beem/conveyor.py +++ b/beem/conveyor.py @@ -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): diff --git a/beem/nodelist.py b/beem/nodelist.py index d8c2e4f4..bb130b22 100644 --- a/beem/nodelist.py +++ b/beem/nodelist.py @@ -221,7 +221,7 @@ def __init__(self): "type": "appbase", "owner": "anyx", "score": 50 - }, + }, { "url": "https://rpc.curiesteem.com", "version": "0.20.2", diff --git a/beem/version.py b/beem/version.py index c4da6b12..410a960b 100644 --- a/beem/version.py +++ b/beem/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.11' +version = '0.20.12' diff --git a/beem/wallet.py b/beem/wallet.py index 3505d242..3d1c82bb 100644 --- a/beem/wallet.py +++ b/beem/wallet.py @@ -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 diff --git a/beemapi/graphenerpc.py b/beemapi/graphenerpc.py index 977b081a..af086942 100644 --- a/beemapi/graphenerpc.py +++ b/beemapi/graphenerpc.py @@ -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): diff --git a/beemapi/version.py b/beemapi/version.py index c4da6b12..410a960b 100644 --- a/beemapi/version.py +++ b/beemapi/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.11' +version = '0.20.12' diff --git a/beemapi/websocket.py b/beemapi/websocket.py index 12c58163..29a0fe77 100644 --- a/beemapi/websocket.py +++ b/beemapi/websocket.py @@ -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 @@ -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: diff --git a/beembase/version.py b/beembase/version.py index c4da6b12..410a960b 100644 --- a/beembase/version.py +++ b/beembase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.11' +version = '0.20.12' diff --git a/beemgraphenebase/version.py b/beemgraphenebase/version.py index c4da6b12..410a960b 100644 --- a/beemgraphenebase/version.py +++ b/beemgraphenebase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.11' +version = '0.20.12' diff --git a/setup.py b/setup.py index c3fa9311..24a2d111 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.20.11' +VERSION = '0.20.12' tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']