From dc63324d9aad74c8285654cc0bd89bcaf2a464f0 Mon Sep 17 00:00:00 2001 From: ligi Date: Sat, 26 Nov 2022 22:07:25 +0100 Subject: [PATCH] Prevent empty RPC (#1944) closes #173 --- _data/chains/eip155-144.json | 2 +- _data/chains/eip155-2203.json | 2 +- .../kotlin/org/ethereum/lists/chains/Main.kt | 28 +++++++++++-------- .../ethereum/lists/chains/model/Exceptions.kt | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/_data/chains/eip155-144.json b/_data/chains/eip155-144.json index c89fae1a..4d1cf582 100644 --- a/_data/chains/eip155-144.json +++ b/_data/chains/eip155-144.json @@ -1,7 +1,7 @@ { "name": "PHI Network v2", "chain": "PHI", - "rpc": ["https://connect.phi.network", ""], + "rpc": ["https://connect.phi.network"], "faucets": [], "nativeCurrency": { "name": "PHI", diff --git a/_data/chains/eip155-2203.json b/_data/chains/eip155-2203.json index b88d7ebe..fcd54848 100644 --- a/_data/chains/eip155-2203.json +++ b/_data/chains/eip155-2203.json @@ -1,7 +1,7 @@ { "name": "Bitcoin EVM", "chain": "Bitcoin EVM", - "rpc": ["https://connect.bitcoinevm.com", ""], + "rpc": ["https://connect.bitcoinevm.com"], "faucets": [], "nativeCurrency": { "name": "Bitcoin", diff --git a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt index b73b58ea..50297bd1 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -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()) } } } diff --git a/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt b/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt index 2c940ee3..a584bc0b 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt @@ -8,6 +8,7 @@ class ShouldHaveNoExtraFields(fields: Set) : Exception("should have no e class ShouldHaveNoMissingFields(fields: Set) : 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")