コード例 #1
0
ファイル: beaconchain.py プロジェクト: zalam003/rotki
    def get_performance(
        self,
        indices_or_pubkeys: Union[List[int], List[str]],
    ) -> Union[Dict[int, ValidatorPerformance], Dict[str,
                                                     ValidatorPerformance]]:
        """Get the performance of all the validators given from the list of indices or pubkeys

        Queries in chunks of 100 due to api limitations

        May raise:
        - RemoteError due to problems querying beaconcha.in API
        """
        chunks = list(get_chunks(indices_or_pubkeys, n=100))  # type: ignore
        data = []
        for chunk in chunks:
            result = self._query(
                module='validator',
                endpoint='performance',
                encoded_args=','.join(str(x) for x in chunk),
            )
            if isinstance(result, list):
                data.extend(result)
            else:
                data.append(result)

        try:
            performance = {}
            for entry in data:
                index = entry['validatorindex']
                performance[index] = ValidatorPerformance(
                    balance=entry['balance'],
                    performance_1d=entry['performance1d'],
                    performance_1w=entry['performance7d'],
                    performance_1m=entry['performance31d'],
                    performance_1y=entry['performance365d'],
                )
        except KeyError as e:
            raise RemoteError(
                f'Beaconchai.in performance response processing error. Missing key entry {str(e)}',
            ) from e

        return performance
コード例 #2
0
ファイル: test_eth2.py プロジェクト: zalam003/rotki
def test_get_eth2_details_validator_not_yet_active(beaconchain, inquirer,
                                                   price_historian):  # pylint: disable=unused-argument  # noqa: E501
    """Test that if a validator is detected but is not yet active the balance is shown properly

    Test for: https://github.com/rotki/rotki/issues/1888
    """
    with _create_beacon_mock(beaconchain):
        details = get_eth2_details(beaconchain=beaconchain, addresses=[ADDR1])

    for idx in range(0, 2):
        # basic check about daily stats but then delete since this is not what this test checks
        assert len(details[idx].daily_stats) > 0
        assert details[idx].daily_stats[0].timestamp < details[
            idx].daily_stats[-1].timestamp
        details[idx] = details[idx]._replace(daily_stats=[])

    expected_details = [
        ValidatorDetails(
            validator_index=9,
            public_key=
            '0xb016e31f633a21fbe42a015152399361184f1e2c0803d89823c224994af74a561c4ad8cfc94b18781d589d03e952cd5b',  # noqa: E501
            eth1_depositor=ADDR1,
            performance=ValidatorPerformance(
                balance=32143716247,
                performance_1d=14437802,
                performance_1w=105960750,
                performance_1m=143716247,
                performance_1y=143716247,
            ),
            daily_stats=[],
        ),
        ValidatorDetails(
            validator_index=1507,
            public_key=
            '0x8b242e5cdb0a7740a605f3c39262253eb2b5e7ee514a544e823f996e8de9961db7d5264d08c5ce13a65efa82b868accc',  # noqa: E501
            eth1_depositor=ADDR1,
            performance=DEPOSITING_VALIDATOR_PERFORMANCE,
            daily_stats=[],
        ),
    ]
    assert details == expected_details