Exemple #1
0
    def _handle_state_update_message(self, state_update_message: StateUpdateMessage) -> None:
        """
        Handle a state update message.

        :param state_update_message: the state update message
        :return: None
        """
        assert self._ownership_state is None, "OwnershipState already initialized."
        assert self._preferences is None, "Preferences already initialized."
        currency_endowment = cast(CurrencyEndowment, state_update_message.get("currency_endowment"))
        good_endowment = cast(GoodEndowment, state_update_message.get("good_endowment"))
        self.ownership_state.init(currency_endowment=currency_endowment, good_endowment=good_endowment)
        utility_params = cast(UtilityParams, state_update_message.get("utility_params"))
        exchange_params = cast(ExchangeParams, state_update_message.get("exchange_params"))
        self.preferences.init(exchange_params=exchange_params, utility_params=utility_params)
Exemple #2
0
    def _handle_state_update_message(
            self, state_update_message: StateUpdateMessage) -> None:
        """
        Handle a state update message.

        :param state_update_message: the state update message
        :return: None
        """
        performative = state_update_message.get("performative")
        if performative == StateUpdateMessage.Performative.INITIALIZE:
            amount_by_currency = cast(
                Dict[str, int], state_update_message.get("amount_by_currency"))
            quantities_by_good_pbk = cast(
                Dict[str, int],
                state_update_message.get("quantities_by_good_pbk"))
            self.ownership_state.init(
                amount_by_currency=amount_by_currency,
                quantities_by_good_pbk=quantities_by_good_pbk,
                agent_name=self._agent_name)
            exchange_params_by_currency = cast(
                Dict[str, float],
                state_update_message.get("exchange_params_by_currency"))
            utility_params_by_good_pbk = cast(
                Dict[str, float],
                state_update_message.get("utility_params_by_good_pbk"))
            tx_fee = cast(int, state_update_message.get("tx_fee"))
            self.preferences.init(
                exchange_params_by_currency=exchange_params_by_currency,
                utility_params_by_good_pbk=utility_params_by_good_pbk,
                tx_fee=tx_fee,
                agent_name=self._agent_name)
            self.goal_pursuit_readiness.update(
                GoalPursuitReadiness.Status.READY)
        elif performative == StateUpdateMessage.Performative.APPLY:
            amount_by_currency = cast(
                Dict[str, int], state_update_message.get("amount_by_currency"))
            quantities_by_good_pbk = cast(
                Dict[str, int],
                state_update_message.get("quantities_by_good_pbk"))
            new_ownership_state = self.ownership_state.apply_state_update(
                amount_deltas_by_currency=amount_by_currency,
                quantity_deltas_by_good_pbk=quantities_by_good_pbk)
            self._ownership_state = new_ownership_state