-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENS metadata and reverse ENS record set (#2116)
* ENS metadata and reverse ENS record Signed-off-by: Nischal Sharma <[email protected]> * updated name wrapper contract address Signed-off-by: Nischal Sharma <[email protected]> * set and get ENS text Signed-off-by: Nischal Sharma <[email protected]> * added tests Signed-off-by: Nischal Sharma <[email protected]> * added changelog entry Signed-off-by: Nischal Sharma <[email protected]> * resolved comments Signed-off-by: Nischal Sharma <[email protected]> --------- Signed-off-by: Nischal Sharma <[email protected]>
- Loading branch information
Showing
9 changed files
with
970 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
core/src/main/java/org/web3j/ens/EnsMetadataResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright 2024 Web3 Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.web3j.ens; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class EnsMetadataResponse { | ||
public boolean is_normalized; | ||
public String name; | ||
public String description; | ||
public Attribute[] attributes; | ||
public String url; | ||
public long last_request_date; | ||
public int version; | ||
public String background_image; | ||
public String image; | ||
public String image_url; | ||
|
||
public boolean isIs_normalized() { | ||
return is_normalized; | ||
} | ||
|
||
public void setIs_normalized(boolean is_normalized) { | ||
this.is_normalized = is_normalized; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public Attribute[] getAttributes() { | ||
return attributes; | ||
} | ||
|
||
public void setAttributes(Attribute[] attributes) { | ||
this.attributes = attributes; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
public long getLast_request_date() { | ||
return last_request_date; | ||
} | ||
|
||
public void setLast_request_date(long last_request_date) { | ||
this.last_request_date = last_request_date; | ||
} | ||
|
||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(int version) { | ||
this.version = version; | ||
} | ||
|
||
public String getBackground_image() { | ||
return background_image; | ||
} | ||
|
||
public void setBackground_image(String background_image) { | ||
this.background_image = background_image; | ||
} | ||
|
||
public String getImage() { | ||
return image; | ||
} | ||
|
||
public void setImage(String image) { | ||
this.image = image; | ||
} | ||
|
||
public String getImage_url() { | ||
return image_url; | ||
} | ||
|
||
public void setImage_url(String image_url) { | ||
this.image_url = image_url; | ||
} | ||
|
||
public static class Attribute { | ||
public String trait_type; | ||
public String display_type; | ||
public Object value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
try { | ||
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); | ||
} catch (JsonProcessingException e) { | ||
return "Error serializing EnsMetadataResponse: " + e.getMessage(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2024 Web3 Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.web3j.ens; | ||
|
||
import org.web3j.tx.ChainIdLong; | ||
|
||
public class NameWrapperUrl { | ||
|
||
public static final String BASE_URL = "https://ens-metadata-service.appspot.com/"; | ||
public static final String MAINNET_URL = | ||
BASE_URL + "mainnet/" + "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401/"; | ||
public static final String SEPOLIA_URL = | ||
BASE_URL + "sepolia/" + "0x0635513f179D50A207757E05759CbD106d7dFcE8/"; | ||
public static final String HOLESKY_URL = | ||
BASE_URL + "holesky/" + "0xab50971078225D365994dc1Edcb9b7FD72Bb4862/"; | ||
|
||
private NameWrapperUrl() {} | ||
|
||
public static String getEnsMetadataApi(String chainId) { | ||
final Long chainIdLong = Long.parseLong(chainId); | ||
if (chainIdLong.equals(ChainIdLong.MAINNET)) { | ||
return MAINNET_URL; | ||
} else if (chainIdLong.equals(ChainIdLong.SEPOLIA)) { | ||
return SEPOLIA_URL; | ||
} else if (chainIdLong.equals(ChainIdLong.HOLESKY)) { | ||
return HOLESKY_URL; | ||
} else { | ||
throw new EnsResolutionException( | ||
"Unable to get ENS metadata API for network id: " + chainId); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
core/src/main/java/org/web3j/ens/ReverseRegistrarContracts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2024 Web3 Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.web3j.ens; | ||
|
||
import org.web3j.tx.ChainIdLong; | ||
|
||
public class ReverseRegistrarContracts { | ||
|
||
public static final String MAINNET = "0xa58E81fe9b61B5c3fE2AFD33CF304c454AbFc7Cb"; | ||
public static final String SEPOLIA = "0xA0a1AbcDAe1a2a4A2EF8e9113Ff0e02DD81DC0C6"; | ||
public static final String HOLESKY = "0x132AC0B116a73add4225029D1951A9A707Ef673f"; | ||
public static final String LINEA = "0x08D3fF6E65f680844fd2465393ff6f0d742b67D5"; | ||
public static final String LINEA_SEPOLIA = "0x4aAA964D8EB65508ca3DA3b0A3C060c16059E613"; | ||
|
||
private ReverseRegistrarContracts() {} | ||
|
||
public static String resolveReverseRegistrarContract(String chainId) { | ||
final Long chainIdLong = Long.parseLong(chainId); | ||
if (chainIdLong.equals(ChainIdLong.MAINNET)) { | ||
return MAINNET; | ||
} else if (chainIdLong.equals(ChainIdLong.SEPOLIA)) { | ||
return SEPOLIA; | ||
} else if (chainIdLong.equals(ChainIdLong.HOLESKY)) { | ||
return HOLESKY; | ||
} else if (chainIdLong.equals(ChainIdLong.LINEA)) { | ||
return LINEA; | ||
} else if (chainIdLong.equals(ChainIdLong.LINEA_SEPOLIA)) { | ||
return LINEA_SEPOLIA; | ||
} else { | ||
throw new EnsResolutionException( | ||
"Unable to resolve ENS reverse registrar contract for network id: " + chainId); | ||
} | ||
} | ||
} |
Oops, something went wrong.