ethereum / eth-abi

Ethereum ABI utilities for python
MIT License
247 stars 269 forks source link

Export ABI Types #150

Open fubuloubu opened 3 years ago

fubuloubu commented 3 years ago

It would be handy to be able to leverage this package to create type hints for other packages that describe restrictions in abi types for different purposes, e.g. https://github.com/ApeWorX/eip712 where we currently use is_encodeable_type to parse a deferred type when describing an EIP-712 structured message like so:

class Order(EIP712Message):
    a: "address"  # implicit validation using `eth_abi.is_encodeable_type`

It would be much nicer if all of the registered types were made available in mypy-compliant form to use for type checking code as follows:

from eth_abi.types import address

class Order(EIP712Message):
    a: address  # explicit validation provided by eth_abi

Ideally, these types would work as aliases for int, Decimal, str, bytes, etc., doing the proper size and bounds checks as well (or at least allowing us to perform that validation easily) to make it easier to integrate this work into other libraries.

kclowes commented 2 years ago

@fubuloubu I just came across this - does the eth-typing library solve this?

fubuloubu commented 2 years ago

@fubuloubu I just came across this - does the eth-typing library solve this?

No, not quite. My thinking was to be able to say things like this:

class Order(EIP712Message):
    a: abi_types.address
    b: abi_types.bytes32
    c: abi_types.array[abi_types.uint256]