From 119c6b28ea5214139658a9738faaebd4b4321fd1 Mon Sep 17 00:00:00 2001 From: Huseyin ABANOZ Date: Sun, 10 Feb 2019 18:03:44 +0300 Subject: [PATCH] yaml changes --- src/BusinessConfiguration.py | 10 ++--- src/main.py | 11 ----- src/util/client_utils.py | 79 ++++++++++++++++++++++++++++++++++-- src/util/fee_validator.py | 14 ++++--- 4 files changed, 89 insertions(+), 25 deletions(-) diff --git a/src/BusinessConfiguration.py b/src/BusinessConfiguration.py index 9e0e6c1f..7de1ac41 100644 --- a/src/BusinessConfiguration.py +++ b/src/BusinessConfiguration.py @@ -1,19 +1,19 @@ # baker's bussiness parameters # baker's 'tz' address, NOT A KT address -BAKING_ADDRESS = "tz1YZReTLamLhyPLGSALa4TbMhjjgnSi2cqP" +BAKING_ADDRESS = "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj" # standard fee that is valid for everybody -STANDARD_FEE=0.045 +STANDARD_FEE=0 # Minimum delegation amount (in Tez) -MIN_DELEGATION_AMT=1000 +MIN_DELEGATION_AMT=0 # founders that shares the profits. map of founder payment address and share of the profit. Shares should sum up to 1. founders_map={"tz1MWTkFRXA2dwez4RHJWnDWziLpaN6iDTZ9":1.0} # deposit owners map of address and deposit ratio which must sum up to 1 owners_map={"KT1MMhmTkUoHez4u58XMZL7NkpU9FWY4QLn2":1.0} # no fee customers, e.g. founders, supporters -supporters_set={"KT1T4RgrQ986qp2ndZ2YTnxKVSSUrD2BoKFH","KT1MMhmTkUoHez4u58XMZL7NkpU9FWY4QLn2"} +supporters_set={} # customers with special rates. map of KT address and baking fee -specials_map={"KT1VYLbR7Cp4xxywWR4c12BPbkmrqSf5UXad":0.01} \ No newline at end of file +specials_map={} \ No newline at end of file diff --git a/src/main.py b/src/main.py index c4f9760d..03649506 100644 --- a/src/main.py +++ b/src/main.py @@ -291,17 +291,6 @@ def retry_failed_payments(self): os.rename(payment_failed_report_file, payment_failed_report_file + BUSY_FILE) -# all shares in the map must sum up to 1 -def validate_map_share_sum(share_map, map_name): - if len(share_map) > 0: - if abs(1 - sum(share_map.values()) > 1e-4): # a zero check actually - raise Exception("Map '{}' shares does not sum up to 1!".format(map_name)) - - -def validate_standard_fee(fee): - FeeValidator("standard_fee").validate(fee) - - def validate_release_override(release_override): if not release_override: pass diff --git a/src/util/client_utils.py b/src/util/client_utils.py index d56d85fa..648798dd 100644 --- a/src/util/client_utils.py +++ b/src/util/client_utils.py @@ -131,20 +131,91 @@ def clear_terminal_chars(content): return result +def get_manager_for_contract(client_cmd, pkh, verbose): + response = send_request(client_cmd + " get manager for " + pkh, verbose) + + response = clear_terminal_chars(response) + + return dict + + +def parse_get_manager_for_contract_response(response, verbose=None): + manager = None + for line in response.splitlines(): + line = line.strip() + if line.startswith("tz"): + line = line.replace(" (", ':') + manager, alias_plus = line.split(":", maxsplit=1) + break + + if verbose: + print("Manager address is : {}".format(manager)) + + return manager + + +def client_generate_address_dict(client_cmd, verbose: None): + contr_dict = client_list_known_contracts(client_cmd, verbose) + addr_dict = client_list_known_addresses(client_cmd, verbose) + + for alias, pkh in contr_dict.items(): + if pkh.startswith("KT"): + manager = get_manager_for_contract(client_cmd, pkh, verbose) + manager_sk = addr_dict[manager]['sk'] + addr_dict[pkh] = {"pkh": pkh, "originated": True, "alias": alias, "sk": manager_sk, "manager": manager} + + def client_list_known_contracts(client_cmd, verbose=None): - response = send_request(client_cmd + " list known contracts") + response = send_request(client_cmd + " list known contracts", verbose) response = clear_terminal_chars(response) - dict = {} + dict = parse_client_list_known_contracts_response(response, verbose) + + return dict + +def parse_client_list_known_contracts_response(response, verbose=None): + dict = {} for line in response.splitlines(): - if ":" in line and "Warning" not in line[0:10]: + line = line.strip() + if ":" in line and not_indicator_line(line): alias, pkh = line.split(":", maxsplit=1) dict[alias.strip()] = pkh.strip() - if verbose: print("known contracts: {}".format(dict)) + return dict + + +def client_list_known_addresses(client_cmd, verbose=None): + response = send_request(client_cmd + " list known addresses", verbose) + + response = clear_terminal_chars(response) + + dict = parse_list_known_addresses_response(response, verbose) + + return dict + + +def not_indicator_line(line): + return "Warning" not in line[0:15] and "Disclaimer" not in line[0:15] + + +def parse_list_known_addresses_response(response, verbose=None): + dict = {} + + for line in response.splitlines(): + line = line.strip() + if ":" in line and not_indicator_line(line): + alias, pkh_plus_braces = line.split(":", maxsplit=1) + pkh_plus_braces = pkh_plus_braces.replace(' (', ':') + pkh, sk_section = pkh_plus_braces.split(":", maxsplit=1) + sk_known = "sk known" in sk_section + pkh = pkh.strip() + alias = alias.strip() + dict[pkh] = {"pkh": pkh, "originated": False, "alias": alias, "sk": sk_known, "manager": pkh} + if verbose: + print("known addresses: {}".format(dict)) return dict diff --git a/src/util/fee_validator.py b/src/util/fee_validator.py index 52ac2c65..5a9a3c65 100644 --- a/src/util/fee_validator.py +++ b/src/util/fee_validator.py @@ -2,11 +2,15 @@ class FeeValidator: def __init__(self, specifier) -> None: super().__init__() - self.specifier=specifier + self.specifier = specifier def validate(self, fee): - if fee < 0: - raise Exception("Fee for {} cannot be less than 0, it is {}".format(self.specifier, fee)) + failed=False + try: + if fee != 0 and not 1 <= fee <= 100: + failed=True + except TypeError: + failed=True - if fee > 1: - raise Exception("Fee for {} cannot be greater than 1, it is {}".format(self.specifier, fee)) + if failed: + raise Exception("Fee for {} cannot be {}. Valid values are 0, [1-100]".format(self.specifier, fee)) \ No newline at end of file