From f0274fdfa84bc7a3c5296c56cba708e4a91cbfc8 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Mon, 12 Jul 2021 13:02:58 -0400 Subject: [PATCH] Add support for AttributeDict and HexBytes serialization --- schemas/blocks.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/schemas/blocks.py b/schemas/blocks.py index 66851b9..35aa340 100644 --- a/schemas/blocks.py +++ b/schemas/blocks.py @@ -1,6 +1,9 @@ +import json from typing import Dict, List, Optional +from hexbytes import HexBytes from pydantic import BaseModel +from web3.datastructures import AttributeDict class Block(BaseModel): @@ -12,6 +15,12 @@ class Block(BaseModel): transaction_hashes: List[str] txs_gas_data: Dict[str, dict] + class Config: + json_encoders = { + AttributeDict: dict, + HexBytes: lambda h: h.hex(), + } + def get_filtered_calls(self, hash: str) -> List[dict]: return [ call for call in self.calls