Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pydantic v2 API; incorrect encoding #175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion silverback/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion silverback/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion silverback/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Loading