コード例 #1
0
    def test_calculate(self):
        nw = {"NAME": "MAINNET"}
        mirror_selector = DunScanMirrorSelector(nw)
        mirror_selector.initialize()

        api = DunScanRewardApiImpl(nw, BAKING_ADDRESS, mirror_selector)
        model = api.get_rewards_for_cycle_map(43)

        phase0 = CalculatePhase0(model)
        reward_data, total_rewards = phase0.calculate()

        staking_balance = int(model.delegate_staking_balance)

        # total reward ratio is 1
        self.assertTrue(1.0, sum(r.ratio0 for r in reward_data))

        # check that ratio calculations are correct
        delegators_balances = model.delegator_balance_dict

        # check ratios
        for (address, balance), reward in zip(delegators_balances.items(),
                                              reward_data):
            # ratio must be equal to stake/total staking balance
            self.assertEqual(int(balance) / staking_balance, reward.ratio0)

        # last one is owners record
        self.assertTrue(reward_data[-1].type == reward_log.TYPE_OWNERS_PARENT)
コード例 #2
0
    def __init__(self, nw, baking_address, node_url, validate=True, verbose=True):
        super(PRpcRewardApiImpl, self).__init__()

        self.blocks_per_cycle = nw['BLOCKS_PER_CYCLE']
        self.preserved_cycles = nw['NB_FREEZE_CYCLE']
        self.blocks_per_roll_snapshot = nw['BLOCKS_PER_ROLL_SNAPSHOT']

        self.baking_address = baking_address
        self.node_url = node_url

        self.verbose = verbose
        self.validate = validate

        # replace protocol placeholder
        protocol = 'https'
        self.COMM_HEAD = self.COMM_HEAD.replace('%protocol%',protocol)
        self.COMM_DELEGATES = self.COMM_DELEGATES.replace('%protocol%',protocol)
        self.COMM_BLOCK = self.COMM_BLOCK.replace('%protocol%',protocol)
        self.COMM_SNAPSHOT = self.COMM_SNAPSHOT.replace('%protocol%',protocol)
        self.COMM_DELEGATE_BALANCE = self.COMM_DELEGATE_BALANCE.replace('%protocol%',protocol)

        if self.validate:
            mirror_selector = DunScanMirrorSelector(nw)
            mirror_selector.initialize()
            self.validate_api = DunScanRewardApiImpl(nw, self.baking_address, mirror_selector)
コード例 #3
0
    def test_validate_no_founders_map(self):
        data_no_founders = """
        version : 1.0
        baking_address : dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x
        payment_address : dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x
        owners_map : {'KT2Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj':0.5,'KT3Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj':0.5}
        service_fee : 4.5
        """

        managers_map = {
            'dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x':
            'dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x'
        }

        contr_dict_by_alias = {}
        addr_dict_by_pkh = {
            "dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x": {
                "pkh": "dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x",
                "originated": False,
                "alias": "main1",
                "sk": True,
                "manager": "dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x"
            }
        }

        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_map)

        mirror_selector = DunScanMirrorSelector(network)
        mirror_selector.initialize()
        block_api = DunScanBlockApiImpl(network, mirror_selector)
        cnf_prsr = BakingYamlConfParser(data_no_founders,
                                        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'),
                         'dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x')
        self.assertEqual(cnf_prsr.get_conf_obj_attr('payment_address'),
                         'dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x')
        self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_pkh'),
                         'dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x')
        self.assertEqual(
            cnf_prsr.get_conf_obj_attr('__payment_address_manager'),
            'dn1VWnJRnF3vsa3tkYp3PqoCbV1eBRc5vJ2x')
        self.assertEqual(cnf_prsr.get_conf_obj_attr('__payment_address_type'),
                         AddrType.DN)
        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(0, cnf_prsr.get_conf_obj_attr('min_delegation_amt'))
コード例 #4
0
    def __init__(self,
                 nw,
                 baking_address,
                 wllt_clnt_mngr,
                 node_url,
                 validate=True):
        super(RpcRewardApiImpl, self).__init__()

        self.blocks_per_cycle = nw['BLOCKS_PER_CYCLE']
        self.preserved_cycles = nw['NB_FREEZE_CYCLE']
        self.blocks_per_roll_snapshot = nw['BLOCKS_PER_ROLL_SNAPSHOT']

        self.baking_address = baking_address
        self.wllt_clnt_mngr = wllt_clnt_mngr
        self.node_url = node_url

        self.validate = validate
        if self.validate:
            mirror_selector = DunScanMirrorSelector(nw)
            mirror_selector.initialize()
            self.validate_api = DunScanRewardApiImpl(nw, self.baking_address,
                                                     mirror_selector)
コード例 #5
0
class ProviderFactory:
    URL = "{}.tzbeta.net/"
    URL = "{}.tezrpc.me/"
    url_prefixes = {"MAINNET": "rpc", "ALPHANET": "rpcalpha", "ZERONET": "rpczero"}
    url_prefixes = {"MAINNET": "mainnet", "ALPHANET": "alphanet", "ZERONET": "zeronet"}

    def __init__(self, provider, verbose=False):
        self.provider = provider
        self.mirror_selector = None
        self.verbose = verbose

    def newRewardApi(self, network_config, baking_address, wllt_clnt_mngr, node_url):
        if self.provider == 'rpc':
            return LRpcRewardApiImpl(network_config, baking_address, node_url, wllt_clnt_mngr, verbose=self.verbose)
        elif self.provider == 'prpc':
            url_prefix = self.url_prefixes[network_config['NAME']]
            return PRpcRewardApiImpl(network_config,  baking_address, self.URL.format(url_prefix), verbose=self.verbose)
        elif self.provider == 'dunscan':
            if not self.mirror_selector:
                self.init_mirror_selector(network_config)
            return DunscanRewardApiImpl(network_config, baking_address, self.mirror_selector, verbose=self.verbose)

        raise Exception("No supported reward data provider : {}".format(self.provider))

    def init_mirror_selector(self, network_config):
        self.mirror_selector = DunScanMirrorSelector(network_config)
        self.mirror_selector.initialize()

    def newBlockApi(self, network_config, wllt_clnt_mngr, node_url):
        if self.provider == 'rpc' or self.provider == 'prpc':
            return RpcBlockApiImpl(network_config, wllt_clnt_mngr, node_url)
        elif self.provider == 'dunscan':
            if not self.mirror_selector:
                self.init_mirror_selector(network_config)
            return DunScanBlockApiImpl(network_config,self.mirror_selector)

        raise Exception("No supported reward data provider : {}".format(self.provider))
コード例 #6
0
 def init_mirror_selector(self, network_config):
     self.mirror_selector = DunScanMirrorSelector(network_config)
     self.mirror_selector.initialize()