def accumulation_hook(self, db_session): self.block.count_log = len(self.block.logs) for idx, log_data in enumerate(self.block.logs): log_digest = LogDigest(ScaleBytes(log_data)) log_digest.decode() log = Log( block_id=self.block.id, log_idx=idx, type_id=log_digest.index, type=log_digest.index_value, data=log_digest.value, ) if log.type == 'PreRuntime': if log.data['value']['engine'] == 'BABE': # Determine block producer self.block.authority_index = log.data['value']['data']['authorityIndex'] self.block.slot_number = log.data['value']['data']['slotNumber'] if log.data['value']['engine'] == 'aura': self.block.slot_number = log.data['value']['data']['slotNumber'] log.save(db_session)
def accumulation_hook(self, db_session): self.block.count_log = len(self.block.logs) for idx, log_data in enumerate(self.block.logs): log_digest = LogDigest(ScaleBytes(log_data)) log_digest.decode() if log_digest.index_value == "PreRuntime": data = log_digest.value.get('value').get('data') if data: res = RawBabePreDigest(ScaleBytes("0x{}".format(data))) if data[0:2] == "01" and len(data) == 34: res.decode() self.block.account_index = res.value.get("Secondary").get("authorityIndex") else: res.decode(check_remaining=False) self.block.account_index = res.value.get("Primary").get("authorityIndex") self.block.save(db_session) log = Log( block_id=self.block.id, log_idx=idx, type_id=log_digest.index, type=log_digest.index_value, data=log_digest.value, ) log.save(db_session)
def accumulation_hook(self, db_session): self.block.count_log = len(self.block.logs) for idx, log_data in enumerate(self.block.logs): log_digest = LogDigest(ScaleBytes(log_data)) log_digest.decode() log = Log( block_id=self.block.id, log_idx=idx, type_id=log_digest.index, type=log_digest.index_value, data=log_digest.value, ) if log.type == 'PreRuntime': if log.data['value']['engine'] == 'BABE': # Determine block producer babe_predigest_cls = RuntimeConfiguration( ).get_decoder_class('RawBabePreDigest') babe_predigest = babe_predigest_cls( ScaleBytes( bytearray.fromhex( log.data['value']['data'].replace( '0x', '')))).decode() if len(list(babe_predigest.values())) > 0: babe_predigest_value = list(babe_predigest.values())[0] log.data['value']['data'] = babe_predigest_value self.block.authority_index = log.data['value']['data'][ 'authorityIndex'] self.block.slot_number = log.data['value']['data'][ 'slotNumber'] if log.data['value']['engine'] == 'aura': aura_predigest_cls = RuntimeConfiguration( ).get_decoder_class('RawAuraPreDigest') aura_predigest = aura_predigest_cls( ScaleBytes( bytearray.fromhex( log.data['value']['data'].replace( '0x', '')))).decode() log.data['value']['data'] = aura_predigest self.block.slot_number = aura_predigest['slotNumber'] log.save(db_session)
def accumulation_hook(self, db_session): self.block.count_log = len(self.block.logs) for idx, log_data in enumerate(self.block.logs): log_digest = LogDigest(ScaleBytes(log_data)) log_digest.decode() log = Log( block_id=self.block.id, log_idx=idx, type_id=log_digest.index, type=log_digest.index_value, data=log_digest.value, ) log.save(db_session)
def accumulation_hook(self, db_session): #print('start add_block Process block processors {} =='.format("Process block log processors")) self.block.count_log = len(self.block.logs) if self.block.count_log != 0: for idx, log_data in enumerate(self.block.logs): if idx == 1: num = log_data.index('03000000000000000000') final = '0x' + log_data[20 + num:] oy = ScaleDecoder.get_decoder_class( 'Vec<(SessionKey, u64)>', ScaleBytes(final)) oy.decode() for i in range(len(oy.value)): oy.value[i] = "{'authoritiy': '" + oy.value[i][ "col1"] + "', 'weight': " + str( oy.value[i]["col2"]) + "}" log = Log( block_id=self.block.bid, log_idx=1, type_id=0, type='Other', data=oy.value, shard_num=self.block.shard_num, ) else: log_digest = LogDigest(ScaleBytes(log_data)) log_digest.decode() log = Log( block_id=self.block.bid, log_idx=idx, type_id=log_digest.index, type=log_digest.index_value, data=log_digest.value, shard_num=self.block.shard_num, ) log.save(db_session)