
    (i!              	          d dl Z d dlmZmZmZmZmZmZmZm	Z	m
Z
mZmZ d dlZd dlmZ d dlmZ d dlmZ d dlmZmZ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"m#Z# erd d
l$m%Z%m&Z& d dl'm(Z( edef   Z)ededee!ede#f   f   de
edf   fd       Z*dee	e)      de+de	e   fdZ,dddedede
d   fdZ-dddedee   fdZ. G d dee"         Z/ G d d      Z0y)    N)TYPE_CHECKINGAnyCallableDictGenericListOptionalSequenceTupleTypeUnion)to_tuplepipe)$RPC_METHODS_UNSUPPORTED_DURING_BATCH)get_error_formattersget_null_result_formattersget_request_formattersget_result_formatters)RPC)MethodNotSupportedWeb3TypeErrorWeb3ValidationErrorWeb3ValueError)RPCEndpointTFuncTReturn)PersistentConnectionProviderWeb3)Module.paramsrequest_formattersreturnc                 &    |rt        | |      }|S | S Nr   )r!   r"   formatted_paramss      </var/www/br/venv/lib/python3.12/site-packages/web3/method.py_apply_request_formattersr(   ;   s      (:;M    mungersis_propertyc                 H    |r| rt        d      | r| S |rt        gS t        gS )Nz'Mungers cannot be used with a property.)r   default_mungerdefault_root_munger)r*   r+   s     r'   _set_mungersr/   E   sC     w!"KLL  	  
 ""r)   _moduler    argskwargs c                 "    |s|rt        d      y)Nz*Parameters cannot be passed to a property.r3   )r   )r0   r1   r2   s      r'   r-   r-   T   s    v!"NOOr)   c                 
    g |S r%   r3   )r0   r1   s     r'   r.   r.   Z   s    T7Nr)   c                      e Zd ZdZ	 	 	 	 	 	 	 ddee   deee      deede	f      deede	f      deede	f      d	eedef      d
e
fdZ	 	 dded   deed      defdZdededefdZedeg ef   fd       Zdddededee   fdZdddededeeeeedef   f   eedf   f   eee	eeedef   f   f   edef   ee	edef   f   f   f   fdZy)Methoda  
    Method object for web3 module methods

    Calls to the Method go through these steps:

    1. input munging - includes normalization, parameter checking, early parameter
    formatting. Any processing on the input parameters that need to happen before
    json_rpc method string selection occurs.

            A note about mungers: The first (root) munger should reflect the desired
        api function arguments. In other words, if the api function wants to
        behave as: `get_balance(account, block_identifier=None)`, the root munger
        should accept these same arguments, with the addition of the module as
        the first argument e.g.:

        ```
        def get_balance_root_munger(module, account, block_identifier=None):
            if block_identifier is None:
                block_identifier = DEFAULT_BLOCK
            return module, [account, block_identifier]
        ```

        all mungers should return an argument list.

        if no munger is provided, a default munger expecting no method arguments
        will be used.

    2. method selection - The json_rpc_method argument can be method string or a
    function that returns a method string. If a callable is provided the processed
    method inputs are passed to the method selection function, and the returned
    method string is used.

    3. request and response formatters are set - formatters are retrieved
    using the json rpc method string.

    4. After the parameter processing from steps 1-3 the request is made using
    the calling function returned by the module attribute ``retrieve_caller_fn``
    and the response formatters are applied to the output.
    Njson_rpc_methodr*   r"   .result_formattersnull_result_formattersmethod_choice_depends_on_argsr+   c                     || _         t        ||      | _        |xs t        | _        |xs t
        | _        |xs t        | _        || _	        || _
        y r%   )r8   r/   r*   r   r"   r   r9   r   r:   r;   r+   )selfr8   r*   r"   r9   r:   r;   r+   s           r'   __init__zMethod.__init__   sZ      /#G[9"4"N8N!2!K6K"@&@ 	# .K*&r)   moduler    _typer#   c                    || _         |t        d      |j                  j                  j                  r<| j
                  t        v rt        d| j
                   d      |j                  |       S |j                  |       S )Nz~Direct calls to methods are not supported. Methods must be called from a module instance, usually attached to a web3 instance.zMethod `z*` is not supported within a batch request.)
r0   r   w3provider_is_batchingr8   r   r   retrieve_request_informationretrieve_caller_fn)r=   r?   r@   s      r'   __get__zMethod.__get__   s    
 >7  99**##'KK(t334 5   66t<<,,T22r)   r1   r2   c                 D     | j                  | j                        |i |S r%   )rG   r0   )r=   r1   r2   s      r'   __call__zMethod.__call__   s!    )t||DLL)4:6::r)   c                 v    | j                   t              rS t        t              rfdS t	        d      )z)Gets the method selector from the config.c                       S r%   r3   )methods   r'   <lambda>z+Method.method_selector_fn.<locals>.<lambda>   s    6 r)   z@``json_rpc_method`` config invalid.  May be a string or function)r8   callable
isinstancestrr   )r=   rL   s    @r'   method_selector_fnzMethod.method_selector_fn   s=    
 %%FM$!!N
 	
r)   c                 P    t        j                  fd| j                  |      S )Nc                      |g| i S r%   r3   )r1   mungerr2   r?   s     r'   rM   z%Method.input_munger.<locals>.<lambda>   s    !@!@!@ r)   )	functoolsreducer*   )r=   r?   r1   r2   s    ` `r'   input_mungerzMethod.input_munger   s$     @$,,PT
 	
r)   c                    | j                  |||      }| j                  rJ| j                  |d         | _        t        j                  t        j
                  g}| j                  |v rg }| j                         }| j                  ||      t        |      | j                  |      f}|t        || j                  |            f}||fS )Nr   )value)rW   r;   r8   r   eth_newPendingTransactionFiltereth_newBlockFilterrQ   r9   r   r:   r(   r"   )	r=   r?   r1   r2   r!    pending_or_latest_filter_methodsrL   response_formattersrequests	            r'   process_paramszMethod.process_params   s     ""648-- $(#E#EFSTI#E#VD  33&&0, ##'GG ((*""662 (''/
 %fd.E.Ef.MN
 +++r)   )NNNNNNFNN)__name__
__module____qualname____doc__r	   r   r
   Mungerr   r   boolr>   r   r   rG   r   rI   propertyrQ   r   rW   r   r   r   rP   r_   r3   r)   r'   r7   r7   ^   s   &T 26.2?C>BCGNR!'!+.' (6*+' %Xc7l%;<	'
 $HS'\$:;' !)#w,)? @' (0k9I0J'K' ', &**.3"3 X'3 
	3.;c ;S ;S ; 
	"k/	"
 

8 
3 
 
S	 
$,$,'*$,69$,	eK#{*:!;;<eKQTDT>UUV'4Xc3h%7 7889S#X'8CH--.0	
	
$,r)   r7   c                   |    e Zd Z	 	 	 ddeedef      dee   dee   dee   ddf
dZ	 dd	ed
   dee	d
      defdZ
y)DeprecatedMethodNrL   .old_namenew_namemsgr#   c                 <    || _         || _        || _        || _        y r%   )rL   rj   rk   rl   )r=   rL   rj   rk   rl   s        r'   r>   zDeprecatedMethod.__init__   s        r)   objr    obj_typec                     | j                    d| j                   }| j                  | j                  }t        j                  |t
        d       | j                  j                  ||      S )Nz is deprecated in favor of    )category
stacklevel)rj   rk   rl   warningswarnDeprecationWarningrL   rG   )r=   rn   ro   messages       r'   rG   zDeprecatedMethod.__get__   s^     ]]O#>t}}oN88hhG'	

 {{""311r)   )NNNr`   )ra   rb   rc   r7   r   r   r	   rP   r>   r   rG   r3   r)   r'   ri   ri      s     #'"&!
xS)*
 3-
 3-	

 c]
 

 TX2H%28@h8P2	2r)   ri   )1rU   typingr   r   r   r   r   r   r	   r
   r   r   r   rt   eth_utils.curriedr   eth_utils.toolzr   web3._utils.batchingr   web3._utils.method_formattersr   r   r   r   web3._utils.rpc_abir   web3.exceptionsr   r   r   r   
web3.typesr   r   r   web3r   r   web3.moduler    re   r(   rf   r/   r-   r.   r7   ri   r3   r)   r'   <module>r      sD            # 
#s(	 
%)+xW7M*M%N
38_ 
hv&'6:c]H S C E"I  # $s) Q,WU^ Q,h2 2r)   