
    (i"                     |   d dl Z d dl mZ d dlmZ ddlmZmZ ddlmZ  G d d      Zd Z	d	d
z  dz
  Z
eeeee j                  f   Zdede j                  dee j                  z  fdZdede j                  defdZdededee j                  z  fdZdededefdZdededee j                  z  fdZdededefdZy)    N)localcontext)Union   )
is_integer	is_string)unitsc                      e Zd Z eed         Z eed         Z eed         Z eed         Z eed         Z	 eed         Z
 eed         Z eed         Z eed	         Z eed
         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Z eed         Zy)denomsweikweibabbage
femtoethermweilovelace	picoethergweishannon	nanoethernanoszabo
microethermicrofinney
milliethermillietherkethergrandmethergethertetherN)__name__
__module____qualname__intr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!        C/var/www/br/venv/lib/python3.12/site-packages/eth_utils/currency.pyr
   r
      sL   
eEl
CuV}D%	"#GU<()JuV}D5$%HE+&'IuV}D%	"#GE+&'IuV}DgEU<()JgEx!FU<()JgEgEx!FgEx!Fx!Fx!Fr'   r
         number
unit_valuereturnc                     | dk(  ry| t         k  s	| t        kD  rt        d      t               5 }d|_        t        j                  | |      }||z  }d d d        |S # 1 sw Y   S xY w)Nr   z&value must be between 0 and 2**256 - 1  valuecontext)MIN_WEIMAX_WEI
ValueErrorr   precdecimalDecimal)r+   r,   ctxd_numberresult_values        r(   	_from_weir<   2   so    {6G+ABB	 -3??=*,-
 -
 s   $AA&c                    t        |       st        |       rt        j                  |       }nXt	        | t
              r t        j                  t        |             }n(t	        | t        j                        r| }nt        d      |t        j                  d      k(  ryt        |       }|dk  rcd|v r_t               5 }t        |      |j                  d      z
  dz
  }||_        t        j                  | |      d|z  z  }d d d        |dz  z  }t               5 }d|_        t        j                  ||      |z  }d d d        t        k  s	|t        kD  rt        d	      t        |      S # 1 sw Y   mxY w# 1 sw Y   =xY w)
Nr1   z:Unsupported type. Must be one of integer, float, or stringr   r   .r0   
   r/   z4Resulting wei value must be between 0 and 2**256 - 1)r   r   r7   r8   
isinstancefloatstr	TypeErrorr   lenindexr6   r3   r4   r5   r%   )r+   r,   r:   s_numberr9   
multiplierr;   s          r(   _to_weirI   A   sT   &Yv.??0	FE	"??V5	FGOO	,TUU7??1%%6{H!|x^ 	SsX)<<q@J!CHVSAB
NRH	S 	b*n$
	 Q3XsCjPQ g!7OPP|	S 	SQ Qs   =AE."E:.E7:Funitc                     |j                         t        vr/t        ddj                  t        j                                      t        |j                            }t        | |      S )zH
    Takes a number of wei and converts it to any other ether unit.
    Unknown unit. Must be one of /)lowerr   r5   joinkeysr<   r+   rJ   r,   s      r(   from_weirR   a   sR     zz|5 8%**,9O8PQRRtzz|$JVZ((r'   c                     |j                         t        vr/t        ddj                  t        j                                      t        |j                            }t        | |      S )z:
    Takes a number of a unit and converts it to wei.
    rL   rM   )rN   r   r5   rO   rP   rI   rQ   s      r(   to_weirT   m   sR     zz|5 8%**,9O8PQRRtzz|$J6:&&r'   decimalsc                 r    t        j                  d      t        j                  |      z  }t        | |      S )zg
    Takes a number of wei and converts it to a decimal with the specified
    number of decimals.
    r@   r>   )r7   r8   r<   r+   rU   r,   s      r(   from_wei_decimalsrX   y   s-    
 $h(GGJVZ((r'   c                 r    t        j                  d      t        j                  |      z  }t        | |      S )zd
    Takes a number of a unit and converts it to wei with the specified
    number of decimals.
    r@   r>   )r7   r8   rI   rW   s      r(   to_wei_decimalsrZ      s-    
 $h(GGJ6:&&r'   )r7   r   typingr   typesr   r   r   r
   r3   r4   r%   rB   rC   r8   _NumberTyper<   rI   rR   rT   rX   rZ   r&   r'   r(   <module>r^      s   
" "4 
S&1*CW__45c w 3;P K W__  @	)S 	) 	)goo(= 	)	'; 	'c 	'c 	')c )S )S7??5J )'K '3 '3 'r'   