Skip to content

Commit

Permalink
Added support for is_encodable in packed codec
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmendoza committed Nov 24, 2018
1 parent ecece6d commit abceb18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
17 changes: 11 additions & 6 deletions eth_abi/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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
Expand Down
27 changes: 4 additions & 23 deletions eth_abi/codec_packed.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
1 change: 1 addition & 0 deletions eth_abi/packed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit abceb18

Please sign in to comment.