diff --git a/beem/account.py b/beem/account.py index c7f87d24ba105caaa2319a51f61e082deb91d5d2..18d8200117bb79af3fd8216d2e80886ae15af172 100644 --- a/beem/account.py +++ b/beem/account.py @@ -891,8 +891,10 @@ class Account(BlockchainObject): 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 @@ class Account(BlockchainObject): 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 @@ class Account(BlockchainObject): # 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 @@ class Account(BlockchainObject): 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 @@ class Account(BlockchainObject): "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 fc1b047a9bfbb4c47f7642078269d8843f9a01b2..873b76dd33bb7287896b90e310b6ac452eef961b 100644 --- a/beem/amount.py +++ b/beem/amount.py @@ -96,18 +96,12 @@ class Amount(dict): 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 cd4558365c9049e731597f3be15ab880ae8e51d1..a8a71413790f699a580842645cd0767401abd746 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 cdabe01f400ea0b96c8f7645363d58144e06882b..eceec5fe781c846ed561f01a55a7b7a8edff279f 100644 --- a/beem/conveyor.py +++ b/beem/conveyor.py @@ -75,8 +75,7 @@ class Conveyor(object): :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 d8c2e4f4d1524e24355436738bc30a5e7e72b5bd..bb130b223558b6d530ac951925fad57162ec3fbc 100644 --- a/beem/nodelist.py +++ b/beem/nodelist.py @@ -221,7 +221,7 @@ class NodeList(list): "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 c4da6b12a792a90f434bf2604999ee0c707394c7..410a960b4314381e0656f67b2adde3916dcd443c 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 3505d242c20a868da13125eea8cb6f6a73de3ea6..3d1c82bb4068962dadcd91cad229bfe1fb00b62e 100644 --- a/beem/wallet.py +++ b/beem/wallet.py @@ -203,8 +203,7 @@ class Wallet(object): 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 977b081a7ad7013bc6aca4a8119c57ebee83d689..af086942df1d011fbcf3c3d6fa04dfd3f90226c4 100644 --- a/beemapi/graphenerpc.py +++ b/beemapi/graphenerpc.py @@ -335,6 +335,8 @@ class GrapheneRPC(object): 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 c4da6b12a792a90f434bf2604999ee0c707394c7..410a960b4314381e0656f67b2adde3916dcd443c 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 12c5816322d302862b62cb9f807af69f2a5cc986..29a0fe775667521526d66d34442c0144ec57bf70 100644 --- a/beemapi/websocket.py +++ b/beemapi/websocket.py @@ -177,10 +177,7 @@ class SteemWebsocket(Events): # 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 @@ class SteemWebsocket(Events): 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 c4da6b12a792a90f434bf2604999ee0c707394c7..410a960b4314381e0656f67b2adde3916dcd443c 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 c4da6b12a792a90f434bf2604999ee0c707394c7..410a960b4314381e0656f67b2adde3916dcd443c 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 c3fa9311f8ac9f6755147d720206ff4e046d8bc8..24a2d111e7ea499d8bcaf2baf4bced4508b0fc2e 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ except LookupError: 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']