@Test public void testReverseResolve() throws Exception { configureSyncing(false); configureLatestBlock(System.currentTimeMillis() / 1000); NetVersion netVersion = new NetVersion(); netVersion.setResult(Byte.toString(ChainId.MAINNET)); String resolverAddress = "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a"; String contractName = "0x0000000000000000000000000000000000000000000000000000000000000020" + TypeEncoder.encode(new Utf8String("web3j.eth")); System.err.println(contractName); EthCall resolverAddressResponse = new EthCall(); resolverAddressResponse.setResult(resolverAddress); EthCall contractNameResponse = new EthCall(); contractNameResponse.setResult(contractName); when(web3jService.send(any(Request.class), eq(NetVersion.class))) .thenReturn(netVersion); when(web3jService.send(any(Request.class), eq(EthCall.class))) .thenReturn(resolverAddressResponse); when(web3jService.send(any(Request.class), eq(EthCall.class))) .thenReturn(contractNameResponse); assertThat(ensResolver.reverseResolve("0x19e03255f667bdfd50a32722df860b1eeaf4d635"), is("web3j.eth")); }
public String reverseResolve(String address) { if (WalletUtils.isValidAddress(address)) { String reverseName = Numeric.cleanHexPrefix(address) + REVERSE_NAME_SUFFIX; PublicResolver resolver = obtainPublicResolver(reverseName); byte[] nameHash = NameHash.nameHashAsBytes(reverseName); String name = null; try { name = resolver.name(nameHash).send(); } catch (Exception e) { throw new RuntimeException("Unable to execute Ethereum request", e); } if (!isValidEnsName(name)) { throw new RuntimeException("Unable to resolve name for address: " + address); } else { return name; } } else { throw new EnsResolutionException("Address is invalid: " + address); } }
EnsResolver { public String reverseResolve(String address) { if (WalletUtils.isValidAddress(address)) { String reverseName = Numeric.cleanHexPrefix(address) + REVERSE_NAME_SUFFIX; PublicResolver resolver = obtainPublicResolver(reverseName); byte[] nameHash = NameHash.nameHashAsBytes(reverseName); String name = null; try { name = resolver.name(nameHash).send(); } catch (Exception e) { throw new RuntimeException("Unable to execute Ethereum request", e); } if (!isValidEnsName(name)) { throw new RuntimeException("Unable to resolve name for address: " + address); } else { return name; } } else { throw new EnsResolutionException("Address is invalid: " + address); } } }
EnsResolver { public String reverseResolve(String address) { if (WalletUtils.isValidAddress(address)) { String reverseName = Numeric.cleanHexPrefix(address) + REVERSE_NAME_SUFFIX; PublicResolver resolver = obtainPublicResolver(reverseName); byte[] nameHash = NameHash.nameHashAsBytes(reverseName); String name = null; try { name = resolver.name(nameHash).send(); } catch (Exception e) { throw new RuntimeException("Unable to execute Ethereum request", e); } if (!isValidEnsName(name)) { throw new RuntimeException("Unable to resolve name for address: " + address); } else { return name; } } else { throw new EnsResolutionException("Address is invalid: " + address); } } EnsResolver(Web3j web3j, long syncThreshold);  EnsResolver(Web3j web3j); }
EnsResolver { public String reverseResolve(String address) { if (WalletUtils.isValidAddress(address)) { String reverseName = Numeric.cleanHexPrefix(address) + REVERSE_NAME_SUFFIX; PublicResolver resolver = obtainPublicResolver(reverseName); byte[] nameHash = NameHash.nameHashAsBytes(reverseName); String name = null; try { name = resolver.name(nameHash).send(); } catch (Exception e) { throw new RuntimeException("Unable to execute Ethereum request", e); } if (!isValidEnsName(name)) { throw new RuntimeException("Unable to resolve name for address: " + address); } else { return name; } } else { throw new EnsResolutionException("Address is invalid: " + address); } } EnsResolver(Web3j web3j, long syncThreshold);  EnsResolver(Web3j web3j); void setSyncThreshold(long syncThreshold); long getSyncThreshold(); PublicResolver obtainPublicResolver(String ensName); String resolve(String contractId); String reverseResolve(String address); static boolean isValidEnsName(String input); }
EnsResolver { public String reverseResolve(String address) { if (WalletUtils.isValidAddress(address)) { String reverseName = Numeric.cleanHexPrefix(address) + REVERSE_NAME_SUFFIX; PublicResolver resolver = obtainPublicResolver(reverseName); byte[] nameHash = NameHash.nameHashAsBytes(reverseName); String name = null; try { name = resolver.name(nameHash).send(); } catch (Exception e) { throw new RuntimeException("Unable to execute Ethereum request", e); } if (!isValidEnsName(name)) { throw new RuntimeException("Unable to resolve name for address: " + address); } else { return name; } } else { throw new EnsResolutionException("Address is invalid: " + address); } } EnsResolver(Web3j web3j, long syncThreshold);  EnsResolver(Web3j web3j); void setSyncThreshold(long syncThreshold); long getSyncThreshold(); PublicResolver obtainPublicResolver(String ensName); String resolve(String contractId); String reverseResolve(String address); static boolean isValidEnsName(String input);  }