From 06926b6944c9ce5e6b8fd6651ae3841a586f2d82 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Thu, 2 Nov 2023 17:12:14 +0200 Subject: [PATCH] feat: allow for both a message and a result from a contract --- .../decision_maker_abci/behaviours/base.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/base.py b/packages/valory/skills/decision_maker_abci/behaviours/base.py index f3281e9da..2ae3fd8f5 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/base.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/base.py @@ -362,20 +362,21 @@ def default_error( f"using {contract_callable!r}: {response_msg}" ) - def contract_interaction_error( - self, contract_id: str, contract_callable: str, response_msg: ContractApiMessage - ) -> None: - """Return a contract interaction error message.""" - # contracts can only return one message, i.e., multiple levels cannot exist. + def _propagate_contract_messages(self, response_msg: ContractApiMessage) -> None: + """Propagate the contract's message to the logger, if exists. + + Contracts can only return one message at a time. + + :param response_msg: the response message from the contract method. + :return: None + """ for level in ("info", "warning", "error"): msg = response_msg.raw_transaction.body.get(level, None) - logger = getattr(self.context.logger, level) if msg is not None: + logger = getattr(self.context.logger, level) logger(msg) return - self.default_error(contract_id, contract_callable, response_msg) - def contract_interact( self, performative: ContractApiMessage.Performative, @@ -399,11 +400,11 @@ def contract_interact( self.default_error(contract_id, contract_callable, response_msg) return False + self._propagate_contract_messages(response_msg) + data = response_msg.raw_transaction.body.get(data_key, None) if data is None: - self.contract_interaction_error( - contract_id, contract_callable, response_msg - ) + self.default_error(contract_id, contract_callable, response_msg) return False setattr(self, placeholder, data)