o
    ¢ØÆhý  ã                   @   s†   d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlZe jdkr2d dlmZ nd dlmZ G dd	„ d	ejƒZdS )
é    N)ÚAnyÚDictÚUnionÚcast)Úkeccak)Úpipe)ÚHexBytes)é   é   )ÚSelfc                       sŠ   e Zd ZdZedeeef defdd„ƒZ	ede
eef defdd„ƒZdefd	d
„Zdef‡ fdd„Zdeeef f‡ fdd„Z‡  ZS )ÚHashableRLPaç  
    An extension of :class:`rlp.Serializable`. In addition to the below
    functions, the class is iterable.

    Use like:

    ::

        class MyRLP(HashableRLP):
            fields = (
                ('name1', rlp.sedes.big_endian_int),
                ('name2', rlp.sedes.binary),
                etc...
            )

        my_obj = MyRLP(name2=b'\xff', name1=1)
        list(my_obj) == [1, b'\xff']
        # note that the iteration order is always in RLP-defined order
    Ú
field_dictÚreturnc                 C   s   | di |¤ŽS )aì  
        In addition to the standard initialization of.

        ::

            my_obj = MyRLP(name1=1, name2=b'\xff')

        This method enables initialization with.

        ::

            my_obj = MyRLP.from_dict({'name1': 1, 'name2': b'\xff'})

        In general, the standard initialization is preferred, but
        some approaches might favor this API, like when using
        :meth:`toolz.functoolz.pipe`.

        ::

            return eth_utils.toolz.pipe(
                my_dict,
                normalize,
                validate,
                MyRLP.from_dict,
            )

        :param dict field_dict: the dictionary of values to initialize with
        :returns: the new rlp object
        :rtype: HashableRLP
        N© r   )Úclsr   r   r   úY/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/eth_rlp/main.pyÚ	from_dict3   s    zHashableRLP.from_dictÚserialized_bytesc                 C   s   t  || ¡}tt|ƒS )zÑ
        Shorthand invocation for :meth:`rlp.decode` using this class.

        :param bytes serialized_bytes: the byte string to decode
        :return: the decoded object
        :rtype: HashableRLP
        )ÚrlpÚdecoder   r   )r   r   Údecodedr   r   r   Ú
from_bytesU   s   	
zHashableRLP.from_bytesc                 C   s   t t| tjtƒƒS )zf
        :returns: the hash of the encoded bytestring
        :rtype: ~hexbytes.main.HexBytes
        )r   r   r   Úencoder   ©Úselfr   r   r   Úhasha   s   ýÿzHashableRLP.hashc                    s,   t ˆ dƒrt‡ fdd„ˆ jD ƒƒS tƒ  ¡ S )NÚfieldsc                 3   s   � | ]
\}}t ˆ |ƒV  qd S )N)Úgetattr)Ú.0ÚfieldÚ_r   r   r   Ú	<genexpr>p   s   € z'HashableRLP.__iter__.<locals>.<genexpr>)ÚhasattrÚiterr   ÚsuperÚ__iter__r   ©Ú	__class__r   r   r%   n   s   

zHashableRLP.__iter__c                    sL   zt ƒ  ¡ }ttttf |ƒW S  ty%   t| ƒ}ttttf |ƒ Y S w )z�
        Convert rlp object to a dict

        :returns: mapping of RLP field names to field values
        :rtype: dict
        )r$   Úas_dictr   r   Ústrr   ÚAttributeErrorÚvars)r   Ú_as_dictr&   r   r   r(   t   s   
þzHashableRLP.as_dict)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr   r)   r   r   r   r   ÚbytesÚ	bytearrayr   r   r   r%   r(   Ú__classcell__r   r   r&   r   r      s    !"r   )ÚsysÚtypingr   r   r   r   Ú	eth_utilsr   Úeth_utils.toolzr   Úhexbytesr   r   Úversion_infor   Útyping_extensionsÚSerializabler   r   r   r   r   Ú<module>   s    
