示例#1
0
    def finalize_block(self, block_id, data):
        request = consensus_pb2.ConsensusFinalizeBlockRequest(
            data=data, block_id=block_id)

        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.BlockNotReady('Block not ready to be finalized')

        if status != response_type.OK:
            raise exceptions.ReceiveError(
                'Failed with status {}'.format(status))

        return response.block_id
示例#2
0
    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