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: implement cchecksum for ~2x faster checksumming #17

Merged
merged 9 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
14 changes: 3 additions & 11 deletions eth_pydantic_types/address.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from functools import cached_property
from typing import TYPE_CHECKING, Annotated, Any, ClassVar, Optional

from cchecksum import to_checksum_address
from pydantic_core.core_schema import ValidationInfo, str_schema

from eth_pydantic_types.hash import HashStr20
Expand Down Expand Up @@ -36,23 +37,14 @@ def __eth_pydantic_validate__(cls, value: Any, info: Optional[ValidationInfo] =

@classmethod
def to_checksum_address(cls, value: str) -> "ChecksumAddress":
# perf: eth_utils imports are too slow. Hence they are localized.
from eth_utils import is_checksum_address, to_checksum_address

if is_checksum_address(value):
return value # type: ignore[return-value]

else:
return to_checksum_address(value)
return to_checksum_address(value)


class _AddressTypeFactory:
@cached_property
def address_type(self):
from eth_typing import ChecksumAddress

# Lazy define for performance reasons.
AddressType = Annotated[ChecksumAddress, Address]
AddressType = Annotated["ChecksumAddress", Address]
AddressType.__doc__ = """
A type that can be used in place of ``eth_typing.ChecksumAddress``.

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
url="https://github.com/ApeWorX/eth-pydantic-types",
include_package_data=True,
install_requires=[
"cchecksum>=0.0.3,<1",
"hexbytes>=0.3.1,<2",
"eth-utils>=2.3.1,<6",
"eth-typing>=3.5.2,<6",
Expand Down
Loading