Add support for AttributeDict and HexBytes serialization

This commit is contained in:
Luke Van Seters 2021-07-12 13:02:58 -04:00
parent 5e9c350b38
commit f0274fdfa8

View File

@ -1,6 +1,9 @@
import json
from typing import Dict, List, Optional from typing import Dict, List, Optional
from hexbytes import HexBytes
from pydantic import BaseModel from pydantic import BaseModel
from web3.datastructures import AttributeDict
class Block(BaseModel): class Block(BaseModel):
@ -12,6 +15,12 @@ class Block(BaseModel):
transaction_hashes: List[str] transaction_hashes: List[str]
txs_gas_data: Dict[str, dict] 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]: def get_filtered_calls(self, hash: str) -> List[dict]:
return [ return [
call for call in self.calls call for call in self.calls