
    (iX              
          d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZmZmZmZ d dlmZmZ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m Z m!Z!m"Z"m#Z# d d
l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 er"d dl7m8Z8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z?m@Z@ d dlAmBZB  G d de      ZCdddedeDfdZEdeFdddedeFddf
dZGy)    )deepcopy)TYPE_CHECKINGAny	CoroutineOptionalSequenceTupleUnioncast)AddressChecksumAddress
HexAddressHexStr)
is_addressis_binary_addressis_checksum_addressto_checksum_address)merge)HexBytes)abis)BaseENS)EMPTY_ADDR_HEX"ENS_EXTENDED_RESOLVER_INTERFACE_IDENS_MAINNET_ADDR#ENS_MULTICHAIN_ADDRESS_INTERFACE_IDENS_TEXT_INTERFACE_IDREVERSE_REGISTRAR_DOMAIN)AddressMismatchENSValueErrorResolverNotFoundUnauthorizedErrorUnownedNameUnsupportedFunction)
address_inaddress_to_reverse_domaindefaultdns_encode_nameinit_async_web3is_empty_nameis_none_or_zero_addresslabel_to_hashnormal_name_to_hashnormalize_nameraw_name_to_hash)AsyncContractAsyncContractFunction)	AsyncWeb3)
Middleware)AsyncBaseProviderBaseProvider)TxParamsc                       e Zd ZU dZded<   	 	 	 d6ded   dee   deeed	e	f         d
dfdZ
e	 d7ddded
d fd       Z	 d7de	dee   d
ee   fdZ eee      ddfde	deeeef   dee   ded   d
ee   f
dZded
ee	   fdZ	 	 d8de	dee   ded   d
efdZde	d
efdZ	 	 d8de	deded   d
ee   fdZde	d
ed   fdZded
ed   fdZde	de	d
e	fdZ	 d7de	de	de	ddd
ef
d Z	 d9d!e	d"e	d
eed   e	f   fd#Z	 	 d8de	d$ee   ded   d
dfd%Z	 d9de	d"e	d
eeee	f      fd&Z 	 d7d'ede	d(ee	   d
dfd)Z!de	d
eee   ee	   e	f   fd*Z"	 	 d8d+ed,ee	   d-e	d.ee   ded   d
dfd/Z#	 d7dee	   deded   d
efd0Z$d:d1Z%	 d7de	d2d3d4ee&   ddd
ef
d5Z'y);AsyncENSaj  
    Quick access to common Ethereum Name Service functions,
    like getting the address for a name.

    Unless otherwise specified, all addresses are assumed to be a `str` in
    `checksum format <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md>`_,  # blocklint: pragma # noqa: E501
    like: ``"0x314159265dD8dbb310642f98f50C066173C1259b"``
    zAsyncWeb3[Any]w3Nproviderr3   addr
middlewarer2   returnc                    |xs t        dt              }t        ||      | _        |r|nt        }| j                  j
                  j                  t        j                  |      | _	        | j                  j
                  j                  t        j                        | _        | j                  j
                  j                  t        j                        | _        y)a7  
        :param provider: a single provider used to connect to Ethereum
        :type provider: instance of `web3.providers.base.BaseProvider`
        :param hex-string addr: the address of the ENS registry on-chain.
            If not provided, ENS.py will default to the mainnet ENS registry address.
        r3   )abiaddress)r>   N)r   r&   r(   r8   r   ethcontractr   ENSensPUBLIC_RESOLVER_2_EXTENDED_resolver_contractREVERSE_RESOLVER_reverse_resolver_contract)selfr9   r:   r;   ens_addrs        >/var/www/br/venv/lib/python3.12/site-packages/ens/async_ens.py__init__zAsyncENS.__init__g   s     At$7A!(J74%577;;''DHHh'G"&''++"6"6// #7 #
 +/''++*>*>%% +? +
'    c                     |j                   j                  }|j                  j                  } | t	        d|      ||      }|j
                  |_        |S )a  
        Generate an AsyncENS instance with web3

        :param `web3.Web3` w3: to infer connection information
        :param hex-string addr: the address of the ENS registry on-chain. If not
            provided, defaults to the mainnet ENS registry address.
        r3   )r:   r;   )managerr9   middleware_onionr;   r   strict_bytes_type_checking)clsr8   r:   r9   r;   nss         rJ   	from_web3zAsyncENS.from_web3   sO     ::&&((33
)844JW )+(E(E%	rL   name	coin_typec                 `  K   |(t        t        | j                  |d       d{         S | j                  |       d{   }t	        ||t
        d       d{    t        |      }|j                  j                  ||       d{   }t        |      ryt        |      S 7 7 f7 N7 !w)a  
        Look up the Ethereum address that `name` currently points to.

        :param str name: an ENS name to look up
        :param int coin_type: if provided, look up the address for this coin type
        :raises InvalidName: if `name` has invalid syntax
        Nr:   zaddr(bytes32,uint256))r   r   _resolveresolver)_async_validate_resolver_and_interface_idr   r.   callerr:   r*   r   )rH   rT   rU   rnodeaddress_as_bytess         rJ   r?   zAsyncENS.address   s       t}}T6/J)JKKmmD))A;a<>U   $D)D%&XX]]4%CC&'78&'788 *K)  DsE   "B.B&
B.B(B.B*.B.
B,B.(B.*B.,B.r?   transactr5   c                   K   |si }t        |      }| j                  ||       d{   }| j                  ||       d{    t        |      rd}nF|t        u r|}n;t        |      rt        t        t        |            }nt        |      st        d      | j                  |       d{   |k(  ry|t        }||d<   | j                  ||       d{   }t        |      }|3|j                  j!                  ||      j#                  |       d{   S |j                  j!                  |||      j#                  |       d{   S 7 ,7 7 7 7 B7 w)a  
        Set up the name to point to the supplied address.
        The sender of the transaction must own the name, or
        its parent name.

        Example: If the caller owns ``parentname.eth`` with no subdomains
        and calls this method with ``sub.parentname.eth``,
        then ``sub`` will be created as part of this call.

        :param str name: ENS name to set up
        :param str address: name will point to this address, in checksum format.
            If ``None``, erase the record. If not specified, name will point
            to the owner's address.
        :param int coin_type: if provided, set up the address for this coin type
        :param dict transact: the transaction configuration, like in
            :meth:`~web3.eth.Eth.send_transaction`
        :raises InvalidName: if ``name`` has invalid syntax
        :raises UnauthorizedError: if ``'from'`` in `transact` does not own `name`
        r^   N.You must supply the address in checksum formatfrom)r   setup_owner_assert_controlr*   r&   r   r   r   strr   r   r?   r   _set_resolverr.   	functionssetAddrr^   )rH   rT   r?   rU   r^   ownerrX   r\   s           rJ   setup_addresszAsyncENS.setup_address   s]    8 HH%&&th&??""5$///"7+GGw')$sG*<=G$W- PQQd##w.?$G *.*<*<TH*<*U$U%!++33D'BKKHUUU!++33D)WMVV  - @/ $ %V Vsj   &E"EE"EA,E"/E0+E"E?E"E3E"E E"E"E"E"E" E"c                    K   t        |      }| j                  |d       d{   }t        |      | j                  |       d{   k(  r|S dS 7 -7 w)z
        Look up the name that the address points to, using a
        reverse lookup. Reverse lookup is opt-in for name owners.

        :param address:
        :type address: hex-string
        rT   )fn_nameN)r%   rW   r   r?   )rH   r?   reversed_domainrT   s       rJ   rT   zAsyncENS.name   s^      4G<]]?F]CC
 (0$,,t:L4LLD	
RV	
	 D
 5Ms!   "AA"AAAAc                   K   |si }t        |      }|s6| j                  |d       d{    | j                  d||       d{   S | j                  |       d{   }t	        |      r|}n"|r ||k7  r|t
        k7  rt        d|d|d      t	        |      r| j                  |       d{   }t	        |      rt        d      t        |      rt        |      }t        |      st        d      | j                  ||       d{    |s| j                  |||       d{    | j                  |||       d{   S 7 $7 7 7 7 H7 ,7 w)	a  
        Set up the address for reverse lookup, aka "caller ID".
        After successful setup, the method :meth:`~ens.ENS.name` will return
        `name` when supplied with `address`.

        :param str name: ENS name that address will point to
        :param str address: address to set up, in checksum format
        :param dict transact: the transaction configuration, like in
            :meth:`~web3.eth.send_transaction`
        :raises AddressMismatch: if the name does not already point to the address
        :raises InvalidName: if `name` has invalid syntax
        :raises UnauthorizedError: if ``'from'`` in `transact` does not own `name`
        :raises UnownedName: if no one owns `name`
        zthe reverse recordNr`   zCould not set address z0 to point to name, because the name resolves to zI. To change the name for an existing address, call setup_address() first.z+claim subdomain using setup_address() firstra   )r   rd   _setup_reverser?   r*   r   r   ri   r"   r   r   r   r   rj   )rH   rT   r?   r^   resolveds        rJ   
setup_namezAsyncENS.setup_name   sm    ( HH%&&w0DEEE,,T7X,NNN!\\$//H&w/"g1h.6P%,WK 844<< @--  'w/ $

4 00&w/!"OPP )-g6&w/#$TUU&&w555((w(JJJ,,T7X,NNN1 FN/ 1 6JNs}   'EEEEEEAE2E3AEEE,E-EE	EEEEEEEc                 ~   K   t        |      }| j                  j                  j                  |       d{   S 7 w)a  
        Get the owner of a name. Note that this may be different from the
        deed holder in the '.eth' registrar. Learn more about the difference
        between deed and name ownership in the ENS `Managing Ownership docs
        <http://docs.ens.domains/en/latest/userguide.html#managing-ownership>`_

        :param str name: ENS name to look up
        :return: owner address
        :rtype: str
        N)r.   rC   rZ   ri   )rH   rT   r\   s      rJ   ri   zAsyncENS.owner*  s1       %XX__**40000s   4=;=	new_ownerc                   K   |xs t        t        t              }|si }t        |      }| j	                  |       d{   \  }}}|t        u r|}n|st        t
              }nt        |      }| j                  |       d{   }|t
        k(  r|sy||k(  r|S | j                  |||       d{    | j                  |||||       d{    |S 7 7 T7 (7 w)ad  
        Set the owner of the supplied name to `new_owner`.

        For typical scenarios, you'll never need to call this method directly,
        simply call :meth:`setup_name` or :meth:`setup_address`. This method does *not*
        set up the name to point to an address.

        If `new_owner` is not supplied, then this will assume you
        want the same owner as the parent domain.

        If the caller owns ``parentname.eth`` with no subdomains
        and calls this method with ``sub.parentname.eth``,
        then ``sub`` will be created as part of this call.

        :param str name: ENS name to set up
        :param new_owner: account that will own `name`. If ``None``,
            set owner to empty addr.  If not specified, name will point
            to the parent domain owner's address.
        :param dict transact: the transaction configuration, like in
            :meth:`~web3.eth.Eth.send_transaction`
        :raises InvalidName: if `name` has invalid syntax
        :raises UnauthorizedError: if ``'from'`` in `transact` does not own `name`
        :returns: the new owner's address
        Nr`   )
r   r   r&   r   _first_ownerr   r   ri   rd   _claim_ownership)rH   rT   rs   r^   super_ownerunownedownedcurrent_owners           rJ   rc   zAsyncENS.setup_owner8  s     < ?ow!?	HH%.2.?.?.E(E%gu#I'7I+I6I"jj..&}i'  &&{D%@@@''7E; (    # )F / AsF   <CCACC-C1C2CCCCCCr/   c                 `   K   t        |      }| j                  |       d{   }|d   S 7 	w)zZ
        Get the resolver for an ENS name.

        :param str name: The ENS name
        Nr   )r-   _get_resolver)rH   rT   normal_namerX   s       rJ   rX   zAsyncENS.resolverm  s4      %T*++K88{ 9s    .,
.target_addressc                 V   K   t        |      }| j                  |       d {   S 7 wN)r%   rX   )rH   r~   rm   s      rJ   reverserzAsyncENS.reverserw  s'      4NC]]?3333s    )')keyc                    K   t        |      }| j                  |       d{   }t        ||t        d       d{    |j                  j                  ||       d{   S 7 B7 *7 w)a  
        Get the value of a text record by key from an ENS name.

        :param str name: ENS name to look up
        :param str key: ENS name's text record key
        :return: ENS name's text record value
        :rtype: str
        :raises UnsupportedFunction: If the resolver does not support
            the "0x59d1d43c" interface id
        :raises ResolverNotFound: If no resolver is found for the provided name
        Ntext)r.   rX   rY   r   rZ   r   )rH   rT   r   r\   r[   s        rJ   get_textzAsyncENS.get_text  sj       %--%%7!*F
 	
 	
 XX]]4---	 &	
 .s1    A+A%A+A'#A+ A)!A+'A+)A+valuec                    K   | j                  |       d{   }t        ||t        d       d{    t        |      }| j	                  ||j
                  j                  |||f|       d{   S 7 \7 D7 w)aG  
        Set the value of a text record of an ENS name.

        :param str name: ENS name
        :param str key: The name of the attribute to set
        :param str value: Value to set the attribute to
        :param dict transact: The transaction configuration, like in
            :meth:`~web3.eth.Eth.send_transaction`
        :return: Transaction hash
        :rtype: HexBytes
        :raises UnsupportedFunction: If the resolver does not support
            the "0x59d1d43c" interface id
        :raises ResolverNotFound: If no resolver is found for the provided name
        NsetText)rX   rY   r   r.   _set_propertyrg   r   )rH   rT   r   r   r^   r[   r\   s          rJ   set_textzAsyncENS.set_text  s     * --%%7!*I
 	
 	
  %''!++%%c5'98
 
 	
 &	


s1   A:A4A:A6=A:/A80A:6A:8A:r}   rl   c                   K   |}	 t        |      rd |fS | j                  j                  j                  t	        |             d {   }t        |      s t        d| j                  ||            }||fS | j                  |      }7 Aw)Nr/   )	r)   rC   rZ   rX   r,   r*   r   _type_aware_resolverparent)rH   r}   rl   current_nameresolver_addrrX   s         rJ   r|   zAsyncENS._get_resolver  s     
 # \* \))"&((//":":#L1# M +=9#T%>%>}g%V  --  ;;|4L# s   AB
BAB
r   c                   K   |si }t        |      }t        |      r| j                  d       d {   }t        |      }| j                  j
                  j                  |       d {   |k7  r_t        t        t        t        t        f   | j                  j                  j                  ||      j                  |            }| d {    t        d| j                  |            S 7 7 7 $w)Nzresolver.ethr/   )r?   )r   r*   r?   r.   rC   rZ   rX   r   r   r   r   rg   setResolverr^   rE   )rH   rT   r   r^   namehashcoros         rJ   rf   zAsyncENS._set_resolver  s      HH%"=1"&,,~">>M#D)))(33}D#sH,-""..xGPPD JJOT%<%<]%<%STT ?3 s4   /C2C,7C2)C.*A!C2C0!C2.C20C2c                 V  K   t        |      }| j                  ||       d {   \  }}|sy | j                  |      }t        |t               d {   rl||gf} |j
                  | }|j                  j                  t        |      |       d {   }	| j                  |	||      }
t        |
      rt        |
      S |
S ||k(  rXt        |j                  |      } ||      j                          d {   }
t        |
      ry t        |
      rt        |
      S |
S y 7 7 7 7 /wr   )r-   r|   r   "_async_resolver_supports_interfacer   
encode_abirZ   resolver'   _decode_ensip10_resolve_datar   r   getattrrg   callr*   )rH   rT   rl   r}   rX   r   r\   contract_func_with_argscalldatacontract_call_resultresultlookup_functions               rJ   rW   zAsyncENS._resolve  sB    
 %T*'+'9'9+w'O!O,}}[) 48
 
 
 (/&7#*x**,CDH)1)@)@,* $  66$hF 3=V2D&v.P&PL(%h&8&8'BO*405577F&v.2<V2D&v.P&P7 "P
$ 8sG   !D)D!.D)D#A D)D%A#D)7D'8*D)#D)%D)'D)accountparent_ownedc           	         K   t        || j                  j                  j                   d {         st	        d|d|d|xs |      y 7 !w)Nzin order to modify z, you must control account z, which owns )r$   r8   r@   accountsr!   )rH   r   rT   r   s       rJ   rd   zAsyncENS._assert_control
  s[      ')=)=#=>#%dX .;mL,@D+CE  ?#=s   *AA
"Ac                 4  K   d}g }t        |      j                  d      }|rnt        |      rcdj                  |      }| j	                  |       d{   }t        |      r |j                  |j                  d             |rt        |      rc|||fS 7 Bw)z
        Takes a name, and returns the owner of the deepest subdomain that has an owner

        :returns: (owner or None, list(unowned_subdomain_labels), first_owned_domain)
        N.r   )r-   splitr*   joinri   appendpop)rH   rT   ri   rx   piecess        rJ   ru   zAsyncENS._first_owner  s      %++C00788F#D**T**E&u-vzz!}-	 07
 w%% +s   ABB<BBri   rx   ry   	old_ownerc           
      R  K   |si }t        |      }|xs ||d<   t        |      D ]{  }t        t        t        t        t
        f   | j                  j                  j                  t        |      t        |      |      j                  |            }| d {    | d| }} y 7 w)Nrb   r   )r   reversedr   r   r   r   rC   rg   setSubnodeOwnerr.   r+   r^   )rH   ri   rx   ry   r   r^   labelr   s           rJ   rv   zAsyncENS._claim_ownership(  s      HH%$-g& 
	'E#sH,-""22$U+!%( (8$D JJgQug&E
	' s   BB'B%B'c                    K   |rt        |      nd}|si }t        |      }||d<   | j                          d {   }|j                  j	                  |      j                  |       d {   S 7 67 w)N rb   )r-   r   _reverse_registrarrg   setNamer^   )rH   rT   r?   r^   reverse_registrars        rJ   ro   zAsyncENS._setup_reverse@  sr      (,~d#HH%""&"9"9";;&0088>GGQQQ <Qs!   7A4A01A4+A2,A42A4c                    K   | j                   j                  j                  t        t                     d {   }| j
                  j                  j                  |t        j                        S 7 9w)N)r?   r>   )
rC   rZ   ri   r,   r   r8   r@   rA   r   REVERSE_REGISTRAR)rH   r:   s     rJ   r   zAsyncENS._reverse_registrarN  sW     XX__** 89
 
 ww{{##Dd6L6L#MM
s   6A4A2:A4funcr0   argsc                    K   |si }| j                  |       d {   }t        d|i|      } || j                  |       d {   S 7 .7 w)Nrb   )ri   r   r^   )rH   rT   r   r   r^   ri   transact_from_owners          rJ   r   zAsyncENS._set_propertyT  sV      Hjj&&#VUOX>4[))*=>>> ' ?s!   AA
)AAAA)NNNr   )NN)r:   )r<   r/   )(__name__
__module____qualname____doc____annotations__r   r   r   r	   re   rK   classmethodrS   intr?   r   r&   r
   r   r   r   rj   rT   rq   ri   rc   rX   r   r   r   r|   rf   rW   rd   ru   rv   ro   r   r   r    rL   rJ   r7   r7   Z   s@    	 37*.CG	
./
 '
 XeL#,=&>?@	

 

0 ;?!)8	 , $(99 C=9 
/	"	9< @DW@
 $()-77 w;<7 C=7 :&7 
(	7r
/ 
hsm 
( .2)-	0O0O /*0O :&	0O
 
0Od1 1 1" &*)-	33 #3 :&	3
 
/	"3j3 8O+D 4-4	/	"4.3 .S .S .2  $

 
 	

 
 

H 55 5 
x(#-	.	5> 48)-	UU  0U :&	U
 
U2 "" " 
%,-	.	"P '+	
 
 
 sm	

 

&&	x((3-<	=&. 04)-'' #' 	'
 O,' :&' 
'8 *.	RsmR !R :&	R
 
RN  $?? &? sm	?
 ? 
?rL   r7   rX   r/   interface_idr<   c                    K   t        d | j                         D              xr# | j                  j                  |       d {   S 7 w)Nc              3   6   K   | ]  }d t        |      v   yw)supportsInterfaceN)repr).0r   s     rJ   	<genexpr>z5_async_resolver_supports_interface.<locals>.<genexpr>h  s      .2tDz)s   )anyall_functionsrZ   r   )rX   r   s     rJ   r   r   d  sJ       6>6L6L6N  @11,?
?@
?s   AA
AA
ens_nameens_interface_idinterface_nameNc                 ~   K   |st        d|  d      t        ||       d {   st        d|  d| d      y 7 w)NzNo resolver found for name `zH`. It is likely the name contains an unsupported top level domain (tld).zResolver for name `z` does not support the `z` interface.)r    r   r#   )r   rX   r   r   s       rJ   rY   rY   m  si      *8* 5> >
 	
 6h@PQQQ!!(+CNCS T 
 	
 Rs   !=;=)Hcopyr   typingr   r   r   r   r   r	   r
   r   
eth_typingr   r   r   r   	eth_utilsr   r   r   r   eth_utils.toolzr   hexbytesr   rC   r   ens.base_ensr   ens.constantsr   r   r   r   r   r   ens.exceptionsr   r   r    r!   r"   r#   	ens.utilsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   web3.contract.async_contractr/   r0   	web3.mainr1   web3.middleware.baser2   web3.providersr3   r4   
web3.typesr5   r7   boolr   re   rY   r   rL   rJ   <module>r      s   	 	 	        
G?w G?T@@@ 
@


 
 	

 

rL   