diff --git a/eth_abi/codec.py b/eth_abi/codec.py index 144ce43c..ca606920 100644 --- a/eth_abi/codec.py +++ b/eth_abi/codec.py @@ -28,12 +28,9 @@ ) -class ABICodec(): - def __init__(self, registry: ABIRegistry=None): - if registry is None: - self._registry = default_registry - else: - self._registry = registry +class BaseABICodecEncoder(): + def __init__(self, registry): + self._registry = registry def encode_single(self, typ: TypeStr, arg: Any) -> bytes: """ @@ -98,6 +95,14 @@ def is_encodable(self, typ: TypeStr, arg: Any) -> bool: return True + +class ABICodec(BaseABICodecEncoder): + def __init__(self, registry: ABIRegistry=None): + if registry is None: + BaseABICodecEncoder.__init__(self, default_registry) + else: + BaseABICodecEncoder.__init__(self, registry) + def decode_single(self, typ: TypeStr, data: Decodable) -> Any: """ Decodes the binary value ``data`` of the ABI type ``typ`` into its diff --git a/eth_abi/codec_packed.py b/eth_abi/codec_packed.py index 38eda558..e97f72fa 100644 --- a/eth_abi/codec_packed.py +++ b/eth_abi/codec_packed.py @@ -1,17 +1,7 @@ -from typing import ( - Any, - Iterable, - Tuple, -) import warnings -from eth_typing.abi import ( - Decodable, - TypeStr, -) - from eth_abi.codec import ( - ABICodec, + BaseABICodecEncoder, ) from eth_abi.registry import ( ABIRegistry, @@ -24,18 +14,9 @@ ) -class ABICodecPacked(ABICodec): +class ABICodecPacked(BaseABICodecEncoder): def __init__(self, registry: ABIRegistry=None): if registry is None: - ABICodec.__init__(self, default_packed_registry) + BaseABICodecEncoder.__init__(self, default_packed_registry) else: - ABICodec.__init__(self, registry) - - def is_encodable(self, typ: TypeStr, arg: Any) -> bool: - raise NotImplementedError("'is_encodable' is not supported in packed mode") - - def decode_single(self, typ: TypeStr, data: Decodable) -> Any: - raise NotImplementedError("'decode_single' is not supported in packed mode") - - def decode_abi(self, types: Iterable[TypeStr], data: Decodable) -> Tuple[Any, ...]: - raise NotImplementedError("'decode_abi' is not supported in packed mode") + BaseABICodecEncoder.__init__(self, registry) diff --git a/eth_abi/packed.py b/eth_abi/packed.py index a701b76d..e7e9906d 100644 --- a/eth_abi/packed.py +++ b/eth_abi/packed.py @@ -6,3 +6,4 @@ encode_single_packed = default_codec_packed.encode_single encode_abi_packed = default_codec_packed.encode_abi +is_encodable_packed = default_codec_packed.is_encodable