Example #1
0
def global_participation_history_crawler():
    epoch_no = 170
    while (epoch_no < 1745):
        data = False
        data = beacon.get_participation_rate(epoch=epoch_no)
        if data:
            participation = data.get('participation')
            epoch_timestamp = time_calculator.get_epoch_time(epoch_no)
            timestamp = datetime.datetime.strptime(epoch_timestamp,
                                                   '%Y-%m-%dT%H:%M:%SZ')
            obj_id = ObjectId.from_datetime(timestamp)

            insert_data = {
                '_id':
                obj_id,
                'epoch':
                int(data.get('epoch')),
                'voted_ether':
                participation.get('votedEther'),
                'global_participation':
                participation.get('globalParticipationRate'),
                'eligible_ether':
                participation.get('eligibleEther'),
                'timestamp':
                epoch_timestamp
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.global_participation_new_altona.insert(
                insert_data)

            print('processing epoch {} with data {}'.format(
                epoch_no, str(insert_data)))
        epoch_no = epoch_no + 1
Example #2
0
def new_graph_history_crawler():
    epoch_no = 2357
    while (epoch_no < 2440):
        data = False
        data = beacon.get_participation_rate(epoch=epoch_no)
        if data:
            participation = data.get('participation')
            epoch_timestamp = time_calculator.get_epoch_time(epoch_no)
            timestamp = datetime.datetime.strptime(epoch_timestamp,
                                                   '%Y-%m-%dT%H:%M:%SZ')
            obj_id = ObjectId.from_datetime(timestamp)
            data2 = beacon.get_active_validators_count(epoch=epoch_no)

            insert_data = {
                '_id': obj_id,
                'eligible_ether': participation.get('eligibleEther'),
                'epoch': int(data.get('epoch')),
                'timestamp': epoch_timestamp,
                'total_act_validators': data2
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.new_graph_data_altona.insert(insert_data)

            print('processing epoch {} with data {}'.format(
                epoch_no, str(insert_data)))
        epoch_no = epoch_no + 1
Example #3
0
def total_act_validators_script():
    try:
        print("#" * 30)
        print("Executing Total Active Validators Count")

        db_con = mongo_helper.mongo_conn()
        crawled_data = db_con.latest_block_altona.find_one(
            {}, sort=[('_id', pymongo.DESCENDING)])
        data = beacon.get_participation_rate()
        if data:
            data2 = beacon.get_active_validators_count_head()
            data = beacon.get_participation_rate()
            participation = data.get('participation')
            if crawled_data.get('epoch') == data.get('epoch'):
                raise ('skipping operation')
            insert_data = {
                'eligible_ether': participation.get('eligibleEther'),
                'epoch': int(data.get('epoch')),
                'timestamp':
                time_calculator.get_epoch_time(int(data.get('epoch'))),
                'total_act_validators': data2
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.new_graph_data_altona.insert(insert_data)
            print(db_status)
        else:
            print('No data')
            False

    except Exception as e:
        error = common.get_error_traceback(sys, e)
        print(error)
Example #4
0
def global_participation_script():
    try:
        print("#" * 30)
        print("Executing global_participation_script")

        db_con = mongo_helper.mongo_conn()
        crawled_data = db_con.latest_block_altona.find_one(
            {}, sort=[('_id', pymongo.DESCENDING)])
        data = beacon.get_participation_rate()

        if data:
            participation = data.get('participation')
            if crawled_data.get('epoch') == data.get('epoch'):
                raise ('skipping operation')

            insert_data = {
                'epoch':
                data.get('epoch'),
                'voted_ether':
                participation.get('votedEther'),
                'global_participation':
                participation.get('globalParticipationRate'),
                'eligible_ether':
                participation.get('eligibleEther'),
                'timestamp':
                time_calculator.get_epoch_time(int(data.get('epoch')))
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.global_participation_new_altona.insert(
                insert_data)
            print(db_status)
        else:
            print('No data')
            False

    except Exception as e:
        error = common.get_error_traceback(sys, e)
        print(error)
Example #5
0
def get_epoch_data(epoch_number):
    try:
        epoch_state = client_beacon_chain.GetChainHead()
        if not epoch_state:
            raise
        finalized_epoch = int(epoch_state.finalized_epoch)

        if int(epoch_number) <= finalized_epoch:
            finnalized =  True
        else:
            finnalized = False


        uri = '/eth/v1alpha1/beacon/blocks'
        url = base_url+uri

        response = http.request(
            'GET',
            url,
            fields={
                'epoch' : str(epoch_number)           
            } 
        )        

        
        if response.status == 200:
            block_data_ = json.loads(response.data.decode('UTF-8')) 
            block_container = block_data_.get('blockContainers')

            epoch_time = time_calculator.get_epoch_time(int(epoch_number))
            return_list = []

            return_data = {
                'epoch' : epoch_number,
                'time' : epoch_time,
                'blocks' : {
                    'proposed' : len(block_container),
                    'skipped' : 32 - len(block_container)
                }
            } 
            deposit_count = 0
            voluntry_exit_count = 0
            attester_slashing_count = 0
            proposer_slashing_count = 0
            attestations_count = 0

            for single_block_data in block_container:
               
                block_data = single_block_data.get('block')
                block_detail = block_data.get('block')
                block_body = block_detail.get('body')

                deposit_count = deposit_count + len(block_body.get('deposits'))
                voluntry_exit_count = voluntry_exit_count + len(block_body.get('voluntaryExits'))
                attester_slashing_count =  attester_slashing_count + len(block_body.get('attesterSlashings'))
                proposer_slashing_count = proposer_slashing_count + len(block_body.get('proposerSlashings'))
                attestations_count = attestations_count + len(block_body.get('attestations'))


            return_data.update({
                'deposits' : deposit_count,
                'voluntay_exists' : voluntry_exit_count,
                'slashing' : {
                    'proposer_slashing' : proposer_slashing_count,
                    'attester_slashing' : attester_slashing_count
                },
                'attestations' : attestations_count
            })

        uri = '/eth/v1alpha1/validators/participation'
        url = base_url+uri
        if not finnalized:
            response = http.request(
                'GET',
                url
            )
        else:
            response = http.request(
                        'GET',
                        url,
                        fields={
                            'epoch' : epoch_number
                        }                         
                    )            


        if response.status == 200:
            data = json.loads(response.data.decode('UTF-8'))        
            return_data['finalized'] = data.get('finalized')            
            voted_ether = float(data.get('participation').get('votedEther')) / 1000000000
            participation_rate = float(data.get('participation').get('globalParticipationRate')) * 100
            eligible_ether = float(data.get('participation').get('eligibleEther'))/1000000000

        return_data.update({
            'voted_ether' : voted_ether,
            'participation_rate' : participation_rate,
            'eligible_ether' : eligible_ether
        })

        uri = '/eth/v1alpha1/validators'
        url = base_url+uri
        validators = http.request(
            'GET',
            url,
            fields={
                'epoch' : epoch_number                         
            } 
        )

        if validators.status == 200:
            validators =  json.loads(validators.data.decode('UTF-8'))

            count = {
                'validator_count' : str(validators.get('totalSize'))
            }
            return_data.update(count)
        return common.send_sucess_msg(return_data)

        # else:
        #     return common.send_error_msg()

    except Exception as e:
        error = common.get_error_traceback(sys,e)
        print (error)
        return common.send_error_msg()