Check RPC schemas

This commit is contained in:
ligi 2022-11-27 09:57:12 +01:00
parent 87417e5e6d
commit 5accff5810
3 changed files with 9 additions and 2 deletions

View File

@ -44,4 +44,7 @@ val ipfs by lazy {
Moshi.Builder().build()
)
)
}
}
val httpPrefixes = listOf("https://", "http://")
val rpcPrefixes = httpPrefixes + listOf("wss://", "ws://")

View File

@ -315,7 +315,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
}
val url = explorer["url"]
if (url == null || url !is String || !(url.startsWith("https://") || url.startsWith("http://"))) {
if (url == null || url !is String || httpPrefixes.none { prefix -> url.startsWith(prefix) } ) {
throw (ExplorerMustWithHttpsOrHttp())
}
@ -412,6 +412,8 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
throw (RPCMustBeListOfStrings())
} else if (it.isBlank()) {
throw (RPCCannotBeEmpty())
} else if (rpcPrefixes.none { prefix -> it.startsWith(prefix) }) {
throw (InvalidRPCPrefix(it))
} else {
if (connectRPC) {
var chainId: BigInteger? = null

View File

@ -1,5 +1,6 @@
package org.ethereum.lists.chains.model
import org.ethereum.lists.chains.rpcPrefixes
import java.io.File
class FileNameMustMatchChainId : Exception("chainId must match the filename")
@ -9,6 +10,7 @@ class ShouldHaveNoMissingFields(fields: Set<String>) : Exception("missing field(
class RPCMustBeList : Exception("rpc must be a list")
class RPCMustBeListOfStrings : Exception("rpc must be a list of strings")
class RPCCannotBeEmpty : Exception("rpc cannot be empty")
class InvalidRPCPrefix(prefix: String) : Exception("rpc has invalid prefix: $prefix - must be any of $rpcPrefixes")
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")