mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
Add ENS registries - closes #77
This commit is contained in:
parent
2d28a30ea4
commit
a84ec154dc
|
@ -16,5 +16,8 @@
|
||||||
"shortName": "eth",
|
"shortName": "eth",
|
||||||
"chainId": 1,
|
"chainId": 1,
|
||||||
"networkId": 1,
|
"networkId": 1,
|
||||||
"slip44": 60
|
"slip44": 60,
|
||||||
}
|
"ens": {
|
||||||
|
"registry":"0x314159265dd8dbb310642f98f50c066173c1259b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,5 +16,8 @@
|
||||||
"infoURL": "https://github.com/ethereum/ropsten",
|
"infoURL": "https://github.com/ethereum/ropsten",
|
||||||
"shortName": "rop",
|
"shortName": "rop",
|
||||||
"chainId": 3,
|
"chainId": 3,
|
||||||
"networkId": 3
|
"networkId": 3,
|
||||||
}
|
"ens": {
|
||||||
|
"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,5 +16,8 @@
|
||||||
"infoURL": "https://www.rinkeby.io",
|
"infoURL": "https://www.rinkeby.io",
|
||||||
"shortName": "rin",
|
"shortName": "rin",
|
||||||
"chainId": 4,
|
"chainId": 4,
|
||||||
"networkId": 4
|
"networkId": 4,
|
||||||
}
|
"ens": {
|
||||||
|
"registry":"0xe7410170f87102df0055eb195163a03b7f2bff4a"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,5 +19,8 @@
|
||||||
"infoURL": "https://goerli.net/#about",
|
"infoURL": "https://goerli.net/#about",
|
||||||
"shortName": "gor",
|
"shortName": "gor",
|
||||||
"chainId": 5,
|
"chainId": 5,
|
||||||
"networkId": 5
|
"networkId": 5,
|
||||||
}
|
"ens": {
|
||||||
|
"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.ethereum.lists.chains
|
||||||
|
|
||||||
import com.beust.klaxon.JsonObject
|
import com.beust.klaxon.JsonObject
|
||||||
import com.beust.klaxon.Klaxon
|
import com.beust.klaxon.Klaxon
|
||||||
|
import org.kethereum.functions.isValid
|
||||||
|
import org.kethereum.model.Address
|
||||||
import org.kethereum.rpc.HttpEthereumRPC
|
import org.kethereum.rpc.HttpEthereumRPC
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
|
@ -19,7 +21,8 @@ val mandatory_fields = listOf(
|
||||||
"nativeCurrency"
|
"nativeCurrency"
|
||||||
)
|
)
|
||||||
val optionalFields = listOf(
|
val optionalFields = listOf(
|
||||||
"slip44"
|
"slip44",
|
||||||
|
"ens"
|
||||||
)
|
)
|
||||||
|
|
||||||
class FileNameMustMatchChainId : Exception("chainId must match the filename")
|
class FileNameMustMatchChainId : Exception("chainId must match the filename")
|
||||||
|
@ -28,6 +31,9 @@ class ShouldHaveNoExtraFields(fields: Set<String>) : Exception("should have no e
|
||||||
class ShouldHaveNoMissingFields(fields: Set<String>) : Exception("missing field(s) $fields")
|
class ShouldHaveNoMissingFields(fields: Set<String>) : Exception("missing field(s) $fields")
|
||||||
class RPCMustBeList : Exception("rpc must be a list")
|
class RPCMustBeList : Exception("rpc must be a list")
|
||||||
class RPCMustBeListOfStrings : Exception("rpc must be a list of strings")
|
class RPCMustBeListOfStrings : Exception("rpc must be a list of strings")
|
||||||
|
class ENSMustBeObject: Exception("ens must be an object")
|
||||||
|
class ENSMustHaveOnlyRegistry: Exception("ens can only have a registry currently")
|
||||||
|
class ENSRegistryAddressMustBeValid: Exception("ens registry must have valid address")
|
||||||
|
|
||||||
fun checkChain(it: File, connectRPC: Boolean) {
|
fun checkChain(it: File, connectRPC: Boolean) {
|
||||||
println("processing $it")
|
println("processing $it")
|
||||||
|
@ -53,6 +59,21 @@ fun checkChain(it: File, connectRPC: Boolean) {
|
||||||
if (missingFields.isNotEmpty()) {
|
if (missingFields.isNotEmpty()) {
|
||||||
throw ShouldHaveNoMissingFields(missingFields)
|
throw ShouldHaveNoMissingFields(missingFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonObject["ens"]?.let {
|
||||||
|
if (it !is JsonObject) {
|
||||||
|
throw ENSMustBeObject()
|
||||||
|
}
|
||||||
|
if (it.keys != mutableSetOf("registry")) {
|
||||||
|
throw ENSMustHaveOnlyRegistry()
|
||||||
|
}
|
||||||
|
|
||||||
|
val address = Address(it["registry"] as String)
|
||||||
|
if (!address.isValid()) {
|
||||||
|
throw ENSRegistryAddressMustBeValid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (connectRPC) {
|
if (connectRPC) {
|
||||||
if (jsonObject["rpc"] is List<*>) {
|
if (jsonObject["rpc"] is List<*>) {
|
||||||
(jsonObject["rpc"] as List<*>).forEach {
|
(jsonObject["rpc"] as List<*>).forEach {
|
||||||
|
|
|
@ -39,6 +39,35 @@ class TheChainChecker {
|
||||||
checkChain(file, false)
|
checkChain(file, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(expected = ENSRegistryAddressMustBeValid::class)
|
||||||
|
fun shouldFailForInvalidENSAddress() {
|
||||||
|
val file = getFile("invalid/99.json")
|
||||||
|
|
||||||
|
checkChain(file, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ENSMustHaveOnlyRegistry::class)
|
||||||
|
fun shouldFailForExtraENSFields() {
|
||||||
|
val file = getFile("invalid/100.json")
|
||||||
|
|
||||||
|
checkChain(file, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ENSMustHaveOnlyRegistry::class)
|
||||||
|
fun shouldFailForNoRegistryField() {
|
||||||
|
val file = getFile("invalid/101.json")
|
||||||
|
|
||||||
|
checkChain(file, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ENSMustBeObject::class)
|
||||||
|
fun shouldFailForENSISNotObject() {
|
||||||
|
val file = getFile("invalid/102.json")
|
||||||
|
|
||||||
|
checkChain(file, false)
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = ExtensionMustBeJSON::class)
|
@Test(expected = ExtensionMustBeJSON::class)
|
||||||
fun shouldFailFoNonJSON() {
|
fun shouldFailFoNonJSON() {
|
||||||
val file = getFile("invalid/1.nojson")
|
val file = getFile("invalid/1.nojson")
|
||||||
|
|
23
src/test/resources/test_chains/invalid/100.json
Normal file
23
src/test/resources/test_chains/invalid/100.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"name": "Ethereum Mainnet",
|
||||||
|
"shortName": "eth",
|
||||||
|
"chain": "ETH",
|
||||||
|
"network": "mainnet",
|
||||||
|
"chainId": 100,
|
||||||
|
"networkId": 1,
|
||||||
|
"rpc": [
|
||||||
|
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
|
||||||
|
"https://api.mycryptoapi.com/eth"
|
||||||
|
],
|
||||||
|
"faucets": [],
|
||||||
|
"infoURL": "https://ethereum.org",
|
||||||
|
"nativeCurrency": {
|
||||||
|
"name": "Ether",
|
||||||
|
"symbol": "ETH",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
|
"ens": {
|
||||||
|
"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||||
|
"yolo": 1
|
||||||
|
}
|
||||||
|
}
|
21
src/test/resources/test_chains/invalid/101.json
Normal file
21
src/test/resources/test_chains/invalid/101.json
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"name": "Ethereum Mainnet",
|
||||||
|
"shortName": "eth",
|
||||||
|
"chain": "ETH",
|
||||||
|
"network": "mainnet",
|
||||||
|
"chainId": 101,
|
||||||
|
"networkId": 1,
|
||||||
|
"rpc": [
|
||||||
|
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
|
||||||
|
"https://api.mycryptoapi.com/eth"
|
||||||
|
],
|
||||||
|
"faucets": [],
|
||||||
|
"infoURL": "https://ethereum.org",
|
||||||
|
"nativeCurrency": {
|
||||||
|
"name": "Ether",
|
||||||
|
"symbol": "ETH",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
|
"ens": {
|
||||||
|
}
|
||||||
|
}
|
20
src/test/resources/test_chains/invalid/102.json
Normal file
20
src/test/resources/test_chains/invalid/102.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "Ethereum Mainnet",
|
||||||
|
"shortName": "eth",
|
||||||
|
"chain": "ETH",
|
||||||
|
"network": "mainnet",
|
||||||
|
"chainId": 102,
|
||||||
|
"networkId": 1,
|
||||||
|
"rpc": [
|
||||||
|
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
|
||||||
|
"https://api.mycryptoapi.com/eth"
|
||||||
|
],
|
||||||
|
"faucets": [],
|
||||||
|
"infoURL": "https://ethereum.org",
|
||||||
|
"nativeCurrency": {
|
||||||
|
"name": "Ether",
|
||||||
|
"symbol": "ETH",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
|
"ens": ""
|
||||||
|
}
|
22
src/test/resources/test_chains/invalid/99.json
Normal file
22
src/test/resources/test_chains/invalid/99.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "Ethereum Mainnet",
|
||||||
|
"shortName": "eth",
|
||||||
|
"chain": "ETH",
|
||||||
|
"network": "mainnet",
|
||||||
|
"chainId": 99,
|
||||||
|
"networkId": 1,
|
||||||
|
"rpc": [
|
||||||
|
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
|
||||||
|
"https://api.mycryptoapi.com/eth"
|
||||||
|
],
|
||||||
|
"faucets": [],
|
||||||
|
"infoURL": "https://ethereum.org",
|
||||||
|
"nativeCurrency": {
|
||||||
|
"name": "Ether",
|
||||||
|
"symbol": "ETH",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
|
"ens": {
|
||||||
|
"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010yolo"
|
||||||
|
}
|
||||||
|
}
|
26
src/test/resources/test_chains/valid/5.json
Normal file
26
src/test/resources/test_chains/valid/5.json
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"name": "Ethereum Testnet Görli",
|
||||||
|
"chain": "ETH",
|
||||||
|
"network": "goerli",
|
||||||
|
"rpc": [
|
||||||
|
"https://rpc.goerli.mudit.blog/",
|
||||||
|
"https://rpc.slock.it/goerli ",
|
||||||
|
"https://goerli.prylabs.net"
|
||||||
|
],
|
||||||
|
"faucets": [
|
||||||
|
"https://goerli-faucet.slock.it/?address=${ADDRESS}",
|
||||||
|
"https://faucet.goerli.mudit.blog"
|
||||||
|
],
|
||||||
|
"nativeCurrency": {
|
||||||
|
"name": "Görli Ether",
|
||||||
|
"symbol": "GOR",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
|
"infoURL": "https://goerli.net/#about",
|
||||||
|
"shortName": "gor",
|
||||||
|
"chainId": 5,
|
||||||
|
"networkId": 5,
|
||||||
|
"ens": {
|
||||||
|
"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user