def initialize_block(self, previous_id): request = ( consensus_pb2.ConsensusInitializeBlockRequest( previous_id=previous_id) if previous_id else consensus_pb2.ConsensusInitializeBlockRequest() ) response_type = consensus_pb2.ConsensusInitializeBlockResponse response = self._send( request=request, message_type=Message.CONSENSUS_INITIALIZE_BLOCK_REQUEST, response_type=response_type) status = response.status if status == response_type.INVALID_STATE: raise exceptions.InvalidState( 'Cannot initialize block in current state') if status == response_type.UNKNOWN_BLOCK: raise exceptions.UnknownBlock() if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status))
def finalize_block(self, data): request = consensus_pb2.ConsensusFinalizeBlockRequest(data=data) response_type = consensus_pb2.ConsensusFinalizeBlockResponse response = self._send( request=request, message_type=Message.CONSENSUS_FINALIZE_BLOCK_REQUEST, response_type=response_type) status = response.status if status == response_type.INVALID_STATE: raise exceptions.InvalidState( 'Cannot finalize block in current state') if status == response_type.BLOCK_NOT_READY: raise exceptions.BLOCK_NOT_READY( 'Block not ready to be finalized') if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status)) return response.block_id
def cancel_block(self): request = consensus_pb2.ConsensusCancelBlockRequest() response_type = consensus_pb2.ConsensusCancelBlockResponse response = self._send( request=request, message_type=Message.CONSENSUS_CANCEL_BLOCK_REQUEST, response_type=response_type) status = response.status if status == response_type.INVALID_STATE: raise exceptions.InvalidState( 'Cannot cancel block in current state') if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status))
def summarize_block(self): request = consensus_pb2.ConsensusSummarizeBlockRequest() response_type = consensus_pb2.ConsensusSummarizeBlockResponse response = self._send( request=request, message_type=Message.CONSENSUS_SUMMARIZE_BLOCK_REQUEST, response_type=response_type) status = response.status if status == response_type.INVALID_STATE: raise exceptions.InvalidState( 'Cannot summarize block in current state') if status == response_type.BLOCK_NOT_READY: raise exceptions.BlockNotReady('Block not ready to be summarize') if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status)) return response.summary