Skip to content

Commit

Permalink
chore: updates HashBytes to HexBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwise-constructs committed Oct 14, 2024
1 parent af95600 commit 6044a64
Showing 1 changed file with 6 additions and 6 deletions.
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

0 comments on commit 6044a64

Please sign in to comment.