Prevent empty RPC (#1944)

closes #173
This commit is contained in:
ligi 2022-11-26 22:07:25 +01:00 committed by GitHub
parent c5b56176aa
commit dc63324d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 13 deletions

View File

@ -1,7 +1,7 @@
{
"name": "PHI Network v2",
"chain": "PHI",
"rpc": ["https://connect.phi.network", ""],
"rpc": ["https://connect.phi.network"],
"faucets": [],
"nativeCurrency": {
"name": "PHI",

View File

@ -1,7 +1,7 @@
{
"name": "Bitcoin EVM",
"chain": "Bitcoin EVM",
"rpc": ["https://connect.bitcoinevm.com", ""],
"rpc": ["https://connect.bitcoinevm.com"],
"faucets": [],
"nativeCurrency": {
"name": "Bitcoin",

View File

@ -116,8 +116,13 @@ private fun createOutputFiles() {
}
private fun doChecks(doRPCConnect: Boolean, doIconDownload: Boolean, verbose: Boolean) {
allChainFiles.forEach {
checkChain(it, doRPCConnect, verbose)
allChainFiles.forEach { file ->
try {
checkChain(file, doRPCConnect, verbose)
} catch (exception: Exception) {
println("Problem with $file")
throw exception
}
}
val allIcons = iconsPath.listFiles() ?: return
@ -399,12 +404,16 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
parseWithMoshi(chainFile)
if (connectRPC) {
if (jsonObject["rpc"] is List<*>) {
(jsonObject["rpc"] as List<*>).forEach {
if (it !is String) {
throw (RPCMustBeListOfStrings())
} else {
if (jsonObject["rpc"] !is List<*>) {
throw (RPCMustBeList())
} else {
(jsonObject["rpc"] as List<*>).forEach {
if (it !is String) {
throw (RPCMustBeListOfStrings())
} else if (it.isEmpty()) {
throw (RPCCannotBeEmpty())
} else {
if (connectRPC) {
var chainId: BigInteger? = null
try {
println("connecting to $it")
@ -425,9 +434,6 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
}
}
}
println()
} else {
throw (RPCMustBeList())
}
}
}

View File

@ -8,6 +8,7 @@ class ShouldHaveNoExtraFields(fields: Set<String>) : Exception("should have no e
class ShouldHaveNoMissingFields(fields: Set<String>) : Exception("missing field(s) $fields")
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 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")