
    (i              
          d dl mZ d dl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d
z  ded
z  ded
z  defd       Ze
	 	 	 dded
z  ded
z  ded
z  defd       Ze
	 	 	 dded
z  ded
z  ded
z  de fd       Z!e
	 	 	 dded
z  ded
z  ded
z  defd       Z"dedef   de ez  ez  defdZ#dedef   de ez  ez  defdZ$y
)    )Callable)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                    |"t        t        |j                                     S |t        |j	                  d            S t        |       r| rt        d      S t        d      S t        | t        t        f      rt        |       S t        | t              rt        t        |             S t        |       rt        d      t        |       r"t        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
    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   s      F/var/www/br/venv/lib/python3.12/site-packages/eth_utils/conversions.pyto_hexr+   (   s     VFLLN344$++g.//) )ve}<ve}<)eY/0)$$)Z(%	*++	9	1
 	

 )c$sI./00

d4	?34 5# 	#     c                 h   |t        |d      S |t        |      S t        | t        t        f      rt	        |       S t        | t
              rt	        t        |             S t        | t              rt        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
       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)   s      r*   to_intr1   Q   s    $ 62		4y	Iy1	2 ++	Iz	* y!122	Is	#EFF	IT{	+9~NI!
 	
r,   c                 t   t        |       r| rdS dS t        | t        t        f      rt	        |       S t        | t              r| S t        |       rt        t        |             S |5t        |      dz  rt        t        dt        |      z         }t        |      S ||j                  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)   s      r*   r7   r7   v   s     )#w00	I	:6	7Y	Iu	%	I	vi011		v;?&%*:6*B"BCF&!!		{{7##
	' r,   c                    |t        |      j                  d      S ||S t        | t              rt	        |       S t        | t
        t        f      r| j                  d      S t        | t              rt        |       j                  d      S t        |       r$t        t        t        |             }t	        |      S t        d      )Nr5   r   z,Expected an int, bytes, bytearray or hexstr.)r7   decoder    r/   to_textr!   r"   r#   r   r   r   r&   r$   )r   r   r   byte_encodings       r*   r;   r;      s     v&--g66			Is	#i((	Iy1	2((	Iz	*Y&&w//	I	)$sI*>?}%%
B
CCr,   to_type.text_or_primitivec                 D    t        |t              r	 | |      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/   )r=   r>   s     r*   text_if_strr@      s'     #S)-..())r,   hexstr_or_primitivec                     t        |t              r?t        t        |            r"t	        |      st        dt        |              | |      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: r5   )r    r/   r   r   r   
ValueErrorr'   )r=   rA   s     r*   hexstr_if_strrD      sg     %s+F#678B
 0124  122*++r,   )NNN)%collections.abcr   typingr   r   r   
eth_typingr   r   
decoratorsr
   encodingr   r   hexadecimalr   r   r   r   r   typesr   r   r   r   r"   r#   	BytesLiker/   r+   r&   r1   r!   r7   r;   r@   rD    r,   r*   <module>rN      s   
   CL*i34	 "& %4%TM% *% 	% %P "& !
4!
TM!
 *!
 		!
 !
H "& 4TM * 	 2 "& D4DTMD *D 		D D**#q&) *eckC>O *TU *,c1f,49CK#4E,,r,   