From 35167ae84f211d22a59387c76dde20f2e67df8ae Mon Sep 17 00:00:00 2001 From: fubuloubu <3859395+fubuloubu@users.noreply.github.com> Date: Sun, 24 Nov 2024 13:58:54 -0500 Subject: [PATCH 1/2] refactor: use pydantic v2 API --- silverback/main.py | 4 +++- silverback/state.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/silverback/main.py b/silverback/main.py index eccedd5e..c403c448 100644 --- a/silverback/main.py +++ b/silverback/main.py @@ -125,7 +125,9 @@ def __init__(self, settings: Settings | None = None): ): settings.NEW_BLOCK_TIMEOUT = int(timedelta(days=1).total_seconds()) - settings_str = "\n ".join(f'{key}="{val}"' for key, val in settings.dict().items() if val) + settings_str = "\n ".join( + f'{key}="{val}"' for key, val in settings.model_dump().items() if val + ) logger.info(f"Loading Silverback Bot with settings:\n {settings_str}") self.broker = settings.get_broker() diff --git a/silverback/state.py b/silverback/state.py index 22591ffe..fe0914a6 100644 --- a/silverback/state.py +++ b/silverback/state.py @@ -46,7 +46,7 @@ async def init(self, bot_id: SilverbackID) -> StateSnapshot | None: self.state_backup_file = data_folder / "state.json" return ( - StateSnapshot.parse_file(self.state_backup_file) + StateSnapshot.model_validate_json(self.state_backup_file.read_text()) if self.state_backup_file.exists() else None ) From 2740493bef93b88f225ee97d16e9d73faee1b8e7 Mon Sep 17 00:00:00 2001 From: fubuloubu <3859395+fubuloubu@users.noreply.github.com> Date: Sun, 24 Nov 2024 13:59:30 -0500 Subject: [PATCH 2/2] fix: encode transaction hash correctly --- silverback/middlewares.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/silverback/middlewares.py b/silverback/middlewares.py index ef97206c..37fe5f09 100644 --- a/silverback/middlewares.py +++ b/silverback/middlewares.py @@ -24,12 +24,15 @@ def compute_block_time() -> int: self.block_time = self.chain_manager.provider.network.block_time or compute_block_time() def pre_send(self, message: TaskiqMessage) -> TaskiqMessage: - # TODO: Necessary because bytes/HexBytes doesn't encode/deocde well for some reason + # TODO: Necessary because bytes/HexBytes doesn't encode/decode well for some reason def fix_dict(data: dict, recurse_count: int = 0) -> dict: fixed_data: dict[str, Any] = {} for name, value in data.items(): if isinstance(value, bytes): fixed_data[name] = to_hex(value) + elif name == "transaction_hash" and isinstance(value, list): + # TODO: Why is it a list now? (as of Ape v0.8.19ish) + fixed_data[name] = to_hex(bytearray(value)) elif isinstance(value, dict): if recurse_count > 3: raise RecursionError("Event object is too deep")