예제 #1
0
def delegations(address):
    skale = init_skale_from_config()
    if not skale:
        return
    delegations_list = skale.delegation_service.get_all_delegations_by_holder(
        address)
    print(f'Delegations for address {address}:\n')
    print_delegations(delegations_list)
예제 #2
0
def linked_addresses(address):
    skale = init_skale_from_config()
    if not skale:
        return
    addresses = skale.validator_service.get_linked_addresses_by_validator_address(
        address)
    addresses_info = get_addresses_info(skale, addresses)
    print(f'Linked addresses for {address}:\n')
    print_linked_addresses(addresses_info)
예제 #3
0
def get_metrics_from_events(node_ids,
                            start_date=None,
                            end_date=None,
                            limit=None,
                            is_validator=False):
    skale = init_skale_from_config()
    metrics_rows = []
    total_bounty = 0
    limit = format_limit(limit)
    start_block_number, last_block_number = get_start_end_block_numbers(
        skale, node_ids, start_date, end_date)
    start_chunk_block_number = start_block_number
    blocks_total = last_block_number - start_block_number
    while len(metrics_rows) < limit:
        progress_bar(start_chunk_block_number - start_block_number,
                     blocks_total)

        end_chunk_block_number = start_chunk_block_number + BLOCK_CHUNK_SIZE - 1
        if end_chunk_block_number > last_block_number:
            end_chunk_block_number = last_block_number

        event_filter = SkaleFilter(skale.manager.contract.events.BountyGot,
                                   from_block=hex(start_chunk_block_number),
                                   argument_filters={'nodeIndex': node_ids},
                                   to_block=hex(end_chunk_block_number))
        logs = event_filter.get_events()
        for log in logs:
            args = log['args']
            tx_block_number = log['blockNumber']
            block_data = skale.web3.eth.getBlock(tx_block_number)
            block_timestamp = datetime.utcfromtimestamp(
                block_data['timestamp'])
            metrics_row = [
                str(block_timestamp),
                to_skl(args['bounty']), args['averageDowntime'],
                round(args['averageLatency'] / 1000, 1)
            ]
            if is_validator:
                metrics_row.insert(1, args['nodeIndex'])
                total_bounty += metrics_row[2]
            else:
                total_bounty += metrics_row[1]
            metrics_rows.append(metrics_row)
            if len(metrics_rows) >= limit:
                break
        start_chunk_block_number = start_chunk_block_number + BLOCK_CHUNK_SIZE
        if end_chunk_block_number >= last_block_number:
            break
    progress_bar(blocks_total, blocks_total)
    return metrics_rows, total_bounty
예제 #4
0
def info(validator_id):
    skale = init_skale_from_config()
    if not skale:
        return
    validator_info = skale.validator_service.get(validator_id)
    delegated_amount = skale.delegation_service.get_delegated_amount(
        validator_id)
    earned_bounty_amount = skale.delegation_service.get_earned_bounty_amount(
        validator_info['validator_address'])
    msr = skale.constants_holder.msr()
    table = SingleTable([['Validator ID', validator_id],
                         ['Name', validator_info['name']],
                         ['Address', validator_info['validator_address']],
                         ['Fee rate (%)', validator_info['fee_rate']],
                         [
                             'Minimum delegation amount (SKL)',
                             validator_info['minimum_delegation_amount']
                         ], ['Delegated tokens', delegated_amount],
                         ['Earned bounty', earned_bounty_amount], ['MSR',
                                                                   msr]])
    print(table.table)
예제 #5
0
def validators_list():
    skale = init_skale_from_config()
    validators = skale.validator_service.ls()
    print_validators(validators)
예제 #6
0
def get_nodes_for_validator(val_id):
    skale = init_skale_from_config()
    validator_service = skale.get_contract_by_name('validator_service')
    return validator_service.contract.functions.getValidatorNodeIndexes(
        val_id).call()
예제 #7
0
def get_last_reward_date(node_id):
    skale = init_skale_from_config()
    return skale.nodes_data.get(node_id)['last_reward_date']
예제 #8
0
def get_start_date(node_id):
    skale = init_skale_from_config()
    return skale.nodes_data.get(node_id)['start_date']
예제 #9
0
def get_bounty_from_events(node_ids,
                           start_date=None,
                           end_date=None,
                           limit=None) -> tuple:
    skale = init_skale_from_config()
    bounty_rows = []
    total_bounty = 0
    cur_month_record = {}
    limit = format_limit(limit)
    start_block_number, last_block_number = get_start_end_block_numbers(
        skale, node_ids, start_date, end_date)
    start_chunk_block_number = start_block_number
    blocks_total = last_block_number - start_block_number

    while len(bounty_rows) < limit:
        progress_bar(start_chunk_block_number - start_block_number,
                     blocks_total)
        end_chunk_block_number = start_chunk_block_number + BLOCK_CHUNK_SIZE - 1
        if end_chunk_block_number > last_block_number:
            end_chunk_block_number = last_block_number

        event_filter = SkaleFilter(skale.manager.contract.events.BountyGot,
                                   from_block=hex(start_chunk_block_number),
                                   argument_filters={'nodeIndex': node_ids},
                                   to_block=hex(end_chunk_block_number))
        logs = event_filter.get_events()
        for log in logs:
            args = log['args']
            node_id = args['nodeIndex']
            bounty = args['bounty']
            tx_block_number = log['blockNumber']
            block_data = skale.web3.eth.getBlock(tx_block_number)
            block_timestamp = datetime.utcfromtimestamp(
                block_data['timestamp'])
            cur_year_month = f'{block_timestamp.strftime("%Y")} {block_timestamp.strftime("%B")}'
            # for tests where epoch = 1 hour
            cur_year_month = f'{cur_year_month} ' \
                             f'{block_timestamp.strftime("%d")}'
            if cur_year_month in cur_month_record:
                if node_id in cur_month_record[cur_year_month]:
                    cur_month_record[cur_year_month][node_id] += bounty
                else:
                    cur_month_record[cur_year_month][node_id] = bounty
            else:
                if bool(cur_month_record):  # if prepared dict is not empty
                    bounty_row = bounty_to_ordered_row(cur_month_record,
                                                       node_ids)
                    total_bounty += bounty_row[1]
                    bounty_rows.append(bounty_row)
                cur_month_record = {cur_year_month: {node_id: bounty}}
            if len(bounty_rows) >= limit:
                break
        start_chunk_block_number = start_chunk_block_number + BLOCK_CHUNK_SIZE
        if end_chunk_block_number >= last_block_number:
            break
    progress_bar(blocks_total, blocks_total)
    if bool(cur_month_record) and len(bounty_rows) < limit:
        bounty_row = bounty_to_ordered_row(cur_month_record, node_ids)
        total_bounty += bounty_row[1]
        bounty_rows.append(bounty_row)
    return bounty_rows, total_bounty