Skip to content

Commit

Permalink
Merge pull request tezos-reward-distributor-organization#106 from hab…
Browse files Browse the repository at this point in the history
…anoz/development

Development
  • Loading branch information
habanoz authored Oct 16, 2019
2 parents 7c872e9 + 7d783bf commit b60e0ce
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 80 deletions.
4 changes: 2 additions & 2 deletions fee.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
fee=1274

[KTTX]
storage_limit=0
gas_limit=10200
storage_limit=300
gas_limit=10300
base=100
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
4 changes: 1 addition & 3 deletions src/api/provider_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions src/cli/cmd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
28 changes: 14 additions & 14 deletions src/cli/wallet_client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.")
Expand Down
57 changes: 5 additions & 52 deletions src/config/test_BakingYamlConfParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -125,62 +125,15 @@ 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())
self.assertEqual(cnf_prsr.get_conf_obj_attr('supporters_set'), set())

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())
12 changes: 9 additions & 3 deletions src/config/yaml_baking_conf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/launch_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/pay/batch_payer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%'"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
9 changes: 8 additions & 1 deletion src/rpc/rpc_block_api.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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


Expand Down
13 changes: 11 additions & 2 deletions src/tzscan/tzscan_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down

0 comments on commit b60e0ce

Please sign in to comment.