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

feat: pydantic refactor #71

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions evm_trace/geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Iterator
from typing import Optional

from eth_pydantic_types import HashBytes20, HexBytes
from eth_pydantic_types import HexBytes20, HexBytes
from eth_utils import to_hex, to_int
from pydantic import Field, RootModel, field_validator

Expand Down Expand Up @@ -49,15 +49,15 @@ class TraceFrame(BaseModel):
storage: dict[HexBytes, HexBytes] = {}
"""Contract storage."""

contract_address: Optional[HashBytes20] = None
contract_address: Optional[HexBytes20] = None
"""The address producing the frame."""

@field_validator("pc", "gas", "gas_cost", "depth", mode="before")
def validate_ints(cls, value):
return int(value, 16) if isinstance(value, str) else value

@property
def address(self) -> Optional[HashBytes20]:
def address(self) -> Optional[HexBytes20]:
"""
The address of this CALL frame.
Only returns a value if this frame's opcode is a call-based opcode.
Expand All @@ -66,7 +66,7 @@ def address(self) -> Optional[HashBytes20]:
if not self.contract_address and (
self.op in CALL_OPCODES and CallType.CREATE.value not in self.op
):
self.contract_address = HashBytes20.__eth_pydantic_validate__(self.stack[-2][-20:])
self.contract_address = HexBytes20.__eth_pydantic_validate__(self.stack[-2][-20:])

return self.contract_address

Expand Down Expand Up @@ -116,7 +116,7 @@ def _get_create_frames(frame: TraceFrame, frames: Iterator[dict]) -> list[TraceF
# the first frame after the CREATE with an equal depth.
if len(next_frame_obj.stack) > 0:
raw_addr = HexBytes(next_frame_obj.stack[-1][-40:])
frame.contract_address = HashBytes20.__eth_pydantic_validate__(raw_addr)
frame.contract_address = HexBytes20.__eth_pydantic_validate__(raw_addr)

create_frames.append(next_frame_obj)
break
Expand Down Expand Up @@ -274,7 +274,7 @@ def _create_node(
node_kwargs["last_create_depth"].pop()
for subcall in node_kwargs.get("calls", [])[::-1]:
if subcall.call_type in (CallType.CREATE, CallType.CREATE2):
subcall.address = HashBytes20.__eth_pydantic_validate__(frame.stack[-1][-40:])
subcall.address = HexBytes20.__eth_pydantic_validate__(frame.stack[-1][-40:])
if len(frame.stack) >= 5:
subcall.calldata = frame.memory.get(frame.stack[-4], frame.stack[-5])

Expand Down
Loading