Improve symbol checks and shorten symbols to <7 chars

closes #1069
This commit is contained in:
ligi 2022-04-11 14:15:52 +02:00
parent 6c3e788d32
commit ff736c8d27
No known key found for this signature in database
GPG Key ID: 8E81894010ABF23D
5 changed files with 35 additions and 6 deletions

View File

@ -9,7 +9,7 @@
],
"nativeCurrency": {
"name": "MetaDot Token TestNet",
"symbol": "MTT-test",
"symbol": "MTTest",
"decimals": 18
},
"infoURL": "https://metadot.network",

View File

@ -10,7 +10,7 @@
"faucets": [],
"nativeCurrency": {
"name": "milkTAda",
"symbol": "milkTAda",
"symbol": "mTAda",
"decimals": 18
},
"infoURL": "https://milkomeda.com",
@ -24,4 +24,4 @@
"standard": "none"
}
]
}
}

View File

@ -9,11 +9,11 @@
],
"nativeCurrency": {
"name": "Lisinski Ether",
"symbol": "LISINSKI",
"symbol": "LISINS",
"decimals": 18
},
"infoURL": "https://lisinski.online",
"shortName": "lisinski",
"chainId": 385,
"networkId": 385
}
}

View File

@ -171,6 +171,29 @@ fun checkChain(chainFile: File, connectRPC: Boolean) {
}
}
jsonObject["nativeCurrency"]?.let {
if (it !is JsonObject) {
throw NativeCurrencyMustBeObject()
}
val symbol = it["symbol"]
if (symbol !is String) {
throw NativeCurrencySymbolMustBeString()
}
if (symbol.length >= 7) {
throw NativeCurrencySymbolMustHaveLessThan7Chars()
}
if (it.keys != setOf("symbol","decimals","name")) {
throw NativeCurrencyCanOnlyHaveSymbolNameAndDecimals()
}
if (it["decimals"] !is Int) {
throw NativeCurrencyDecimalMustBeInt()
}
if (it["name"] !is String) {
throw NativeCurrencyNameMustBeString()
}
}
jsonObject["explorers"]?.let {
if (it !is JsonArray<*>) {
throw (ExplorersMustBeArray())

View File

@ -26,4 +26,10 @@ class ParentBridgeNoArray: Exception("parent bridge must be array")
class BridgeNoObject: Exception("parent bridges must be array consisting of json objects")
class BridgeOnlyURL: Exception("parent bridge only contain an URL")
class ParentChainDoesNotExist(chain: String): Exception("Referenced parent chain ($chain) does not exist")
class DeprecatedMustBeBoolean: Exception("deprecated must be boolean")
class DeprecatedMustBeBoolean: Exception("deprecated must be boolean")
class NativeCurrencyMustBeObject: Exception("Native currency must be object")
class NativeCurrencySymbolMustBeString: Exception("Native currency symbol must be string")
class NativeCurrencySymbolMustHaveLessThan7Chars: Exception("Native currency symbol must have less than 7 chars")
class NativeCurrencyCanOnlyHaveSymbolNameAndDecimals: Exception("Native currency can only have symbol decimals and name")
class NativeCurrencyDecimalMustBeInt: Exception("Native currency decimals must be int")
class NativeCurrencyNameMustBeString: Exception("Native currency name must be string")