Check for Strings that are blank or have leading/trailing spaces

This commit is contained in:
ligi 2022-12-12 01:17:51 +01:00
parent ba442eaadb
commit 49cefee645
4 changed files with 21 additions and 8 deletions

View File

@ -320,9 +320,11 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
}
if (url.endsWith("/")) {
throw (ExplorerCannotEndInSlash())
throw ExplorerCannotEndInSlash()
}
url.checkString("Explorer URL")
if (explorer["standard"] != "EIP3091" && explorer["standard"] != "none") {
throw (ExplorerStandardMustBeEIP3091OrNone())
}
@ -360,9 +362,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
throw FaucetMustBeString()
}
if (it.isBlank()) {
throw FaucetMustBeString()
}
it.checkString("Faucet URL")
}
}
@ -376,6 +376,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
throw RedFlagMustBeString()
}
it.checkString("Red flag")
if (!allowedRedFlags.contains(it))
throw (InvalidRedFlags(it))
}
@ -427,11 +428,10 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
(jsonObject["rpc"] as List<*>).forEach {
if (it !is String) {
throw (RPCMustBeListOfStrings())
} else if (it.isBlank()) {
throw (RPCCannotBeEmpty())
} else if (rpcPrefixes.none { prefix -> it.startsWith(prefix) }) {
throw (InvalidRPCPrefix(it))
} else {
it.checkString("RPC URL")
if (connectRPC) {
var chainId: BigInteger? = null
try {
@ -457,6 +457,16 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
}
}
private fun String.checkString(which: String) {
if (isBlank()) {
throw StringCannotBeBlank(which)
}
if (trim() != this) {
throw StringCannotHaveExtraSpaces(which)
}
}
fun String.normalizeName() = replace(" ", "").uppercase()
/*

View File

@ -22,6 +22,9 @@ class ExplorersMustBeArray: Exception("explorers must be an array")
class ExplorerMustHaveName: Exception("Explorer must have name")
class ExplorerMustWithHttpsOrHttp: Exception("Explorer have url starting with https:// or http://")
class ExplorerCannotEndInSlash: Exception("Explorer cannot have a slash on the end")
class StringCannotBeBlank(which: String): Exception("$which cannot be blank")
class StringCannotHaveExtraSpaces(which: String): Exception("$which cannot have leading or tailing spaces")
class ExplorerStandardMustBeEIP3091OrNone: Exception("explorer standard must be 'none' or 'EIP3091'")
class ParentHasInvalidType(type: String?): Exception("Parent has invalid type $type - only L2 or shard allowed")
class RedFlagsMustBeArray: Exception("redFlags not an array")

View File

@ -3,7 +3,7 @@
"chain": "ETH",
"rpc": [
"https://rpc.goerli.mudit.blog/",
"https://rpc.slock.it/goerli ",
"https://rpc.slock.it/goerli",
"https://goerli.prylabs.net"
],
"faucets": [

View File

@ -3,7 +3,7 @@
"chain": "ETH",
"rpc": [
"https://rpc.goerli.mudit.blog/",
"https://rpc.slock.it/goerli ",
"https://rpc.slock.it/goerli",
"https://goerli.prylabs.net"
],
"faucets": [