diff --git a/fee.ini b/fee.ini index 88bfa5da..6ebc6c60 100644 --- a/fee.ini +++ b/fee.ini @@ -2,6 +2,6 @@ fee=1274 [KTTX] -storage_limit=0 -gas_limit=10200 +storage_limit=300 +gas_limit=10300 base=100 diff --git a/readme.md b/readme.md index 73a6af92..20f3f273 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ TRD supports complex payments, pays in batches, provides two back ends for calcu https://medium.com/@huseyinabanox/tezos-reward-distributor-e6588c4d27e7 -## TRD Art Work +## TRD Art Work https://github.com/habanoz/trd-art contains logo images. If you are using TRD and want to let everybody know about it, feel free to place them in your website. diff --git a/src/api/provider_factory.py b/src/api/provider_factory.py index 81bba21b..d6c661dd 100644 --- a/src/api/provider_factory.py +++ b/src/api/provider_factory.py @@ -8,9 +8,7 @@ class ProviderFactory: - URL = "{}.tzbeta.net/" - URL = "{}.tezrpc.me/" - url_prefixes = {"MAINNET": "rpc", "ALPHANET": "rpcalpha", "ZERONET": "rpczero"} + URL = "https://rpc.tulip.tools/{}/" url_prefixes = {"MAINNET": "mainnet", "ALPHANET": "alphanet", "ZERONET": "zeronet"} def __init__(self, provider, verbose=False): diff --git a/src/cli/cmd_manager.py b/src/cli/cmd_manager.py index 0c3bfdd9..7a88a32a 100644 --- a/src/cli/cmd_manager.py +++ b/src/cli/cmd_manager.py @@ -28,8 +28,10 @@ def execute(self, cmd, verbose_override=None, timeout=None): try: output = check_output(cmd, shell=True, stderr=STDOUT, timeout=timeout, encoding='utf8') except TimeoutExpired as e: + logger.info("Command timed out") raise e except CalledProcessError as e: + logger.info("Command failed, error is |{}|".format(e.output)) return False, e.output # output = output.decode('utf-8') diff --git a/src/cli/wallet_client_manager.py b/src/cli/wallet_client_manager.py index 61eb21ab..e707c4ef 100644 --- a/src/cli/wallet_client_manager.py +++ b/src/cli/wallet_client_manager.py @@ -78,8 +78,8 @@ def generate_address_dict(self): self.address_dict = {} - if self.contr_dict_by_alias is None: - self.contr_dict_by_alias = self.__list_known_contracts_by_alias() + #if self.contr_dict_by_alias is None: + # self.contr_dict_by_alias = self.__list_known_contracts_by_alias() if self.addr_dict_by_pkh is None: self.addr_dict_by_pkh = self.__list_known_addresses_by_pkh() @@ -92,20 +92,20 @@ def generate_address_dict(self): logger.debug("Known address added: {}".format(self.address_dict[pkh])) - for alias, pkh in self.contr_dict_by_alias.items(): - if pkh.startswith("KT"): - manager = self.get_manager_for_contract(pkh) - if manager not in self.addr_dict_by_pkh: - # raise ConfigurationException("Manager pkh {} not found in known addresses".format(manager)) - manager_sk = None - else: - manager_sk = self.addr_dict_by_pkh[manager]['sk'] + #for alias, pkh in self.contr_dict_by_alias.items(): + # if pkh.startswith("KT"): + # manager = self.get_manager_for_contract(pkh) + # if manager not in self.addr_dict_by_pkh: + # # raise ConfigurationException("Manager pkh {} not found in known addresses".format(manager)) + # manager_sk = None + # else: + # manager_sk = self.addr_dict_by_pkh[manager]['sk'] - self.address_dict[pkh] = {"pkh": pkh, "originated": True, "alias": alias, "sk": manager_sk, "manager": manager} - if pkh in self.addr_dict_by_pkh and "revealed" in self.addr_dict_by_pkh[pkh]: - self.address_dict[pkh]["revealed"] = self.addr_dict_by_pkh[pkh]["revealed"] + # self.address_dict[pkh] = {"pkh": pkh, "originated": True, "alias": alias, "sk": manager_sk, "manager": manager} + # if pkh in self.addr_dict_by_pkh and "revealed" in self.addr_dict_by_pkh[pkh]: + # self.address_dict[pkh]["revealed"] = self.addr_dict_by_pkh[pkh]["revealed"] - logger.debug("Known contract added: {}".format(self.address_dict[pkh])) + # logger.debug("Known contract added: {}".format(self.address_dict[pkh])) if not self.address_dict: logger.warn("No known address info is reached. Check your environment. Try to run in privileged mode.") diff --git a/src/config/test_BakingYamlConfParser.py b/src/config/test_BakingYamlConfParser.py index f776aa07..7ce437e4 100644 --- a/src/config/test_BakingYamlConfParser.py +++ b/src/config/test_BakingYamlConfParser.py @@ -95,7 +95,7 @@ def test_validate_pymnt_alias(self): data_no_founders = """ version : 1.0 baking_address : tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj - payment_address : ktPay + payment_address : tzPay owners_map : {'KT2Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj':0.5,'KT3Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj':0.5} service_fee : 4.5 min_delegation_amt : 100 @@ -104,7 +104,7 @@ def test_validate_pymnt_alias(self): managers_map = {'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj': 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj', 'KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj': 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj'} - contr_dict_by_alias = {'ktPay': 'KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj'} + contr_dict_by_alias = {'kt': 'KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj','tzPay':'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj'} addr_dict_by_pkh = { "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj": {"pkh": "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj", "originated": False, "alias": "tz1", "sk": True, @@ -125,10 +125,10 @@ def test_validate_pymnt_alias(self): cnf_prsr.validate() self.assertEqual(cnf_prsr.get_conf_obj_attr('baking_address'), 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') - self.assertEqual(cnf_prsr.get_conf_obj_attr('payment_address'), 'ktPay') - self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_pkh'), 'KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') + self.assertEqual(cnf_prsr.get_conf_obj_attr('payment_address'), 'tzPay') + self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_pkh'), 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_manager'), 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') - self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_type'), AddrType.KTALS) + self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_type'), AddrType.TZALS) self.assertEqual(cnf_prsr.get_conf_obj_attr('founders_map'), dict()) self.assertEqual(cnf_prsr.get_conf_obj_attr('specials_map'), dict()) @@ -136,51 +136,4 @@ def test_validate_pymnt_alias(self): self.assertEqual(100, cnf_prsr.get_conf_obj_attr('min_delegation_amt')) - def test_validate_empty(self): - data_fine = """ - version : 1.0 - baking_address : tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj - payment_address : KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj - service_fee : 4.5 - founders_map : {} - owners_map : {} - specials_map : {} - supporters_set : {} - min_delegation_amt : 0 - """ - - - managers = {'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj': 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj', - 'KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj': 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj'} - - contr_dict_by_alias = {} - addr_dict_by_pkh = { - "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj": {"pkh": "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj", "originated": False, - "alias": "main1", "sk": True, "revealed" : True, - "manager": "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj"}, - - "KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj": {"pkh": "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj", "originated": False, - "alias": "ktPay", "sk": True, "revealed":True, - "manager": "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj"} - } - - wallet_client_manager = WalletClientManager(client_path=None, addr_dict_by_pkh=addr_dict_by_pkh, - contr_dict_by_alias=contr_dict_by_alias, managers=managers) - - mirror_selector = TzScanMirrorSelector(network) - mirror_selector.initialize() - block_api = TzScanBlockApiImpl(network, mirror_selector) - cnf_prsr = BakingYamlConfParser(data_fine, wallet_client_manager, provider_factory=None, - network_config=network, node_url=mainnet_public_node_url, block_api=block_api) - - cnf_prsr.parse() - cnf_prsr.validate() - - self.assertEqual(cnf_prsr.get_conf_obj_attr('baking_address'), 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') - self.assertEqual(cnf_prsr.get_conf_obj_attr('payment_address'), 'KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') - self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_pkh'), 'KT1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') - self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_manager'), 'tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj') - self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_type'), AddrType.KT) - self.assertEqual(0, cnf_prsr.get_conf_obj_attr('min_delegation_amt')) - self.assertEqual(cnf_prsr.get_conf_obj_attr('supporters_set'), set()) diff --git a/src/config/yaml_baking_conf_parser.py b/src/config/yaml_baking_conf_parser.py index 6e6fae25..af995fa7 100644 --- a/src/config/yaml_baking_conf_parser.py +++ b/src/config/yaml_baking_conf_parser.py @@ -118,20 +118,26 @@ def validate_payment_address(self, conf_obj): if not pymnt_addr: raise ConfigurationException("Payment address must be set") - if len(pymnt_addr) == PKH_LENGHT and (pymnt_addr.startswith("KT") or pymnt_addr.startswith("tz")): + if pymnt_addr.startswith("KT"): + raise ConfigurationException("KT addresses cannot be used for payments. Only tz addresses are allowed") + + if len(pymnt_addr) == PKH_LENGHT and pymnt_addr.startswith("tz"): addr_obj = self.wllt_clnt_mngr.get_addr_dict_by_pkh(pymnt_addr) self.check_sk(addr_obj, pymnt_addr) - conf_obj[('__%s_type' % PAYMENT_ADDRESS)] = AddrType.KT if pymnt_addr.startswith("KT") else AddrType.TZ + conf_obj[('__%s_type' % PAYMENT_ADDRESS)] = AddrType.TZ conf_obj[('__%s_pkh' % PAYMENT_ADDRESS)] = pymnt_addr - conf_obj[('__%s_manager' % PAYMENT_ADDRESS)] = self.wllt_clnt_mngr.get_manager_for_contract(pymnt_addr) + conf_obj[('__%s_manager' % PAYMENT_ADDRESS)] = pymnt_addr else: if pymnt_addr in self.wllt_clnt_mngr.get_known_contracts_by_alias(): pkh = self.wllt_clnt_mngr.get_known_contract_by_alias(pymnt_addr) + if pkh.startswith("KT"): + raise ConfigurationException("KT addresses cannot be used for payments. Only tz addresses are allowed") + addr_obj = self.wllt_clnt_mngr.get_addr_dict_by_pkh(pkh) self.check_sk(addr_obj, pkh) diff --git a/src/launch_common.py b/src/launch_common.py index 8fe91535..de0160f2 100644 --- a/src/launch_common.py +++ b/src/launch_common.py @@ -33,8 +33,8 @@ def add_argument_reports_base(parser): def add_argument_provider(parser): - parser.add_argument("-P", "--reward_data_provider", help="where reward data is provided. prpc=public rpc", choices=['tzscan', 'rpc','prpc'], - default='tzscan') + parser.add_argument("-P", "--reward_data_provider", help="where reward data is provided. prpc=public rpc", choices=['rpc','prpc'], + default='prpc') def add_argument_config_dir(parser): diff --git a/src/pay/batch_payer.py b/src/pay/batch_payer.py index 6fd6113b..00dc2f23 100644 --- a/src/pay/batch_payer.py +++ b/src/pay/batch_payer.py @@ -26,6 +26,7 @@ FORGE_JSON = '{"branch": "%BRANCH%","contents":[%CONTENT%]}' RUNOPS_JSON = '{"branch": "%BRANCH%","contents":[%CONTENT%], "signature":"edsigtXomBKi5CTRf5cjATJWSyaRvhfYNHqSUGrn4SdbYRcGwQrUGjzEfQDTuqHhuA8b2d8NarZjz8TRf65WkpQmo423BtomS8Q"}' PREAPPLY_JSON = '[{"protocol":"%PROTOCOL%","branch":"%BRANCH%","contents":[%CONTENT%],"signature":"%SIGNATURE%"}]' +JSON_WRAP='{"operation": %JSON%,"chain_id":"%chain_id%"}' COMM_FORGE = " rpc post http://%NODE%/chains/main/blocks/head/helpers/forge/operations with '%JSON%'" COMM_RUNOPS = " rpc post http://%NODE%/chains/main/blocks/head/helpers/scripts/run_operation with '%JSON%'" COMM_PREAPPLY = " rpc post http://%NODE%/chains/main/blocks/head/helpers/preapply/operations with '%JSON%'" @@ -230,6 +231,7 @@ def attempt_single_batch(self, payment_records, op_counter, verbose=None, dry_ru _, response = self.wllt_clnt_mngr.send_request(self.comm_head, verbose_override=False) head = parse_json_response(response) branch = head["hash"] + chain_id = head["chain_id"] protocol = head["metadata"]["protocol"] logger.debug("head: branch {} counter {} protocol {}".format(branch, op_counter.get(), protocol)) @@ -260,6 +262,7 @@ def attempt_single_batch(self, payment_records, op_counter, verbose=None, dry_ru # run the operations logger.debug("Running {} operations".format(len(content_list))) runops_json = RUNOPS_JSON.replace('%BRANCH%', branch).replace("%CONTENT%", contents_string) + runops_json = JSON_WRAP.replace("%JSON%", runops_json).replace("%chain_id%",chain_id) runops_command_str = self.comm_runops.replace("%JSON%", runops_json) # if verbose: print("--> runops_command_str is |{}|".format(runops_command_str)) diff --git a/src/rpc/rpc_block_api.py b/src/rpc/rpc_block_api.py index 30e16402..2cc82cc9 100644 --- a/src/rpc/rpc_block_api.py +++ b/src/rpc/rpc_block_api.py @@ -1,6 +1,10 @@ from api.block_api import BlockApi from util.rpc_utils import parse_json_response +from log_config import main_logger + +logger = main_logger + COMM_HEAD = " rpc get http://{}/chains/main/blocks/head" COMM_REVELATION = " rpc get http://{}/chains/main/blocks/head/context/contracts/{}/manager_key" @@ -21,7 +25,10 @@ def get_current_level(self, verbose=False): def get_revelation(self, pkh, verbose=False): _, response = self.wllt_clnt_mngr.send_request(COMM_REVELATION.format(self.node_url, pkh)) manager_key = parse_json_response(response, verbose=verbose) - bool_revelation = "key" in manager_key.keys() and len(manager_key["key"]) > 0 + + logger.debug("Manager key is '{}'".format(manager_key)) + + bool_revelation = manager_key and manager_key!='null' return bool_revelation diff --git a/src/tzscan/tzscan_reward_api.py b/src/tzscan/tzscan_reward_api.py index de48d806..45f6ed90 100644 --- a/src/tzscan/tzscan_reward_api.py +++ b/src/tzscan/tzscan_reward_api.py @@ -24,8 +24,17 @@ def get_rewards_for_cycle_map(self, cycle): future_blocks_rewards = int(root["future_blocks_rewards"]) endorsements_rewards = int(root["endorsements_rewards"]) future_endorsements_rewards = int(root["future_endorsements_rewards"]) - lost_rewards_denounciation = int(root["lost_rewards_denounciation_baking"])+int(root["lost_rewards_denounciation_endorsement"]) - lost_fees_denounciation = int(root["lost_fees_denounciation_baking"])+int(root["lost_fees_denounciation_endorsement"]) + + if "lost_rewards_denounciation_baking" in root: + lost_rewards_denounciation = int(root["lost_rewards_denounciation_baking"])+int(root["lost_rewards_denounciation_endorsement"]) + else: + lost_rewards_denounciation = int(root["lost_rewards_denounciation"]) + + if "lost_fees_denounciation_baking" in root: + lost_fees_denounciation = int(root["lost_fees_denounciation_baking"])+int(root["lost_fees_denounciation_endorsement"]) + else: + lost_fees_denounciation = int(root["lost_fees_denounciation"]) + fees = int(root["fees"]) total_reward_amount = (blocks_rewards + endorsements_rewards + future_blocks_rewards +