def __getitem__(self, block_id): """Return the consensus state corresponding to the block ID Args: block_id (str): The ID of the block for which consensus state is being requested Returns: ConsensusState object Raises: KeyError if the block ID is not in the store """ serialized_consensus_state = self._store_db[block_id] if serialized_consensus_state is None: raise KeyError('Block ID {} not found'.format(block_id)) try: consensus_state = ConsensusState() consensus_state.parse_from_bytes( buffer=serialized_consensus_state) return consensus_state except ValueError as error: raise \ KeyError( 'Cannot return block with ID {}: {}'.format( block_id, error))
def __str__(self): out = [] for block_id in self._store_db.keys(): try: serialized_consensus_state = self._store_db[block_id] consensus_state = ConsensusState() consensus_state.parse_from_bytes( buffer=serialized_consensus_state) out.append('{}...{}: {{{}}}'.format(block_id[:8], block_id[-8:], consensus_state)) except ValueError: pass return ', '.join(out)
def __str__(self): out = [] for block_id in self._store_db.keys(): try: serialized_consensus_state = self._store_db[block_id] consensus_state = ConsensusState() consensus_state.parse_from_bytes( buffer=serialized_consensus_state) out.append( '{}...{}: {{{}}}'.format( block_id[:8], block_id[-8:], consensus_state)) except ValueError: pass return ', '.join(out)