def address(self): """ Should be called to get client direct address @method address @returns {String} client direct address """ if self.isDirect(): base36 = self._iban[4:] asInt = int(base36, 36) return to_checksum_address(pad_left_hex(baseN(asInt, 16), 20)) return ""
def setup_owner(self, name, new_owner=default, transact={}): ''' 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.sendTransaction` :raises InvalidName: if `name` has invalid syntax :raises UnauthorizedError: if ``'from'`` in `transact` does not own `name` :returns: the new owner's address ''' (super_owner, unowned, owned) = self._first_owner(name) if new_owner is default: new_owner = super_owner elif not new_owner: new_owner = EMPTY_ADDR_HEX else: new_owner = to_checksum_address(new_owner) current_owner = self.owner(name) if new_owner == EMPTY_ADDR_HEX and not current_owner: return None elif current_owner == new_owner: return current_owner else: self._assert_control(super_owner, name, owned) self._claim_ownership(new_owner, unowned, owned, super_owner, transact=transact) return new_owner
def setup_name(self, name, address=None, transact={}): ''' Set up the address for reverse lookup, aka "caller ID". After successful setup, the method :meth:`~ens.main.ENS.name` will return `name` when supplied with `address`. :param str name: ENS name that address will point to :param str address: to set up, in checksum format :param dict transact: the transaction configuration, like in :meth:`~web3.eth.sendTransaction` :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` ''' if not name: self._assert_control(address, 'the reverse record') return self._setup_reverse(None, address, transact=transact) else: resolved = self.address(name) if not address: address = resolved elif resolved and address != resolved: raise AddressMismatch( "Could not set address %r to point to name, because the name resolves to %r. " "To change the name for an existing address, call setup_address() first." % (address, resolved)) if not address: address = self.owner(name) if not address: raise UnownedName( "claim subdomain using setup_address() first") if is_binary_address(address): address = to_checksum_address(address) if not is_checksum_address(address): raise ValueError( "You must supply the address in checksum format") self._assert_control(address, name) if not resolved: self.setup_address(name, address, transact=transact) return self._setup_reverse(name, address, transact=transact)
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)
def encode_abi(web3, abi, arguments, vmtype, data=None, setabi=None): arguments = list(arguments) if vmtype == 1: inputlength = len(abi['inputs']) if inputlength == len(arguments): if arguments: arrinputs = abi['inputs'] paramabi = encodeparameters(arrinputs, arguments, setabi) else: paramabi = [] else: raise Exception( 'The number of arguments is not matching the methods required number.' 'You need to pass {} arguments.'.format(inputlength)) magicnum = ['00', '61', '73', '6d'] paramabi.insert(0, fnv1_64(bytes(abi['name'], 'utf8'))) if abi['type'] == 'constructor': if data: data1 = bytes.fromhex(str(data, encoding='utf8')) deploydata = rlp.encode([data1, rlp.encode(paramabi)]) encodata = ''.join(magicnum) + deploydata.hex() return '0x' + encodata else: return '0x' + rlp.encode(paramabi).hex() else: encodata = rlp.encode(paramabi).hex() return '0x' + encodata else: argument_types = get_abi_input_types(abi) for j in range(len(argument_types)): if argument_types[j]: if argument_types[j] == 'address': hrpgot, data1 = bech32.decode(arguments[j][:3], arguments[j]) addr = to_checksum_address(bytes(data1)) arguments[j] = addr # .split(",") elif argument_types[j] == 'address[]': for i in range(len(arguments[j])): hrpgot, data1 = bech32.decode(arguments[j][i][:3], arguments[j][i]) addr = to_checksum_address(bytes(data1)) arguments[j][i] = addr if not check_if_arguments_can_be_encoded(abi, arguments, {}): raise TypeError( "One or more arguments could not be encoded to the necessary " "ABI type. Expected types are: {0}".format( ', '.join(argument_types), )) try: normalizers = [ abi_ens_resolver(web3), abi_address_to_hex, abi_bytes_to_bytes, abi_string_to_text, ] normalized_arguments = map_abi_data( normalizers, argument_types, arguments, ) encoded_arguments = eth_abi_encode_abi( argument_types, normalized_arguments, ) except EncodingError as e: raise TypeError( "One or more arguments could not be encoded to the necessary " "ABI type: {0}".format(str(e))) if data: return to_hex(HexBytes(data) + encoded_arguments) else: return encode_hex(encoded_arguments)
def to_checksum_address(self) -> ChecksumAddress: return to_checksum_address(public_key_bytes_to_address(self.to_bytes()))
}], "payable": False, "stateMutability": "view", "type": "function" }] tx = contract_deploy(bytecode, from_address) print(tx) tx_receipt = platon.waitForTransactionReceipt(tx) print(tx_receipt) contractAddress = tx_receipt.contractAddress print(contractAddress) # contractAddress = bech32.bech32_decode(contractAddress) hrpgot, data = bech32.decode("lax", from_address) address = to_checksum_address(bytes(data)) print('qqq') print(address) def SendTxn(txn): signed_txn = platon.account.signTransaction(txn, private_key=send_privatekey) res = platon.sendRawTransaction(signed_txn.rawTransaction).hex() txn_receipt = platon.waitForTransactionReceipt(res) print(res) return txn_receipt # print(len([10, 14, 31, 23, 10, 20, 20, 9, 15, 9, 0, 15, 12, 20, 6, 15, 12, 8, 5, 6, 28, 22, 7, 25, 11, 30, 2, 27, 10, 23, 19, 11])) contract_instance = platon.contract(address=contractAddress, abi=abi)