def decode_abi(self, types: Iterable[TypeStr],
                   data: Decodable) -> Tuple[Any, ...]:
        """
        Decodes the binary value ``data`` as a sequence of values of the ABI types
        in ``types`` via the head-tail mechanism into a tuple of equivalent python
        values.

        :param types: An iterable of string representations of the ABI types that
            will be used for decoding e.g. ``('uint256', 'bytes[]', '(int,int)')``
        :param data: The binary value to be decoded.

        :returns: A tuple of equivalent python values for the ABI values
            represented in ``data``.
        """
        if not is_bytes(data):
            raise TypeError(
                "The `data` value must be of bytes type.  Got {0}".format(
                    type(data)))

        decoders = [self._registry.get_decoder(type_str) for type_str in types]

        decoder = TupleDecoder(decoders=decoders)
        stream = self.stream_class(data)

        return decoder(stream)
Example #2
0
def decode_abi(types, data):
    if not is_bytes(data):
        raise TypeError(
            "The `data` value must be of bytes type.  Got {0}".format(
                type(data)))

    decoders = [registry.get_decoder(type_str) for type_str in types]

    decoder = TupleDecoder(decoders=decoders)
    stream = ContextFramesBytesIO(data)

    return decoder(stream)
Example #3
0
    def decode(self, types: Iterable[TypeStr],
               data: Decodable) -> Tuple[Any, ...]:
        """
        Decodes the binary value ``data`` as a sequence of values of the ABI types
        in ``types`` via the head-tail mechanism into a tuple of equivalent python
        values.

        :param types: A list or tuple of string representations of the ABI types that
            will be used for decoding e.g. ``('uint256', 'bytes[]', '(int,int)')``
        :param data: The binary value to be decoded.

        :returns: A tuple of equivalent python values for the ABI values
            represented in ``data``.
        """
        validate_list_like_param(types, 'types')
        validate_bytes_param(data, 'data')

        decoders = [self._registry.get_decoder(type_str) for type_str in types]

        decoder = TupleDecoder(decoders=decoders)
        stream = self.stream_class(data)

        return decoder(stream)
def test_tuple_decoder(types, data, expected):
    decoders = [registry.get_decoder(t) for t in types]
    decoder = TupleDecoder(decoders=decoders)
    stream = ContextFramesBytesIO(decode_hex(data))
    actual = decoder(stream)
    assert actual == expected