o
    ¢ØÆhò  ã                
   @   sª  d dl mZmZmZmZmZ d dlmZmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZmZmZ ddlmZmZmZ edƒZeeeef Ze
						dd
ee dee dee defdd„ƒZe
						dd
ee dee dee defdd„ƒZe
						dd
ee dee dee de fdd„ƒZ!e
						dd
ee dee dee defdd„ƒZ"dedef dee eef defdd„Z#dedef dee eef defdd„Z$d	S )é    )ÚCallableÚOptionalÚTypeVarÚUnionÚcast)ÚHexStrÚ
Primitivesé   )Úvalidate_conversion_arguments)Úbig_endian_to_intÚint_to_big_endian)Úadd_0x_prefixÚ
decode_hexÚ
encode_hexÚ	is_hexstrÚremove_0x_prefix)Ú
is_booleanÚ
is_integerÚ	is_stringÚTNÚ	primitiveÚhexstrÚtextÚreturnc                 C   s¸   |durt t| ¡ ƒƒS |durt| d¡ƒS t| ƒr%| r!tdƒS tdƒS t| ttfƒr0t| ƒS t| t	ƒr;tt| ƒƒS t
| ƒrCtdƒ‚t| ƒrPtttt| ƒƒƒS tdtt| ƒƒ› d�ƒ‚)z¶
    Auto converts any supported value into its hex representation.
    Trims leading zeros, as defined in:
    https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding
    Núutf-8Ú0x1Ú0x0zaUnsupported type: The primitive argument must be one of: bytes,bytearray, int or bool and not strzUnsupported type: 'z6'. Must be one of: bool, str, bytes, bytearray or int.)r   r   Úlowerr   Úencoder   Ú
isinstanceÚbytesÚ	bytearrayÚ
memoryviewr   Ú	TypeErrorr   Úhexr   ÚintÚreprÚtype©r   r   r   © r)   úb/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/eth_utils/conversions.pyÚto_hex'   s&   
ÿÿr+   c                 C   sˆ   |dur	t |dƒS |durt |ƒS t| ttfƒrt| ƒS t| tƒr'tt| ƒƒS t| tƒr0tdƒ‚t| t tfƒr;t | ƒS tdt	| ƒ› �ƒ‚)aI  
    Converts value to its integer representation.
    Values are converted this way:

     * primitive:

       * bytes, bytearray, memoryview: big-endian integer
       * bool: True => 1, False => 0
       * int: unchanged
     * hexstr: interpret hex as integer
     * text: interpret as string of digits, like '12' => 12
    Né   z+Pass in strings with keyword hexstr or textz@Invalid type. Expected one of int/bool/str/bytes/bytearray. Got )
r%   r   r    r!   r   r"   Ústrr#   Úboolr'   r(   r)   r)   r*   Úto_intP   s"   


ÿÿr/   c                 C   s–   t | ƒr
| rdS dS t| ttfƒrt| ƒS t| tƒr| S t| ƒr'tt| ƒd�S |d ur>t|ƒd r:t	t
dt|ƒ ƒ}t|ƒS |d urG| d¡S tdƒ‚)Nó   ó    ©r   é   r   r   zRexpected a bool, int, byte or bytearray in first arg, or keyword of hexstr or text)r   r   r!   r"   r    r   Úto_bytesr+   Úlenr   r   r   r   r   r#   r(   r)   r)   r*   r4   u   s"   

ÿr4   c                 C   sŽ   |d urt |d� d¡S |d ur|S t| tƒrt| d�S t| ttfƒr(|  d¡S t| tƒr4t| ƒ d¡S t| ƒrCt	t
t| ƒƒ}t|ƒS tdƒ‚)Nr2   r   z,Expected an int, bytes, bytearray or hexstr.)r4   Údecoder   r-   Úto_textr    r!   r"   r   r   r   r%   r#   )r   r   r   Úbyte_encodingr)   r)   r*   r7   �   s   



r7   Úto_type.Útext_or_primitivec                 C   s   t |tƒr
| |d�S | |ƒS )a&  
    Convert to a type, assuming that strings can be only unicode text (not a hexstr).

    :param to_type function: takes the arguments (primitive, hexstr=hexstr, text=text),
        eg~ to_bytes, to_text, to_hex, to_int, etc
    :param text_or_primitive bytes, str, int: value to convert
    )r   )r   r-   )r9   r:   r)   r)   r*   Útext_if_str¥   s   


r;   Úhexstr_or_primitivec                 C   sB   t |tƒrtt|ƒƒrt|ƒstdt|ƒ› �ƒ‚| |d�S | |ƒS )a&  
    Convert to a type, assuming that strings can be only hexstr (not unicode text).

    :param to_type function: takes the arguments (primitive, hexstr=hexstr, text=text),
        eg~ to_bytes, to_text, to_hex, to_int, etc
    :param hexstr_or_primitive bytes, str, int: value to convert
    z2when sending a str, it must be a hex string. Got: r2   )r   r-   r   r   r   Ú
ValueErrorr&   )r9   r<   r)   r)   r*   Úhexstr_if_strµ   s   

ÿÿÿ
r>   )NNN)%Útypingr   r   r   r   r   Ú
eth_typingr   r   Ú
decoratorsr
   Úencodingr   r   Úhexadecimalr   r   r   r   r   Útypesr   r   r   r   r!   r"   Ú	BytesLiker-   r+   r%   r/   r    r4   r7   r;   r>   r)   r)   r)   r*   Ú<module>   s”    ýÿþýü(ýÿþýü$ýÿþýüýÿþýü
ÿÿ
þ
ÿÿþ