Normalize names and shortNames (#1412)

This commit is contained in:
ligi 2022-08-04 12:50:58 +02:00 committed by GitHub
parent 62a13890ba
commit 4ba4ca129c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{
"name": "OM Chain Mainnet",
"chain": "omchain",
"name": "OM Platform Mainnet",
"chain": "omplatform",
"network": "mainnet",
"rpc": [
"https://rpc-cnx.omplatform.com/"

View File

@ -14,7 +14,7 @@
"decimals": 18
},
"infoURL": "https://reichain.io",
"shortName": "rei",
"shortName": "reichain",
"chainId": 55555,
"networkId": 55555,
"explorers": [{

View File

@ -11,7 +11,7 @@
"decimals": 18
},
"infoURL": "https://ellaism.org",
"shortName": "ella",
"shortName": "ellaism",
"chainId": 64,
"networkId": 64,
"slip44": 163

View File

@ -329,26 +329,30 @@ fun checkChain(chainFile: File, connectRPC: Boolean) {
}
}
fun String.normalizeName() = replace(" ","").uppercase()
/*
moshi fails for extra commas
https://github.com/ethereum-lists/chains/issues/126
*/
private fun parseWithMoshi(fileToParse: File) {
val parsedChain = chainAdapter.fromJson(fileToParse.readText())
if (parsedNames.contains(parsedChain!!.name)) {
throw NameMustBeUnique(parsedChain.name)
val parsedChainNormalizedName = parsedChain!!.name.normalizeName()
if (parsedNames.contains(parsedChainNormalizedName)) {
throw NameMustBeUnique(parsedChainNormalizedName)
}
parsedNames.add(parsedChain.name)
parsedNames.add(parsedChainNormalizedName)
if (parsedShortNames.contains(parsedChain.shortName)) {
throw ShortNameMustBeUnique(parsedChain.shortName)
val parsedChainNormalizedShortName = parsedChain.shortName.normalizeName()
if (parsedShortNames.contains(parsedChainNormalizedShortName)) {
throw ShortNameMustBeUnique(parsedChainNormalizedShortName)
}
if (parsedChain.shortName == "*") {
if (parsedChainNormalizedShortName == "*") {
throw ShortNameMustNotBeStar()
}
parsedShortNames.add(parsedChain.shortName)
parsedShortNames.add(parsedChainNormalizedShortName)
}
private fun getNumber(jsonObject: JsonObject, field: String): Long {