def set_owner(signer, github_handle, nonce, gas_multiplier=1.101): if mock_request: return '0x7bce7e4bcd2fea4d26f3d254bb8cf52b9ee8dd7353b19bfbc86803c27d9bbf39' owned = settings.ENS_TLD label = github_handle txn_hash = None gas_price = get_gas_price(gas_multiplier) transaction = { 'from': Web3.toChecksumAddress(settings.ENS_OWNER_ACCOUNT), 'value': 0, 'nonce': nonce, 'gas': Web3.toHex(OWNER_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.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) try: txn_hash = convert_txn(w3.eth.sendRawTransaction(signed_txn.rawTransaction)) except ValueError as e: logger.warning(f'{e} - set_owner') return txn_hash
def setAlaDIDPublicEntity(self, node_name, label, DID, name, DIDDocument, active, new_owner_address, caller_key): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) label_hash = label_to_hash(label) # Calculate the hash of the DID DIDHash = b.Web3.keccak(text=DID) success, tx_receipt, tx_hash = b.send_signed_tx( PublicResolver.functions.setAlaDIDPublicEntity( node_hash, label_hash, DIDHash, name, DIDDocument, active, new_owner_address, ), caller_key) return success, tx_receipt, tx_hash
def _claim_ownership(self, owner, unowned, owned, old_owner=None, transact={}): transact['from'] = old_owner or owner for label in reversed(unowned): self.ens.functions.setSubnodeOwner( raw_name_to_hash(owned), label_to_hash(label), owner ).transact(transact) owned = "%s.%s" % (label, owned)
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)
def _claim_ownership(self, owner: ChecksumAddress, unowned: Sequence[str], owned: str, old_owner: ChecksumAddress = None, transact: "TxParams" = {}) -> None: transact['from'] = old_owner or owner for label in reversed(unowned): self.ens.functions.setSubnodeOwner(raw_name_to_hash(owned), label_to_hash(label), owner).transact(transact) owned = "%s.%s" % (label, owned)
def _claim_ownership(self, owner: ChecksumAddress, unowned: Sequence[str], owned: str, old_owner: Optional[ChecksumAddress] = None, transact: Optional["TxParams"] = None) -> None: if not transact: transact = {} transact = deepcopy(transact) transact['from'] = old_owner or owner for label in reversed(unowned): self.ens.functions.setSubnodeOwner(raw_name_to_hash(owned), label_to_hash(label), owner).transact(transact) owned = f"{label}.{owned}"
def setSubnodeOwner(self, node_name="root", label=None, new_owner_address=None, current_owner_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) label_hash = label_to_hash(label) contract_fun = ENS.functions.setSubnodeOwner(node_hash, label_hash, new_owner_address) success, tx_receipt, tx_hash = b.send_signed_tx( contract_fun, current_owner_key) return success, tx_receipt, tx_hash
def setAlaTSP(self, node_name, label, URI, org, active, current_owner_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) label_hash = label_to_hash(label) contract_fun = PublicResolver.functions.setAlaTSP( node_hash, label_hash, URI, org, active) success, tx_receipt, tx_hash = b.send_signed_tx( contract_fun, current_owner_key) return success, tx_receipt, tx_hash
def addAlaTSPService(self, node_name, label, X509SKI, serviceName, X509Certificate, active, current_owner_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) label_hash = label_to_hash(label) contract_fun = PublicResolver.functions.addAlaTSPService( node_hash, label_hash, X509SKI, serviceName, X509Certificate, active) success, tx_receipt, tx_hash = b.send_signed_tx( contract_fun, current_owner_key) return success, tx_receipt, tx_hash
def set_owner(signer, github_handle, nonce, gas_multiplier=1): 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 * gas_multiplier 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
def labelhash(label: str) -> HexBytes: return label_to_hash(label)
def get_registrars(ens): startBlock = None lastRegistrar = None for log in ens.events.NewOwner.getLogs(argument_filters={'node': ZERO_HASH, 'label': label_to_hash('eth')}, fromBlock=0, toBlock='latest'): if lastRegistrar is not None: yield (lastRegistrar, startBlock, int(log.blockNumber)) auctionRegistrar = w3.eth.contract(abi=AUCTION_REGISTRAR_ABI, address=log.args.owner) try: auctionRegistrar.functions.entries(ZERO_HASH).call() lastRegistrar = auctionRegistrar logging.info("Auction registrar %s at block %d", log.args.owner, log.blockNumber) except (web3.exceptions.BadFunctionCallOutput, ValueError) as e: permanentRegistrar = w3.eth.contract(abi=BASE_REGISTRAR_ABI, address=log.args.owner) try: permanentRegistrar.functions.nameExpires(0).call() lastRegistrar = permanentRegistrar logging.info("Permanent registrar %s at %d", log.args.owner, log.blockNumber) except (web3.exceptions.BadFunctionCallOutput, ValueError) as e: logging.error("Unrecognised .eth registrar contract %s at block %d", log.args.owner, log.blockNumber) lastRegistrar = None startBlock = int(log.blockNumber) if lastRegistrar is not None: yield (lastRegistrar, startBlock, 'latest')