
    (iwP                     B   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mZmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
l m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z( d dl)m*Z* d dl+m,Z,m-Z-m.Z. d dl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 d dl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA d dlBmCZCmDZDmEZEmFZF d dlGmHZHmIZImJZJmKZK erd dlLmMZM d dlNmOZO  G d de3      ZP G d de4eP         ZQ G d de5      ZR G d de6eR         ZS G d de0      ZT G d  d!e1      ZU G d" d#e2      ZVy$)%    )TYPE_CHECKINGAny	AwaitableCallableDictIterableListOptionalSequenceTypecast)ABIChecksumAddress)combomethod)abi_to_signatureget_abi_input_names)partial)HexBytes)fallback_func_abi_existsreceive_func_abi_exists)
FallbackFn	ReceiveFn)async_fill_transaction_defaults)Self)async_parse_block_identifier)PropertyCheckingFactory)AsyncEventFilterBuilderget_event_data)AsyncLogFilter)normalize_abinormalize_address_no_ensnormalize_bytecode)	BaseContractBaseContractCallerBaseContractConstructorBaseContractEventBaseContractEventsBaseContractFunctionBaseContractFunctionsNonExistentFallbackFunctionNonExistentReceiveFunction)$async_build_transaction_for_functionasync_call_contract_functionasync_estimate_gas_for_function%async_transact_with_contract_functionfind_events_by_identifierfind_functions_by_identifierget_event_by_identifierget_function_by_identifier)Web3AttributeErrorWeb3TypeErrorWeb3ValidationErrorWeb3ValueError)BlockIdentifier	EventDataStateOverrideTxParams)AsyncENS)	AsyncWeb3c                       e Zd ZU ded<   e	 	 	 	 ddeeeef      dee	   dee	   dee
   deee      f
d	       Zeddd
ddddeeeef      dee	   de	dee   deee      defd       Zedefd       Zy)AsyncContractEventAsyncWeb3[Any]w3Nargument_filters
from_blockto_block
block_hashreturnc                    
K   |Bt         j                        
t        
fd|j                         D              st	        d       j                   j                  ||||      } j                  j                  j                  |       d{   }t         fd|D              } j                   j                  ||      }t        |d       }	t        |	d       }	t        t        t        t              |	      S 7 ow)a   
        Get events for this contract instance using eth_getLogs API.

        This is a stateless method, as opposed to createFilter.
        It can be safely called against nodes which do not provide
        eth_newFilter API, like Infura nodes.

        If there are many events,
        like ``Transfer`` events for a popular token,
        the Ethereum node might be overloaded and timeout
        on the underlying JSON-RPC call.

        Example - how to get all ERC-20 token transactions
        for the latest 10 blocks:

        .. code-block:: python

            from = max(mycontract.web3.eth.block_number - 10, 1)
            to = mycontract.web3.eth.block_number

            events = mycontract.events.Transfer.get_logs(from_block=from, to_block=to)

            for e in events:
                print(e["args"]["from"],
                    e["args"]["to"],
                    e["args"]["value"])

        The returned processed log values will look like:

        .. code-block:: python

            (
                AttributeDict({
                 'args': AttributeDict({}),
                 'event': 'LogNoArguments',
                 'logIndex': 0,
                 'transactionIndex': 0,
                 'transactionHash': HexBytes('...'),
                 'address': '0xF2E246BB76DF876Cef8b38ae84130F4F55De395b',
                 'blockHash': HexBytes('...'),
                 'blockNumber': 3
                }),
                AttributeDict(...),
                ...
            )

        See also: :func:`web3.middleware.filter.LocalFilterMiddleware`.

        :param argument_filters: Filter by argument values. Indexed arguments are
          filtered by the node while non-indexed arguments are filtered by the library.
        :param from_block: block number or "latest", defaults to "latest"
        :param to_block: block number or "latest". Defaults to "latest"
        :param block_hash: block hash. Cannot be set at the
          same time as ``from_block`` or ``to_block``
        :yield: Tuple of :class:`AttributeDict` instances
        Nc              3   &   K   | ]  }|v  
 y wN ).0argevent_arg_namess     M/var/www/br/venv/lib/python3.12/site-packages/web3/contract/async_contract.py	<genexpr>z.AsyncContractEvent.get_logs.<locals>.<genexpr>   s     Q#so-Qs   zaWhen filtering by argument names, all argument names must be present in the contract's event ABI.c              3   t   K   | ]/  }t        j                  j                  j                  |       1 y wrI   )r   rA   codecabi)rK   entryselfs     rN   rO   z.AsyncContractEvent.get_logs.<locals>.<genexpr>   s+      
?DN477==$((E:
s   58c                     | d   S )NlogIndexrJ   es    rN   <lambda>z-AsyncContractEvent.get_logs.<locals>.<lambda>   s
    !J-     )keyc                     | d   S )NblockNumberrJ   rW   s    rN   rY   z-AsyncContractEvent.get_logs.<locals>.<lambda>   s    -8H rZ   )r   rR   allkeysr6   _get_event_filter_paramsrA   ethget_logstuple"_process_get_logs_argument_filterssortedr   r   r   r9   )rT   rB   rC   rD   rE   _filter_paramslogsall_event_logsfiltered_logssorted_logsrM   s   `         @rN   rb   zAsyncContractEvent.get_logsl   s     B '1$((;OQ9I9N9N9PQQ); 
 66HH&
Hj
 WW[[)).99  
HL
 
 ??HH

 ]0GH[.HIIhy12K@@ :s   BDD A0Dlatest)rB   rC   rD   addresstopicsrl   rm   c                D  K   t        | j                  | j                  j                        }| j	                  ||||||       |j                  | j                         d{   }t        | j                  j                  | j                        |_        ||_        |S 7 <w)zW
        Create filter object that tracks logs emitted by this contract event.
        N)	r   rR   rA   rQ   _set_up_filter_builderdeployr   log_entry_formatterbuilder)rT   rB   rC   rD   rl   rm   filter_builder
log_filters           rN   create_filterz AsyncContractEvent.create_filter   s      1477==I##	
 *0099
)7txx)P
&+
	 :s   AB !B"=B c                     t        | j                  | j                  j                  t	        | j                  j                  | j                              }| j
                  |_        |S )N)	formatter)r   rR   rA   rQ   r   rl   )rT   rr   s     rN   build_filterzAsyncContractEvent.build_filter   sF    )HHGGMM$TWW]]DHH=

 ,,rZ   NNNN)__name__
__module____qualname____annotations__r   r
   r   strr   r8   r   r   r   r9   rb   r   r   r   ru   r   rx   rJ   rZ   rN   r?   r?   h   s*    6:04.2)-YA"4S>2YA _-YA ?+	YA
 X&YA 
8I&	'YA YAv  6:04$,-1*. #4S>2 _-	
 " /* #' 
 6 5  rZ   r?   c            	       :     e Zd Z	 ddedddee   ddf fdZ xZS )	AsyncContractEventsNrR   rA   r@   rl   rF   c                 2    t         |   ||t        |       y rI   )super__init__r?   )rT   rR   rA   rl   	__class__s       rN   r   zAsyncContractEvents.__init__   s     	b"4g>rZ   rI   )rz   r{   r|   r   r
   r   r   __classcell__r   s   @rN   r   r      s5    SW??,?7?7P?	? ?rZ   r   c                      e Zd ZU ded<   	 	 	 	 ddee   dedee   dee   de	f
d	Z
ddee   defd
Z	 	 	 ddee   dee   dee   defdZ	 ddee   defdZe	 ddedddee   dd fd       Ze	 ddedddee   dd fd       Zy)AsyncContractFunctionr@   rA   Ntransactionblock_identifierstate_overrideccip_read_enabledrF   c                   K   | j                  |      }t        | j                  |       d{   }t        | j                        }t        | j                  | j                  | j                  |||| j                  | j                  ||| j                  g| j                  xs di | j                  xs i  d{   S 7 7 w)a  
        Execute a contract function call using the `eth_call` interface.

        This method prepares a ``Caller`` object that exposes the contract
        functions and public variables as callable Python functions.

        Reading a public ``owner`` address variable example:

        .. code-block:: python

            ContractFactory = w3.eth.contract(
                abi=wallet_contract_definition["abi"]
            )

            # Not a real contract address
            contract = ContractFactory("0x2f70d3d26829e412A602E83FE8EeBF80255AEeA5")

            # Read "owner" public variable
            addr = contract.functions.owner().call()

        :param transaction: Dictionary of transaction info for web3 interface
        :param block_identifier TODO
        :param state_override TODO
        :param ccip_read_enabled TODO
        :return: ``Caller`` object that has contract public functions
            and variables exposed as Python methods
        NrJ   )_get_call_txparamsr   rA   r   rR   r-   rl   _return_data_normalizerscontract_abidecode_tuplesargskwargs)rT   r   r   r   r   call_transactionblock_idabi_element_identifiers           rN   callzAsyncContractFunction.call   s     D  22;?5dgg?OPP!1$((!;1GGLL))"HH
 YY_"
 kkR
 
 	
	 Q
s"   +CC BC;C<CCc                   K   | j                  |      }t        | j                        }t        | j                  | j
                  ||| j                  | j                  g| j                  xs di | j                  xs i  d {   S 7 wNrJ   )		_transactr   rR   r/   rl   rA   r   r   r   )rT   r   setup_transactionr   s       rN   transactzAsyncContractFunction.transact2  s      NN;7!1$((!;:LLGG"HH	
 YY_"	
 kkR	
 	
 		
 	
   BBB	Bc           
        K   | j                  |      }t        | j                        }t        | j                  | j
                  ||| j                  | j                  ||g| j                  xs di | j                  xs i  d {   S 7 wr   )	_estimate_gasr   rR   r.   rl   rA   r   r   r   )rT   r   r   r   r   r   s         rN   estimate_gasz"AsyncContractFunction.estimate_gas@  s      !..{;!1$((!;4LLGG"HH
 YY_"
 kkR
 
 	
 
s   BBBBc                   K   | j                  |      }t        | j                        }t        | j                  | j
                  ||| j                  | j                  g| j                  xs di | j                  xs i  d {   S 7 wr   )	_build_transactionr   rR   r,   rl   rA   r   r   r   )rT   r   built_transactionr   s       rN   build_transactionz'AsyncContractFunction.build_transactionU  s      !33K@!1$((!;9LLGG"HH	
 YY_"	
 kkR	
 	
 		
 	
r   rR   async_w3rl   c                     | r-t        |       r"t        j                  d|| |t                     S t	        t        t                     S )NfallbackrA   r   rl   r   )r   r   factoryr   r   r*   rR   r   rl   s      rN   get_fallback_functionz+AsyncContractFunction.get_fallback_functione  sO     +C0(00 '1 1    )+F+HIIrZ   c                     | r-t        |       r"t        j                  d|| |t                     S t	        t        t                     S )Nreceiver   )r   r   r   r   r   r+   r   s      rN   get_receive_functionz*AsyncContractFunction.get_receive_functionu  sO     *3/(00 '0 1    )+E+GHHrZ   ry   rI   NNN)rz   r{   r|   r}   r
   r;   r8   r:   boolr   r   r   r   intr   r   staticmethodr   r   r   r   rJ   rZ   rN   r   r      sf    +/,026,06
h'6
 *6
 !/	6

 $D>6
 
6
p
(8*< 
 
  +/6:26	
h'
 #?3
 !/	

 

, 15
#H-
	
   .2JJ"J /*J 
!	J J  .2II"I /*I 
!	I IrZ   r   c                   F     e Zd Z	 	 d	dedddee   dee   ddf
 fdZ xZS )
AsyncContractFunctionsNrR   rA   r@   rl   r   rF   c                 4    t         |   ||t        ||       y rI   )r   r   r   )rT   rR   rA   rl   r   r   s        rN   r   zAsyncContractFunctions.__init__  s     	b"7-PrZ   )NF)	rz   r{   r|   r   r
   r   r   r   r   r   s   @rN   r   r     sU    
 .2(-QQ Q /*	Q
  ~Q 
Q QrZ   r   c                   ^   e Zd ZU dZeed<   dZded<   ded<   dZeed<   dde	e
   d	dfd
Ze	 dddde	e   ded	ee   fd       Zededed	dfd       Zededdde
dedef   d	ed   f
d       Zeded   ded	dfd       Zededdde
dedef   d	ed   f
d       Zeded   ded	dfd       Zy)AsyncContractN	functionsAsyncContractCallercallerr@   rA   eventsrl   rF   c                    | j                   t        d      |rt        |      | _        | j                  st	        d      t        | j                  | j                   | j                  | j                        | _        t        | j                  | j                   | j                  | j                  | j                        | _
        t        | j                  | j                   | j                        | _        t        j                  | j                  | j                   t        | j                        | _        t        j#                  | j                  | j                   t        | j                        | _        y)zv
        Create a new smart contract proxy object.

        :param address: Contract address as 0x hex string
        NzwThe `Contract` class has not been initialized.  Please use the `web3.contract` interface to create your contract class.z;The address argument is required to instantiate a contract.r   r   contract_functions)rA   r4   r!   rl   r5   r   rR   r   r   r   r   r   r   r   r   r   r   r   r   )rT   rl   s     rN   r   zAsyncContract.__init__  s    77?$K 
 3G<DL||M  0HHdggt||4;M;M
 *HHGGLL,,#~~
 *$((DGGT\\J%;;HHdgg4dll
 %99HHdgg4dll
rZ   
class_namer   c           	      0   ||d<   t         t        t        t        d}t        t        t
           t        |xs | j                  | f||            }|j                  r5|j                  D ]&  }|j                  d      }|dv st        d| d       t        |j                  |j                  |j                        |_        t        |j                  |j                  |j                   |j                  |j                  	      |_        t%        |j                  |j                        |_        t(        j+                  |j                  |j                  t,              |_        t(        j1                  |j                  |j                  t,              |_        |S )
NrA   )rR   rl   bytecodebytecode_runtime)normalizersname)rR   rl   z#Contract contains a reserved word `z ` and could not be instantiated.r   r   )r    r!   r"   r   r   r   r   rz   rR   getr4   r   rA   r   r   r   rl   r   r   r   r   r   r   r   r   r   )clsrA   r   r   r   contractrR   abi_names           rN   r   zAsyncContract.factory  si    t !/* 2	
 J#*cll'	
 <<|| 776?11,=hZ H9 :  4LL(++X5K5K
 .LLKK"00'11
 .hllHKKH)??LLKK!

 )==LLKK!

 rZ   r   AsyncContractConstructorc                     | j                   t        d      t        | j                  | j                  | j                   g|i |S )z
        :param args: The contract constructor arguments as positional arguments
        :param kwargs: The contract constructor arguments as keyword arguments
        :return: a contract constructor object
        zVCannot call constructor on a contract that does not have 'bytecode' associated with it)r   r7   r   rA   rR   )r   r   r   s      rN   constructorzAsyncContract.constructor  sH     << 0 
 (WWPVWWrZ   r   callable_check.r   c           
      R    t        t        t           t        ||||t                    S rI   )r   r	   r   r1   r   r   rA   rl   r   s        rN   r1   z*AsyncContract.find_functions_by_identifier  s.     &'(b'>;P
 	
rZ   fns
identifierc                     t        ||      S rI   )r3   )r   r   r   s      rN   r3   z(AsyncContract.get_function_by_identifier  s     *#z::rZ   r?   c                 (    t        ||||t              S rI   )r0   r?   r   s        rN   r0   z'AsyncContract.find_events_by_identifier  s     )"g~7I
 	
rZ   c                     t        ||      S rI   )r2   )r   r   r   s      rN   r2   z%AsyncContract.get_event_by_identifier'  s     'vz::rZ   rI   )rz   r{   r|   r   r   r}   r   r   r   r
   r   r   classmethodr~   r   r   r   r   r   r   r   r   r	   r1   r   r3   r0   r2   rJ   rZ   rN   r   r     s   (,I%,$(F!( 	 #'F&#
 9 #
T #
J ?C4!4/7}4OR4	d4 4l X Xs X7Q X X 

 
 !	

 !c*
 
%	&
 
 ;23;AD;	 ; ;
 	
	
 	
 !		

 !c*	
 
"	#	
 	
 ;23;AD;	; ;rZ   r   c                        e Zd ZU ded<   	 	 	 	 	 ddedddedee   dedee	   d	ee	   d
ee
   ddf fdZ	 	 	 ddee   dedee	   dd fdZ xZS )r   r@   rA   NrR   rl   r   r   r   r   r   rF   c	                 0   t         |   ||||       | j                  rv|i }|t        ||||      }|j                  | _        |j                         D ]<  }	t        | j                  |	|||      }
t        | t        |	j                        |
       > y y )Nr   )r   r   r   )r   r   rR   r   
_functions__iter__r   call_functionsetattrr~   r   )rT   rR   rA   rl   r   r   r   r   r   fncaller_methodr   s              rN   r   zAsyncContractCaller.__init__2  s     	b'G88" !)%;WM&" 1;;DO(113 M '&& +%5&7! c"";";<mLM rZ   c           	          |i } t        |       | j                  | j                  | j                  |||| j                        S )N)r   r   r   r   )typerR   rA   rl   r   )rT   r   r   r   s       rN   __call__zAsyncContractCaller.__call__S  sI     KtDzHHGGLL#-/,,
 	
rZ   )NNNFNr   )rz   r{   r|   r}   r   r   r
   r;   r8   r   r   r   r   r   r   s   @rN   r   r   .  s     +/,0,0(-?CMM M !	M
 h'M *M $D>M  ~M %%;<M 
MF +/,0,0	
h'
 *
 $D>	

 

rZ   r   c                       e Zd ZU ded<   ed
dee   defd       Ze	 d
dee   defd       Z	e	 	 ddee   dee
   defd	       Zy)r   r@   rA   Nr   rF   c                    K   | j                   j                  j                  | j                  |             d {   S 7 wrI   )rA   ra   send_transaction_get_transaction)rT   r   s     rN   r   z!AsyncContractConstructor.transactj  s0     WW[[11$2G2G2TUUUUs   8A?Ac                 l   K   | j                  |      }t        | j                  |       d{   S 7 w)zB
        Build the transaction dictionary without sending
        N)r   r   rA   )rT   r   r   s      rN   r   z*AsyncContractConstructor.build_transactionn  s1      !33K@4TWW>OPPPPs   +424r   c                    K   | j                  |      }| j                  j                  j                  ||       d {   S 7 w)N)r   )r   rA   ra   r   )rT   r   r   s      rN   r   z%AsyncContractConstructor.estimate_gasx  sH      ((5WW[[--*: . 
 
 	
 
s   <AAArI   )NN)rz   r{   r|   r}   r   r
   r;   r   r   r   r8   r   r   rJ   rZ   rN   r   r   f  s    V(8*< V V V 04Q#H-Q	Q Q  +/6:	
h'	
 #?3	
 
		
 	
rZ   r   N)Wtypingr   r   r   r   r   r   r	   r
   r   r   r   
eth_typingr   r   	eth_utilsr   eth_utils.abir   r   eth_utils.toolzr   hexbytesr   web3._utils.abir   r   #web3._utils.abi_element_identifiersr   r   web3._utils.async_transactionsr   web3._utils.compatr   web3._utils.contractsr   web3._utils.datatypesr   web3._utils.eventsr   r   web3._utils.filtersr   web3._utils.normalizersr    r!   r"   web3.contract.base_contractr#   r$   r%   r&   r'   r(   r)   r*   r+   web3.contract.utilsr,   r-   r.   r/   r0   r1   r2   r3   web3.exceptionsr4   r5   r6   r7   
web3.typesr8   r9   r:   r;   ensr<   web3r=   r?   r   r   r   r   r   r   rJ   rZ   rN   <module>r      s      

 
 
	 	 	   D* DN?,-?@ ?MI0 MI`Q23HI QZ;L Z;z5
, 5
p
6 
rZ   