Skip to content

Commit 6c50bd0

Browse files
committed
fix(Client): gateway API uses complex object for addresses now
1 parent 8ed929e commit 6c50bd0

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

ape_safe/client/types.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
from datetime import datetime, timezone
22
from enum import Enum
3-
from typing import NewType, Optional, Union, cast
3+
from typing import Annotated, NewType, Optional, Union, cast
44

55
from ape.types import AddressType, HexBytes
66
from eip712.common import SafeTxV1, SafeTxV2
77
from eth_typing import HexStr
88
from eth_utils import add_0x_prefix, to_hex
9-
from pydantic import BaseModel, Field
9+
from pydantic import BaseModel, BeforeValidator, Field, field_validator
1010

1111
from ape_safe.utils import get_safe_tx_hash
1212

1313
SafeTx = Union[SafeTxV1, SafeTxV2]
1414
SafeTxID = NewType("SafeTxID", str)
1515

1616

17+
def clean_api_address(data: AddressType | dict) -> AddressType:
18+
# NOTE: Safe API returns `{'value':'<addr>', ...}` object
19+
if isinstance(data, dict):
20+
return data["value"]
21+
return data
22+
23+
24+
Address = Annotated[AddressType, BeforeValidator(clean_api_address)]
25+
26+
1727
class SafeDetails(BaseModel):
18-
address: AddressType
28+
address: Address
1929
nonce: int
2030
threshold: int
21-
owners: list[AddressType]
22-
master_copy: AddressType = Field(alias="masterCopy")
23-
modules: list[AddressType]
24-
fallback_handler: AddressType = Field(alias="fallbackHandler")
31+
owners: list[Address]
32+
master_copy: Address = Field(alias="implementation")
33+
modules: list[Address] = []
34+
fallback_handler: Address = Field(alias="fallbackHandler")
2535
guard: AddressType
2636
version: str
2737

38+
@field_validator("modules", mode="before")
39+
def convert_none_to_empty_list(cls, value):
40+
if not value:
41+
return []
42+
return value
43+
2844

2945
class SignatureType(str, Enum):
3046
APPROVED_HASH = "APPROVED_HASH"

0 commit comments

Comments
 (0)