Skip to content

Commit

Permalink
refactor: make object type clearer when working with labels in middle…
Browse files Browse the repository at this point in the history
…ware
  • Loading branch information
fubuloubu committed Apr 10, 2024
1 parent c177a94 commit eadaea5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions silverback/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eadaea5

Please sign in to comment.