o
    ¢ØÆhï  ã                   @   s°   d dl mZmZmZmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZ G dd	„ d	ƒZG d
d„ deƒZG dd„ deƒZG dd„ deeƒZdS )é    )ÚAnyÚIterableÚTupleÚcast)Ú	DecodableÚTypeStr)ÚContextFramesBytesIOÚTupleDecoder)ÚTupleEncoder)ÚEncodingError)ÚABIRegistry)Úvalidate_bytes_paramÚvalidate_list_like_paramc                   @   s   e Zd ZdZdefdd„ZdS )ÚBaseABICoderz´
    Base class for porcelain coding APIs.  These are classes which wrap
    instances of :class:`~eth_abi.registry.ABIRegistry` to provide last-mile
    coding functionality.
    Úregistryc                 C   s
   || _ dS )z‰
        Constructor.

        :param registry: The registry providing the encoders to be used when
            encoding values.
        N)Ú	_registry)Úselfr   © r   úZ/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/eth_abi/codec.pyÚ__init__'   s   
zBaseABICoder.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r       s    r   c                   @   sV   e Zd ZdZdee dee defdd„Zdedede	fd	d
„Z
dede	fdd„ZdS )Ú
ABIEncoderzG
    Wraps a registry to provide last-mile encoding functionality.
    ÚtypesÚargsÚreturnc                    s8   t |dƒ t |dƒ ‡ fdd„|D ƒ}t|d�}||ƒS )a*  
        Encodes the python values in ``args`` as a sequence of binary values of
        the ABI types in ``types`` via the head-tail mechanism.

        :param types: A list or tuple of string representations of the ABI types
            that will be used for encoding e.g.  ``('uint256', 'bytes[]',
            '(int,int)')``
        :param args: A list or tuple of python values to be encoded.

        :returns: The head-tail encoded binary representation of the python
            values in ``args`` as values of the ABI types in ``types``.
        r   r   c                    s   g | ]}ˆ j  |¡‘qS r   )r   Úget_encoder©Ú.0Útype_str©r   r   r   Ú
<listcomp>G   s    z%ABIEncoder.encode.<locals>.<listcomp>)Úencoders)r   r
   )r   r   r   r$   Úencoderr   r"   r   Úencode6   s
   


zABIEncoder.encodeÚtypÚargc                 C   st   |   |¡sdS | j |¡}z| |¡ W dS  ty   Y dS  ty9   z||ƒ W Y dS  ty8   Y Y dS w w )aý  
        Determines if the python value ``arg`` is encodable as a value of the
        ABI type ``typ``.

        :param typ: A string representation for the ABI type against which the
            python value ``arg`` will be checked e.g. ``'uint256'``,
            ``'bytes[]'``, ``'(int,int)'``, etc.
        :param arg: The python value whose encodability should be checked.

        :returns: ``True`` if ``arg`` is encodable as a value of the ABI type
            ``typ``.  Otherwise, ``False``.
        FT)Úis_encodable_typer   r   Úvalidate_valuer   ÚAttributeError)r   r'   r(   r%   r   r   r   Úis_encodableM   s    
	øýÿýzABIEncoder.is_encodablec                 C   s   | j  |¡S )a’  
        Returns ``True`` if values for the ABI type ``typ`` can be encoded by
        this codec.

        :param typ: A string representation for the ABI type that will be
            checked for encodability e.g. ``'uint256'``, ``'bytes[]'``,
            ``'(int,int)'``, etc.

        :returns: ``True`` if values for ``typ`` can be encoded by this codec.
            Otherwise, ``False``.
        )r   Úhas_encoder)r   r'   r   r   r   r)   k   s   zABIEncoder.is_encodable_typeN)r   r   r   r   r   r   r   Úbytesr&   Úboolr,   r)   r   r   r   r   r   1   s
    r   c                   @   s>   e Zd ZdZeZ	ddee dede	de
edf fdd	„Zd
S )Ú
ABIDecoderzG
    Wraps a registry to provide last-mile decoding functionality.
    Tr   ÚdataÚstrictr   .c                    sR   t |dƒ t|dƒ ‡ ‡fdd„|D ƒ}t|d�}ˆ  |¡}tttdf ||ƒƒS )ak  
        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.
        :param strict: If ``False``, dynamic-type decoders will ignore validations such
            as making sure the data is padded to a multiple of 32 bytes or checking that
            padding bytes are zero / empty. ``False`` is how the Solidity ABI decoder
            currently works. However, ``True`` is the default for the eth-abi library.

        :returns: A tuple of equivalent python values for the ABI values
            represented in ``data``.
        r   r1   c                    s   g | ]
}ˆ j j|ˆd �‘qS ))r2   )r   Úget_decoderr   ©r   r2   r   r   r#   ›   s    ÿz%ABIDecoder.decode.<locals>.<listcomp>)Údecoders.)r   r   r	   Ústream_classr   r   r   )r   r   r1   r2   r5   ÚdecoderÚstreamr   r4   r   Údecode�   s   

ÿ

zABIDecoder.decodeN)T)r   r   r   r   r   r6   r   r   r   r/   r   r   r9   r   r   r   r   r0   z   s    üþýü
ûr0   c                   @   s   e Zd ZdS )ÚABICodecN)r   r   r   r   r   r   r   r:   ¥   s    r:   N)Útypingr   r   r   r   Úeth_typing.abir   r   Úeth_abi.decodingr   r	   Úeth_abi.encodingr
   Úeth_abi.exceptionsr   Úeth_abi.registryr   Úeth_abi.utils.validationr   r   r   r   r0   r:   r   r   r   r   Ú<module>   s    I+