Ejemplo n.º 1
0
def set_resolver(signer, github_handle, nonce, gas_multiplier=1.101):
    if mock_request:
        return '0x7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39'

    ns = ENS.fromWeb3(w3)
    resolver_addr = ns.address('resolver.eth')
    signer = Web3.toChecksumAddress(signer)
    txn_hash = None
    gas_price = get_gas_price(gas_multiplier)
    subdomain = f"{github_handle}.{settings.ENS_TLD}"

    transaction = {
        'from': Web3.toChecksumAddress(settings.ENS_OWNER_ACCOUNT),
        'value': 0,
        'nonce': nonce,
        'gas': Web3.toHex(RESOLVER_GAS_COST),
        'gasPrice': Web3.toHex(int(float(gas_price))),
    }

    ens_contract = w3.eth.contract(address=ENS_MAINNET_ADDR, abi=ens_abi, )
    txn = ens_contract.functions.setResolver(dot_eth_namehash(subdomain), resolver_addr, ).buildTransaction(transaction)
    signed_txn = w3.eth.account.signTransaction(txn, private_key=settings.ENS_PRIVATE_KEY)
    try:
        txn_hash = convert_txn(w3.eth.sendRawTransaction(signed_txn.rawTransaction))
    except ValueError as e:
        logger.warning(f'{e} - set_resolver')

    return txn_hash
Ejemplo n.º 2
0
    def setup_address(self, name, address=default, transact={}):
        '''
        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, in checksum format
        :param str address: name will point to this address. If ``None``, erase the record.
            If not specified, name will point to the owner's address.
        :param dict transact: the transaction configuration, like in
            :meth:`~web3.eth.Eth.sendTransaction`
        :raises InvalidName: if ``name`` has invalid syntax
        :raises UnauthorizedError: if ``'from'`` in `transact` does not own `name`
        '''
        owner = self.setup_owner(name, transact=transact)
        self._assert_control(owner, name)
        if not address or address == EMPTY_ADDR_HEX:
            address = None
        elif address is default:
            address = owner
        elif not is_checksum_address(address):
            raise ValueError("You must supply the address in checksum format")
        if self.address(name) == address:
            return None
        if address is None:
            address = EMPTY_ADDR_HEX
        transact['from'] = owner
        resolver = self._set_resolver(name, transact=transact)
        return resolver.setAddr(dot_eth_namehash(name), address, transact=transact)
Ejemplo n.º 3
0
 def _set_resolver(self, name, resolver_addr=None, transact={}):
     if not resolver_addr:
         resolver_addr = self.address('resolver.eth')
     namehash = dot_eth_namehash(name)
     if self.ens.resolver(namehash) != resolver_addr:
         self.ens.setResolver(namehash, resolver_addr, transact=transact)
     return self._resolverContract(address=resolver_addr)
Ejemplo n.º 4
0
    def setup_address(self, name, address=default, transact={}):
        '''
        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, in checksum format
        :param str address: name will point to this address. If ``None``, erase the record.
            If not specified, name will point to the owner's address.
        :param dict transact: the transaction configuration, like in
            :meth:`~web3.eth.Eth.sendTransaction`
        :raises InvalidName: if ``name`` has invalid syntax
        :raises UnauthorizedError: if ``'from'`` in `transact` does not own `name`
        '''
        owner = self.setup_owner(name, transact=transact)
        self._assert_control(owner, name)
        if not address or address == EMPTY_ADDR_HEX:
            address = None
        elif address is default:
            address = owner
        elif is_binary_address(address):
            address = to_checksum_address(address)
        elif not is_checksum_address(address):
            raise ValueError("You must supply the address in checksum format")
        if self.address(name) == address:
            return None
        if address is None:
            address = EMPTY_ADDR_HEX
        transact['from'] = owner
        resolver = self._set_resolver(name, transact=transact)
        return resolver.setAddr(dot_eth_namehash(name), address, transact=transact)
Ejemplo n.º 5
0
 def _claim_ownership(self, owner, unowned, owned, old_owner=None, transact={}):
     transact['from'] = old_owner or owner
     for label in reversed(unowned):
         self.ens.setSubnodeOwner(
             dot_eth_namehash(owned),
             label_to_hash(label),
             owner,
             transact=transact
         )
         owned = "%s.%s" % (label, owned)
Ejemplo n.º 6
0
 def _claim_ownership(self, owner, unowned, owned, old_owner=None, transact={}):
     transact['from'] = old_owner or owner
     for label in reversed(unowned):
         self.ens.setSubnodeOwner(
             dot_eth_namehash(owned),
             label_to_hash(label),
             owner,
             transact=transact
         )
         owned = "%s.%s" % (label, owned)
Ejemplo n.º 7
0
 def resolve(self, name, get='addr'):
     resolver = self.resolver(name)
     if resolver:
         lookup_function = getattr(resolver, get)
         resolved = lookup_function(dot_eth_namehash(name))
         if is_address(resolved):
             resolved = to_checksum_address(resolved)
         return resolved
     else:
         return None
Ejemplo n.º 8
0
 def _set_resolver(self, name, resolver_addr=None, transact={}):
     if not resolver_addr:
         resolver_addr = self.address('resolver.eth')
     namehash = dot_eth_namehash(name)
     if self.ens.resolver(namehash) != resolver_addr:
         self.ens.setResolver(
             namehash,
             resolver_addr,
             transact=transact
         )
     return self._resolverContract(address=resolver_addr)
Ejemplo n.º 9
0
    def owner(self, name):
        '''
        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
        '''
        node = dot_eth_namehash(name)
        return self.ens.owner(node)
Ejemplo n.º 10
0
    def owner(self, name):
        '''
        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
        '''
        node = dot_eth_namehash(name)
        return self.ens.owner(node)
Ejemplo n.º 11
0
Archivo: views.py Proyecto: sthorpe/web
def set_resolver(signer, github_handle, nonce, gas_multiplier=1):
    if mock_request:
        return '0x7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39'

    ns = ENS.fromWeb3(w3)
    resolver_addr = ns.address('resolver.eth')
    signer = Web3.toChecksumAddress(signer)
    txn_hash = None
    gasPrice = recommend_min_gas_price_to_confirm_in_time(
        1) * 10**9 if not settings.DEBUG else 15 * 10**9 * gas_multiplier
    subdomain = f"{github_handle}.{settings.ENS_TLD}"

    transaction = {
        'from': Web3.toChecksumAddress(settings.ENS_OWNER_ACCOUNT),
        'value': 0,
        'nonce': nonce,
        'gas': Web3.toHex(100000),
        'gasPrice': Web3.toHex(int(float(gasPrice))),
    }

    ens_contract = w3.eth.contract(
        address=ENS_MAINNET_ADDR,
        abi=ens_abi,
    )
    txn = ens_contract.functions.setResolver(
        dot_eth_namehash(subdomain),
        resolver_addr,
    ).buildTransaction(transaction)
    signed_txn = w3.eth.account.signTransaction(
        txn, private_key=settings.ENS_PRIVATE_KEY)
    txn_hash = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

    # hack to convert
    # "b'7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39'"
    # to "0x7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39"
    txn_hash = str(binascii.b2a_hex(txn_hash)).replace("b'",
                                                       "0x").replace("'", "")

    return txn_hash
Ejemplo n.º 12
0
def set_owner(signer, github_handle, nonce):
    if mock_request:
        return '0x7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39'
    owned = settings.ENS_TLD
    label = github_handle
    txn_hash = None
    gasPrice = recommend_min_gas_price_to_confirm_in_time(
        1) * 10**9 if not settings.DEBUG else 15 * 10**9

    transaction = {
        'from': Web3.toChecksumAddress(settings.ENS_OWNER_ACCOUNT),
        'value': 0,
        'nonce': nonce,
        'gas': Web3.toHex(100000),
        'gasPrice': Web3.toHex(int(float(gasPrice))),
    }

    ens_contract = w3.eth.contract(
        address=ENS_MAINNET_ADDR,
        abi=ens_abi,
    )

    txn = ens_contract.functions.setSubnodeOwner(
        dot_eth_namehash(owned),
        label_to_hash(label),
        Web3.toChecksumAddress(settings.ENS_OWNER_ACCOUNT),
    ).buildTransaction(transaction)
    signed_txn = w3.eth.account.signTransaction(
        txn, private_key=settings.ENS_PRIVATE_KEY)
    txn_hash = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

    # hack to convert
    # "b'7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39'"
    # to "0x7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39"
    txn_hash = str(binascii.b2a_hex(txn_hash)).replace("b'",
                                                       "0x").replace("'", "")

    return txn_hash
Ejemplo n.º 13
0
 def _reverse_registrar(self):
     addr = self.ens.owner(dot_eth_namehash(REVERSE_REGISTRAR_DOMAIN))
     return self.web3.eth.contract(address=addr, abi=abis.REVERSE_REGISTRAR)
Ejemplo n.º 14
0
 def resolver(self, name):
     resolver_addr = self.ens.resolver(dot_eth_namehash(name))
     if not resolver_addr:
         return None
     return self._resolverContract(address=resolver_addr)