From eadaea547f0a1f778ad3f9303387074914e8c628 Mon Sep 17 00:00:00 2001 From: fubuloubu <3859395+fubuloubu@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:47:16 -0400 Subject: [PATCH] refactor: make object type clearer when working with labels in middleware --- silverback/middlewares.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/silverback/middlewares.py b/silverback/middlewares.py index 44101d3f..9e369c84 100644 --- a/silverback/middlewares.py +++ b/silverback/middlewares.py @@ -67,18 +67,18 @@ def pre_execute(self, message: TaskiqMessage) -> TaskiqMessage: # Add extra labels for our task to see what their source was if task_type is TaskType.NEW_BLOCKS: # NOTE: Necessary because we don't know the exact block class - message.args[0] = self.provider.network.ecosystem.decode_block( + block = message.args[0] = self.provider.network.ecosystem.decode_block( hexbytes_dict(message.args[0]) ) - message.labels["block_number"] = str(message.args[0].number) - message.labels["block_hash"] = message.args[0].hash.hex() + message.labels["block_number"] = str(block.number) + message.labels["block_hash"] = block.hash.hex() elif task_type is TaskType.EVENT_LOG: # NOTE: Just in case the user doesn't specify type as `ContractLog` - message.args[0] = ContractLog.model_validate(message.args[0]) - message.labels["block_number"] = str(message.args[0].block_number) - message.labels["transaction_hash"] = message.args[0].transaction_hash - message.labels["log_index"] = str(message.args[0].log_index) + log = message.args[0] = ContractLog.model_validate(message.args[0]) + message.labels["block_number"] = str(log.block_number) + message.labels["transaction_hash"] = log.transaction_hash + message.labels["log_index"] = str(log.log_index) logger.debug(f"{self._create_label(message)} - Started") return message