
    eiF0              	          d dl Z d dlZddlmZmZmZmZ ddlmZmZ  ed          Z	 G d de          Z e            Z
 G d	 d
          Z G d de          Z G d de          ZdddddddZ ej        d                    d                    d e                                D                                           Zd Ze
j        ZdS )    N   )expressions
ParseErrorNodeVisitorGrammar   )ABITypeErrorr   a  
    type = tuple_type / basic_type

    tuple_type = components arrlist?
    components = non_zero_tuple / zero_tuple

    non_zero_tuple = "(" type next_type* ")"
    next_type = "," type

    zero_tuple = "()"

    basic_type = base sub? arrlist?

    base = alphas

    sub = two_size / digits
    two_size = (digits "x" digits)

    arrlist = (const_arr / dynam_arr)+
    const_arr = "[" digits "]"
    dynam_arr = "[]"

    alphas = ~"[A-Za-z]+"
    digits = ~"[1-9][0-9]*"
    c                        e Zd ZdZeZd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Z ej        d           fd            Z xZS )r   z
    Parsimonious node visitor which performs both parsing of type strings and
    post-processing of parse trees.  Parsing operations are cached.
    c                     |\  }}}}|f|z   S N )selfnodevisited_children_firstrests         k/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/static_dependencies/ethereum/abi/grammar.pyvisit_non_zero_tuplez NodeVisitor.visit_non_zero_tuple5   s    ,5$x$    c                 0    |\  }}t          |||          S Nr   )	TupleType)r   r   r   
componentsarrlists        r   visit_tuple_typezNodeVisitor.visit_tuple_type;   s!    .
GW48888r   c                     |\  }}|S r   r   )r   r   r   r   abi_types        r   visit_next_typezNodeVisitor.visit_next_type@   s    &8r   c                     t                      S r   tupler   r   r   s      r   visit_zero_tuplezNodeVisitor.visit_zero_tupleF       wwr   c                 4    |\  }}}t          ||||          S r   )	BasicType)r   r   r   basesubr   s         r   visit_basic_typezNodeVisitor.visit_basic_typeI   s%    -c7sG$7777r   c                     |\  }}}||fS r   r   )r   r   r   r   r   seconds         r   visit_two_sizezNodeVisitor.visit_two_sizeN   s    +q&f}r   c                     |\  }}}|fS r   r   )r   r   r   r   	int_values        r   visit_const_arrzNodeVisitor.visit_const_arrT   s    *9a|r   c                     t                      S r   r"   r$   s      r   visit_dynam_arrzNodeVisitor.visit_dynam_arrZ   r&   r   c                     |j         S r   )textr$   s      r   visit_alphaszNodeVisitor.visit_alphas]   s
    yr   c                 *    t          |j                  S r   )intr5   r$   s      r   visit_digitszNodeVisitor.visit_digits`   s    49~~r   c                     t          |j        t          j                  r|d         S t          |j        t          j                  rt          |          dk    r|d         S d S t          |          S Nr   )
isinstanceexprr   OneOfOptionallenr#   r$   s      r   generic_visitzNodeVisitor.generic_visitc   sn    di!233 	'#A&&di!566 	#$$))'**4%&&&r   N)maxsizec                 4   t          |t                    s/t          d                    t	          |                              	 t                                          |          S # t          $ r%}t          |j        |j	        |j
                  d}~ww xY w)a  
        Parses a type string into an appropriate instance of
        :class:`~eth_abi.grammar.ABIType`.  If a type string cannot be parsed,
        throws :class:`~eth_abi.exceptions.ParseError`.

        :param type_str: The type string to be parsed.
        :returns: An instance of :class:`~eth_abi.grammar.ABIType` containing
            information about the parsed type string.
        z$Can only parse string values: got {}N)r<   str	TypeErrorformattypesuperparser   r5   posr=   )r   type_stre	__class__s      r   rI   zNodeVisitor.parsep   s     (C(( 	6==d8nnMM  	477==*** 	4 	4 	4QVQUAF333	4s    A( (
B2 BB)__name__
__module____qualname____doc__grammarr   r   r    r%   r+   r.   r1   r3   r6   r9   rA   	functools	lru_cacherI   __classcell__rM   s   @r   r   r   -   s        
 G  9 9 9
    8 8 8
          ' ' ' Y&&&4 4 4 4 '&4 4 4 4 4r   r   c                       e Zd ZdZdZddZd Zd Zd Ze	d             Z
d	 Zd
 Ze	d             Ze	d             Ze	d             ZdS )ABITypezC
    Base class for results of type string parsing operations.
    r   r   Nc                 $    || _         	 || _        d S r   rY   )r   r   r   s      r   __init__zABIType.__init__   s!    	
 		 	r   c                     d                     t          |           j        t          |                                                     S )Nz<{} {}>)rF   rG   rP   reprto_type_strr   s    r   __repr__zABIType.__repr__   s=    JJ#!!##$$
 
 	
r   c                     t          |           t          |          u o)|                                 |                                k    S r   )rG   r^   )r   others     r   __eq__zABIType.__eq__   s;    DzzT%[[(VT-=-=-?-?5CTCTCVCV-VVr   c                      t          d          )z
        Returns the string representation of an ABI type.  This will be equal to
        the type string from which it was created.
        zMust implement `to_type_str`NotImplementedErrorr_   s    r   r^   zABIType.to_type_str   s    
 ""@AAAr   c                      t          d          )z
        If this type is an array type, equal to an appropriate
        :class:`~eth_abi.grammar.ABIType` instance for the array's items.
        zMust implement `item_type`re   r_   s    r   	item_typezABIType.item_type   s     "">???r   c                      t          d          )z
        Validates the properties of an ABI type against the solidity ABI spec:

        https://solidity.readthedocs.io/en/develop/abi-spec.html

        Raises :class:`~eth_abi.exceptions.ABITypeError` if validation fails.
        zMust implement `validate`re   r_   s    r   validatezABIType.validate   s     ""=>>>r   c                     | j         }t          d                    |j        |j        dz   |j        |                    )NzBFor '{comp_str}' type at column {col} in '{type_str}': {error_msg}r   )comp_strcolrK   	error_msg)r   r	   rF   r5   start	full_text)r   rn   r   s      r   
invalidatezABIType.invalidate   sL     y++16JN#	 ,2 , ,
 
 	
r   c                     | j         duS )z
        Equal to ``True`` if a type is an array type (i.e. if it has an array
        dimension list).  Otherwise, equal to ``False``.
        N)r   r_   s    r   is_arrayzABIType.is_array   s     |4''r   c                      t          d          )zv
        Equal to ``True`` if a type has a dynamically sized encoding.
        Otherwise, equal to ``False``.
        zMust implement `is_dynamic`re   r_   s    r   
is_dynamiczABIType.is_dynamic   s     ""?@@@r   c                 L    | j         ot          d | j        D                       S )Nc              3   <   K   | ]}t          |          d k    V  dS )r   N)r@   ).0dims     r   	<genexpr>z/ABIType._has_dynamic_arrlist.<locals>.<genexpr>   s,      $K$KsSXX]$K$K$K$K$K$Kr   )rs   anyr   r_   s    r   _has_dynamic_arrlistzABIType._has_dynamic_arrlist   s(    }K$K$Kdl$K$K$K!K!KKr   NN)rN   rO   rP   rQ   	__slots__r[   r`   rc   r^   propertyrh   rj   rq   rs   ru   r|   r   r   r   rX   rX      s         $I   
 
 
W W WB B B @ @ X@? ? ?
 
 
  ( ( X( A A XA L L XL L Lr   rX   c                   f     e Zd ZdZdZd
dd fdZd Zed             Zd Z	ed	             Z
 xZS )r   zQ
    Represents the result of parsing a tuple type string e.g. "(int,bool)".
    )r   Nr   c                Z    t                                          ||           || _        d S r   )rH   r[   r   )r   r   r   r   rM   s       r   r[   zTupleType.__init__   s.    $'''$	 	r   c                     | j         }t          |t                    r d                    d |D                       }nd}d                    d                    d | j        D                       |          S )N c              3   N   K   | ] }t          t          |                    V  !d S r   r]   listrx   as     r   rz   z(TupleType.to_type_str.<locals>.<genexpr>   .      ==d477mm======r   z({}){},c              3   >   K   | ]}|                                 V  d S r   )r^   rx   cs     r   rz   z(TupleType.to_type_str.<locals>.<genexpr>   s*      >>Q]]__>>>>>>r   )r   r<   r#   joinrF   r   )r   r   s     r   r^   zTupleType.to_type_str   s{    ,gu%% 	gg==W=====GGGHH>>do>>>>>
 
 	
r   c                     | j         s4t          d                    |                                                      t	          |           | j        | j        d d         pd | j                  S Nz2Cannot determine item type for non-array type '{}'r   )rs   
ValueErrorrF   r^   rG   r   r   r   r_   s    r   rh   zTupleType.item_type  s~    } 	DKK$$&&    tDzzOL"%
 
 
 	
r   c                 B    | j         D ]}|                                 d S r   )r   rj   )r   r   s     r   rj   zTupleType.validate  s,     	 	AJJLLLL	 	r   c                 P    | j         rdS t          d | j        D                       S )NTc              3   $   K   | ]}|j         V  d S r   )ru   r   s     r   rz   z'TupleType.is_dynamic.<locals>.<genexpr>  s$      99A1<999999r   )r|   r{   r   r_   s    r   ru   zTupleType.is_dynamic  s1    $ 	499999999r   r   )rN   rO   rP   rQ   r~   r[   r^   r   rh   rj   ru   rU   rV   s   @r   r   r      s           I       
 
 
 
 
 X
   : : X: : : : :r   r   c                   f     e Zd ZdZdZd
dd fdZd Zed             Zed             Z	d	 Z
 xZS )r(   zo
    Represents the result of parsing a basic type string e.g. "uint", "address",
    "ufixed128x19[][2]".
    )r)   r*   Nr   c                j    t                                          ||           || _        	 || _        d S r   )rH   r[   r)   r*   )r   r)   r*   r   r   rM   s        r   r[   zBasicType.__init__%  s8    $'''	E	 	r   c                 ^   | j         | j        }}t          |t                    rt	          |          }n7t          |t
                    r d                    d |D                       }nd}t          |t
                    r d                    d |D                       }nd}| j        |z   |z   S )Nxc              3   4   K   | ]}t          |          V  d S r   )rD   )rx   ss     r   rz   z(BasicType.to_type_str.<locals>.<genexpr>8  s(      //a3q66//////r   r   c              3   N   K   | ] }t          t          |                    V  !d S r   r   r   s     r   rz   z(BasicType.to_type_str.<locals>.<genexpr>=  r   r   )r*   r   r<   r8   rD   r#   r   r)   )r   r*   r   s      r   r^   zBasicType.to_type_str2  s    xWc3 	c((CCU## 	((//3/////CCCgu%% 	gg==W=====GGGy3((r   c                     | j         s4t          d                    |                                                      t	          |           | j        | j        | j        d d         pd | j                  S r   )	rs   r   rF   r^   rG   r)   r*   r   r   r_   s    r   rh   zBasicType.item_typeC  s    } 	DKK$$&&    tDzzIHL"%	
 
 
 	
r   c                 Z    | j         rdS | j        dk    rdS | j        dk    r	| j        dS dS )NTstringbytesF)r|   r)   r*   r_   s    r   ru   zBasicType.is_dynamicS  sB    $ 	49  49DH$44ur   c                    | j         | j        }}|dk    r||                     d           d S d S |dk    rb|*t          |t                    s|                     d           t          |t                    r|dk    r|                     d           d S d S d S |dv rmt          |t                    s|                     d           |d	k     sd
|k     r|                     d           |d	z  dk    r|                     d           d S d S |dv rt          |t
                    s|                     d           |\  }}|d	k     sd
|k     r|                     d           |d	z  dk    r|                     d           |dk     sd|k     r*|                     d                    |                     d S d S |dk    r.t          |t                    s|                     d           d S d S |dk    r||                     d           d S d S d S )Nr   zstring type cannot have suffixr   z;bytes type must have either no suffix or a numerical suffix    z'maximum 32 bytes for fixed-length bytes)r8   uintz'integer type must have numerical suffix      z)integer size out of bounds (max 256 bits)r   z"integer size must be multiple of 8)fixedufixedzBfixed type must have suffix of form <bits>x<exponent>, e.g. 128x19z'fixed size out of bounds (max 256 bits)z fixed size must be multiple of 8r   P   z5fixed exponent size out of bounds, {} must be in 1-80hashz$hash type must have numerical suffixaddresszaddress cannot have suffix)r)   r*   rq   r<   r8   r#   rF   )r   r)   r*   bitsminus_es        r   rj   zBasicType.validate`  s   Itxc 8 @AAAAA  W__K:c3#7#7KQ   #s## Kb IJJJJJK K _$$c3'' K IJJJQww#)) KLLLQw!|| DEEEEE | (((c5)) "  
  MD'axx3:: IJJJax1}} BCCC{{b7llKRR      +l V^^c3'' H FGGGGGH H Y <===== r   r}   )rN   rO   rP   rQ   r~   r[   r^   r   rh   ru   rj   rU   rV   s   @r   r(   r(     s         
  IT       ) ) )" 
 
 X
 
 
 X
<> <> <> <> <> <> <>r   r(   int256uint256fixed128x18ufixed128x18bytes24bytes1)r8   r   r   r   functionbytez\b({})\b|c              #   >   K   | ]}t          j        |          V  d S r   )reescaper   s     r   rz   rz     s*      JJ	!JJJJJJr   c                 :    t                               d |           S )z
    Normalizes a type string into its canonical version e.g. the type string
    'int' becomes 'int256', etc.

    :param type_str: The type string to be normalized.
    :returns: The canonical version of the input type string.
    c                 B    t           |                     d                   S r;   )TYPE_ALIASESgroup)matchs    r   <lambda>znormalize.<locals>.<lambda>  s    l5;;q>>2 r   )TYPE_ALIAS_REr*   )rK   s    r   	normalizer     s%     22  r   )rS   r   parsimoniousr   r   r   r   
exceptionsr	   rR   visitorrX   r   r(   r   compilerF   r   keysr   r   rI   r   r   r   <module>r      s       				                  
 ' :V4 V4 V4 V4 V4+ V4 V4 V4r +--YL YL YL YL YL YL YL YLx5: 5: 5: 5: 5: 5: 5: 5:p> > > > > > > >F   
sxxJJl6G6G6I6IJJJJJKK 
   	r   