o
    ¢ØÆh¦  ã                   @   s¢  d dl Z d dlmZmZmZ 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mZmZ ddlmZmZ e  d	e je jB ¡Zd
edefdd„Zd
edefdd„Zd
edefdd„Zd
eee e!f de	fdd„Z"d
edefdd„Z#deee e!f defdd„Z$dedefdd„Z%deee e!f deee e!f defdd„Z&d
eee e!f defdd „Z'd
edefd!d"„Z(d
edefd#d$„Z)d
edefd%d&„Z*dS )'é    N)ÚAnyÚUnionÚcast)ÚAddressÚ
AnyAddressÚChecksumAddressÚ
HexAddressÚHexStré   )Úhexstr_if_strÚto_hex)Úkeccak)Úadd_0x_prefixÚ
decode_hexÚ
encode_hexÚremove_0x_prefix)Úis_bytesÚis_textz(0x)?[0-9a-f]{40}ÚvalueÚreturnc                 C   s   t | ƒsdS t | ¡duS )z\
    Checks if the given string of text type is an address in hexadecimal encoded form.
    FN)r   Ú_HEX_ADDRESS_REGEXPÚ	fullmatch©r   © r   ú^/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/eth_utils/address.pyÚis_hex_address%   s   r   c                 C   s    t | ƒsdS t| ƒdkrdS dS )zE
    Checks if the given string is an address in raw bytes form.
    Fé   T)r   Úlenr   r   r   r   Úis_binary_address.   s
   r   c                 C   s   t | ƒst| ƒr
dS dS )zE
    Is the given string an address in any of the known formats?
    TF)r   r   r   r   r   r   Ú
is_address:   s   r   c                 C   sd   z	t t| ƒ ¡ }W n ty   tdt| ƒ› �ƒ‚w t|ƒr$tt|ƒƒS t	dt
| ƒ› dt
|ƒ› �ƒ‚)zK
    Converts an address to its normalized hexadecimal representation.
    z+Value must be any string, instead got type zUnknown format z, attempted to normalize to )r   r   ÚlowerÚAttributeErrorÚ	TypeErrorÚtyper   r   r	   Ú
ValueErrorÚrepr)r   Úhex_addressr   r   r   Úto_normalized_addressD   s   ÿÿÿr'   c                 C   s"   t | ƒsdS | t| ƒk}tt|ƒS )zR
    Returns whether the provided value is an address in its normalized form.
    F)r   r'   r   Úbool©r   Úis_equalr   r   r   Úis_normalized_addressU   s   
r+   Úaddressc                 C   s   t tt| ƒƒƒS )zJ
    Convert a valid address to its canonical form (20-length bytes).
    )r   r   r'   )r,   r   r   r   Úto_canonical_address`   s   r-   c                 C   s.   t | ƒr
t| ƒdkrdS | t| ƒk}tt|ƒS )zL
    Returns `True` if the `value` is an address in its canonical form.
    r   F)r   r   r-   r   r(   )r,   r*   r   r   r   Úis_canonical_addressg   s   
r.   ÚleftÚrightc                 C   s,   t | ƒrt |ƒstdƒ‚tt| ƒt|ƒkƒS )z3
    Checks if both addresses are same or not.
    z#Both values must be valid addresses)r   r$   r(   r'   )r/   r0   r   r   r   Úis_same_addressq   s   r1   c                    sR   t | ƒ‰ttttˆƒƒd�ƒ‰ ttd ‡ ‡fdd„tddƒD ƒ¡ƒƒ}tt	|ƒƒS )z<
    Makes a checksum address given a supported format.
    )ÚtextÚ c                 3   s6   � | ]}t ˆ | d ƒdkrˆ|  ¡ nˆ| V  qdS )é   é   N)ÚintÚupper)Ú.0Úi©Úaddress_hashÚnorm_addressr   r   Ú	<genexpr>†   s   € ýÿ
üz&to_checksum_address.<locals>.<genexpr>é   é*   )
r'   r   r   r   r	   r   ÚjoinÚranger   r   )r   Úchecksum_addressr   r:   r   Úto_checksum_address}   s   úÿÿrC   c                 C   s.   t | ƒsdS t| ƒsdS | t| ƒk}tt|ƒS )NF)r   r   rC   r   r(   r)   r   r   r   Úis_checksum_address“   s   
rD   c                 C   s&   t | ƒ}| ¡  o| ¡  o| ¡  S ©N)r   ÚislowerÚisupperÚ	isnumeric)r   Úunprefixed_valuer   r   r   Ú_is_checksum_formatted�   s   
ÿýrJ   c                 C   s   t | ƒot| ƒS rE   )r   rJ   r   r   r   r   Úis_checksum_formatted_address¦   s   rK   )+ÚreÚtypingr   r   r   Ú
eth_typingr   r   r   r   r	   Úconversionsr   r   Úcryptor   Úhexadecimalr   r   r   r   Útypesr   r   ÚcompileÚ
IGNORECASEÚASCIIr   r(   r   r   r   ÚstrÚbytesr'   r+   r-   r.   r1   rC   rD   rJ   rK   r   r   r   r   Ú<module>   s4    	

ÿÿ
þ
	