def get_error_message(
        self,
        e: Exception,
        api: LedgerApi,
        message: Message,
        dialogue: BaseDialogue,
    ) -> ContractApiMessage:
        """
        Build an error message.

        :param e: the exception.
        :param api: the Ledger API.
        :param message: the request message.
        :return: an error message response.
        """
        response = cast(
            ContractApiMessage,
            dialogue.reply(
                performative=ContractApiMessage.Performative.ERROR,
                target_message=message,
                code=500,
                message=str(e),
                data=b"",
            ),
        )
        return response
Ejemplo n.º 2
0
    def __init__(
        self,
        dialogue_label: DialogueLabel,
        self_address: Address,
        role: Dialogue.Role,
        message_class: Type[TProtocolMessage] = TProtocolMessage,
    ) -> None:
        """
        Initialize a dialogue.

        :param dialogue_label: the identifier of the dialogue
        :param self_address: the address of the entity for whom this dialogue is maintained
        :param role: the role of the agent this dialogue is maintained for
        :return: None
        """
        Dialogue.__init__(
            self,
            dialogue_label=dialogue_label,
            message_class=message_class,
            self_address=self_address,
            role=role,
        )
Ejemplo n.º 3
0
    def build_incoming_message_for_skill_dialogue(
        self,
        dialogue: Dialogue,
        performative: Message.Performative,
        message_type: Optional[Type[Message]] = None,
        dialogue_reference: Optional[Tuple[str, str]] = None,
        message_id: Optional[int] = None,
        target: Optional[int] = None,
        to: Optional[Address] = None,
        sender: Optional[Address] = None,
        **kwargs: Any,
    ) -> Message:
        """
        Quickly create an incoming message with the provided attributes for a dialogue.

        For any attribute not provided, a value based on the dialogue is used.
        These values are shown in parantheses in the list of parameters below.

        NOTE: This method must be used with care. The dialogue provided is part of the skill
        which is being tested. Because for any unspecified attribute, a "correct" value is used,
        the test will be, by design, insured to pass on these values.

        :param dialogue: the dialogue to which the incoming message is intended
        :param performative: the performative of the message
        :param message_type: (the message_class of the provided dialogue) the type of the message
        :param dialogue_reference: (the dialogue_reference of the provided dialogue) the dialogue reference of the message
        :param message_id: (the id of the last message in the provided dialogue + 1) the id of the message
        :param target: (the id of the last message in the provided dialogue) the target of the message
        :param to: (the agent address associated with this skill) the receiver of the message
        :param sender: (the counterperty in the provided dialogue) the sender of the message
        :param kwargs: other attributes

        :return: the created incoming message
        """
        if dialogue is None:
            raise AEAEnforceError("dialogue cannot be None.")

        if dialogue.last_message is None:
            raise AEAEnforceError("dialogue cannot be empty.")

        message_type = (
            message_type if message_type is not None else dialogue.message_class
        )
        dialogue_reference = (
            dialogue_reference
            if dialogue_reference is not None
            else dialogue.dialogue_label.dialogue_reference
        )
        message_id = (
            message_id
            if message_id is not None
            else dialogue.get_incoming_next_message_id()
        )
        target = target if target is not None else dialogue.last_message.message_id
        to = to if to is not None else dialogue.self_address
        sender = (
            sender
            if sender is not None
            else dialogue.dialogue_label.dialogue_opponent_addr
        )

        incoming_message = self.build_incoming_message(
            message_type=message_type,
            performative=performative,
            dialogue_reference=dialogue_reference,
            message_id=message_id,
            target=target,
            to=to,
            sender=sender,
            **kwargs,
        )
        return incoming_message