
    (iT              
          d dl mZ d dl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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 er d dl6m7Z7 d dl8m9Z9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@  G d de      ZAdeBdddedeBddf
dZCdddedeDfdZEy)    )deepcopy)TYPE_CHECKINGAny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_web3is_empty_nameis_none_or_zero_addresslabel_to_hashnormal_name_to_hashnormalize_nameraw_name_to_hash)Web3)ContractContractFunction)
Middleware)BaseProvider)TxParamsc                      e Zd ZU dZded<   	 	 	 d6ddd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);ENSaj  
    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"``
    r/   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)aC  
        :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(   r7   r   ethcontractr   r6   ensPUBLIC_RESOLVER_2_EXTENDED_resolver_contractREVERSE_RESOLVER_reverse_resolver_contract)selfr8   r9   r:   ens_addrs        8/var/www/br/venv/lib/python3.12/site-packages/ens/ens.py__init__zENS.__init__c   s     <tNG<Hj14%577;;''DHHh'G"&''++"6"6// #7 #
 +/''++*>*>%% +? +
'    c                     |j                   j                  }|j                  j                  } | t	        d|      ||      }|j
                  |_        |S )a+  
        Generate an ENS instance from a Web3 instance

        :param `web3.Web3` w3: to infer connection, middleware, and codec information
        :param hex-string addr: the address of the ENS registry on-chain. If not
            provided, defaults to the mainnet ENS registry address.
        r3   )r9   r:   )managerr8   middleware_onionr:   r
   strict_bytes_type_checking)clsr7   r9   r8   r:   nss         rH   	from_web3zENS.from_web3|   sN     ::&&((33
nh/dzR )+(E(E%	rJ   name	coin_typec                    | t        t        | j                  |d            S | j                  |      }t	        ||t
        d       t        |      }|j                  j                  ||      }t        |      ryt        |      S )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
        :raises ResolverNotFound: if no resolver found for `name`
        :raises UnsupportedFunction: if the resolver does not support the ``addr()``
                function
        Nr9   zaddr(bytes32,uint256))r
   r   _resolveresolver#_validate_resolver_and_interface_idr   r.   callerr9   r*   r   )rF   rR   rS   rnodeaddress_as_bytess         rH   r>   zENS.address   s~      tV)DEEd#A/a<>U $D)D xx}}T9=&'78&'788rJ   r>   transactr4   c                 D   |si }t        |      }| j                  ||      }| j                  ||       t        |      rd}nF|t        u r|}n;t        |      rt        t        t        |            }nt        |      st        d      | j                  |      |k(  ry|t        }||d<   | j                  ||      }t        |      }|+|j                  j!                  ||      j#                  |      S |j                  j!                  |||      j#                  |      S )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\   )rF   rR   r>   rS   r\   ownerrV   rZ   s           rH   setup_addresszENS.setup_address   s   8 HH%   9UD)"7+GGw')$sG*<=G$W- PQQ<<(?$G #11$1J%%%--dG<EEhOO%%--dIwGPP rJ   c                     t        |      }| j                  |d      }t        |      | j                  |      k(  r|S dS )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
        rR   )fn_nameN)r%   rU   r   r>   )rF   r>   reversed_domainrR   s       rH   rR   zENS.name   sB     4G<}}_f}= +73t||D7IItStSrJ   c                 &   |si }t        |      }|s&| j                  |d       | j                  d||      S | j                  |      }t	        |      r|}n"|r ||k7  r|t
        k7  rt        d|d|d      t	        |      r| j                  |      }t	        |      rt        d      t        |      rt        |      }t        |      st        d      | j                  ||       |s| j                  |||       | j                  |||      S )	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() firstr_   )r   rb   _setup_reverser>   r*   r   r   rg   r"   r   r   r   r   rh   )rF   rR   r>   r\   resolveds        rH   
setup_namezENS.setup_name   s)   ( HH%  *>?&&tWx&HH||D)H&w/"g1h.6P%,WK 844<< @--  'w/**T*&w/!"OPP )-g6&w/#$TUU  $/""48"D&&tWx&HHrJ   c                 b    t        |      }| j                  j                  j                  |      S )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
        )r.   rA   rX   rg   )rF   rR   rZ   s      rH   rg   z	ENS.owner'  s'      %xx$$T**rJ   	new_ownerc                 h   |xs t        t        t              }|si }t        |      }| j	                  |      \  }}}|t        u r|}n|st        t
              }nt        |      }| j                  |      }|t
        k(  r|sy||k(  r|S | j                  |||       | j                  |||||       |S )ac  
        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   rg   rb   _claim_ownership)rF   rR   rq   r\   super_ownerunownedownedcurrent_owners           rH   ra   zENS.setup_owner5  s    < ?ow!?	HH%(,(9(9$(?%gu#I'7I+I6I

4(&}i'    dE:!!7E; "  rJ   r0   c                 @    t        |      }| j                  |      d   S )zZ
        Get the resolver for an ENS name.

        :param str name: The ENS name
        r   )r-   _get_resolver)rF   rR   normal_names      rH   rV   zENS.resolverk  s$     %T*!!+.q11rJ   target_addressc                 :    t        |      }| j                  |      S N)r%   rV   )rF   r|   rk   s      rH   reverserzENS.reversert  s    3NC}}_--rJ   keyc                     t        |      }| j                  |      }t        ||t        d       |j                  j                  ||      S )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
        text)r.   rV   rW   r   rX   r   )rF   rR   r   rZ   rY   s        rH   get_textzENS.get_textz  s@      %MM$+D!5JFSxx}}T3''rJ   valuec                     | j                  |      }t        ||t        d       t        |      }| j	                  ||j
                  j                  |||f|      S )aC  
        Set the value of a text record of an ENS name.

        :param str name: ENS name
        :param str key: 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
        r   )rV   rW   r   r.   _set_propertyre   setText)rF   rR   r   r   r\   rY   rZ   s          rH   set_textzENS.set_text  sX    * MM$+D!5JFS%!!!++%%c5'98
 	
rJ   r{   rj   c                     |}	 t        |      rd |fS | j                  j                  j                  t	        |            }t        |      s t        d| j                  ||            }||fS | j                  |      }z)Nr0   )	r)   rA   rX   rV   r,   r*   r
   _type_aware_resolverparent)rF   r{   rj   current_nameresolver_addrrV   s         rH   rz   zENS._get_resolver  s    
 # \* \)) HHOO445H5VWM*=9 9 9- Q  --  ;;|4L rJ   r   c                 `   |si }t        |      }t        |      r| j                  d      }t        |      }| j                  j
                  j                  |      |k7  r5| j                  j                  j                  ||      j                  |       t        d| j                  |            S )Nzresolver.ethr0   )r>   )r   r*   r>   r.   rA   rX   rV   re   setResolverr\   r
   rC   )rF   rR   r   r\   namehashs        rH   rd   zENS._set_resolver  s     HH%"=1 LL8M#D)88??##H->HH**8]CLLXVJ 7 7 7 NOOrJ   c                    t        |      }| j                  ||      \  }}|sy | j                  |      }t        |t              rd||gf} |j
                  | }|j                  j                  t        |      |      }	| j                  |	||      }
t        |
      rt        |
      S |
S ||k(  rPt        |j                  |      } ||      j                         }
t        |
      ry t        |
      rt        |
      S |
S y r~   )r-   rz   r   _resolver_supports_interfacer   
encode_abirX   resolver'   _decode_ensip10_resolve_datar   r   getattrre   callr*   )rF   rR   rj   r{   rV   r   rZ   contract_func_with_argscalldatacontract_call_resultresultlookup_functions               rH   rU   zENS._resolve  s    %T*!%!3!3K!I,}}[) (2TU'.&7#*x**,CDH#+??#:#:,$  66$hF 3=V2D&v.P&PL(%h&8&8'BO$T*//1F&v.2<V2D&v.P&PrJ   accountparent_ownedc           	          t        || j                  j                  j                        st	        d|d|d|xs |      y )Nzin order to modify z, you must control account z, which owns )r$   r7   r?   accountsr!   )rF   r   rR   r   s       rH   rb   zENS._assert_control  sQ     '477;;#7#78#%dX .;mL,@D+CE  9rJ   c                    d}g }t        |      j                  d      }|rft        |      r[dj                  |      }| j	                  |      }t        |      r |j                  |j                  d             |rt        |      r[|||fS )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*   joinrg   appendpop)rF   rR   rg   rv   piecess        rH   rs   zENS._first_owner   s     %++C00788F#DJJt$E&u-vzz!}-	 07
 w%%rJ   rg   rv   rw   	old_ownerc                     |si }t        |      }|xs ||d<   t        |      D ]Q  }| j                  j                  j	                  t        |      t        |      |      j                  |       | d| }S y )Nr`   r   )r   reversedrA   re   setSubnodeOwnerr.   r+   r\   )rF   rg   rv   rw   r   r\   labels          rH   rt   zENS._claim_ownership  s     HH%$-g& 	'EHH.. 'e$ hx gQug&E	'rJ   c                     |rt        |      nd}|si }t        |      }||d<   | j                         j                  j	                  |      j                  |      S )N r`   )r-   r   _reverse_registrarre   setNamer\   )rF   rR   r>   r\   s       rH   rm   zENS._setup_reverse&  sY     (,~d#HH%"&&(22::4@II(SSrJ   c                     | j                   j                  j                  t        t                    }| j
                  j                  j                  |t        j                        S )N)r>   r=   )
rA   rX   rg   r,   r   r7   r?   r@   r   REVERSE_REGISTRAR)rF   r9   s     rH   r   zENS._reverse_registrar3  sE    xx$$%89Q%RSww{{##Dd6L6L#MMrJ   funcr1   argsc                 p    |si }| j                  |      }t        d|i|      } || j                  |      S )Nr`   )rg   r   r\   )rF   rR   r   r   r\   rg   transact_from_owners          rH   r   zENS._set_property7  sA     H

4 #VUOX>T{##$788rJ   )NNNr~   )NN)r9   )r;   r0   )(__name__
__module____qualname____doc____annotations__r   r   r   r   rc   rI   classmethodrQ   intr>   r
   r&   r	   r   r   r   rh   rR   ro   rg   ra   rV   r   r   r   rz   rd   rU   rb   rs   rt   rm   r   r   r    rJ   rH   r6   r6   V   s,    	J $( $CG	
 
 
 XeL#,=&>?@	

 

2 6  E  ( $(99 C=9 
/	"	9B @DW@
 $()-88 w;<8 C=8 :&8 
(	8tTO T T$ .2)-	0I0I /*0I :&	0I
 
0Id+# +/ +" &*)-	44 #4 :&	4
 
/	"4l2S 2Xj%9 2. .8J;O .(S (s (s (.  $

 
 	

 
 

D 55 5 
x
#S(	)	5: 48)-	PP  0P :&	P
 
P" )/"%	%,-	.F '+	
 
 
 sm	

 

&&	x((3-<	=&. 04)-'' #' 	'
 O,' :&' 
'0 *.	TsmT !T :&	T
 
TN  $99 !9 sm	9
 9 
9rJ   r6   ens_namerV   r0   ens_interface_idinterface_namer;   Nc                 b    |st        d|  d      t        ||      st        d|  d| d      y )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   rV   r   r   s       rH   rW   rW   G  s_     *8* 5> >
 	
 *(4DE!!(+CNCS T 
 	
 FrJ   c                 |    t        d | j                         D              xr | j                  j                  |      S )Nc              3   6   K   | ]  }d t        |      v   yw)supportsInterfaceN)repr).0r   s     rH   	<genexpr>z/_resolver_supports_interface.<locals>.<genexpr>]  s      .2tDz)s   )anyall_functionsrX   r   )rV   r   s     rH   r   r   Y  s?      6>6L6L6N  >
//
+
+,<
=>rJ   )Fcopyr   typingr   r   r   r   r   r	   r
   
eth_typingr   r   r   r   	eth_utilsr   r   r   r   eth_utils.toolzr   hexbytesr   r   r   base_ensr   	constantsr   r   r   r   r   r   
exceptionsr   r   r    r!   r"   r#   utilsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   web3r/   web3.contract.contractr0   r1   web3.middleware.baser2   web3.providersr3   
web3.typesr4   r6   rc   rW   boolr   r   rJ   rH   <module>r      s             
n9' n9b


 
 	

 

$>>> 
>rJ   