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 94d9d755..482a1bdc 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -26,6 +26,7 @@ private val allChainFiles = allFiles.filter { !it.isDirectory } private val allIconFilesList = iconsPath.listFiles() ?: error("${iconsPath.absolutePath} must contain the icon json files - but it does not") private val allIconFiles = allIconFilesList.filter { !it.isDirectory } +private val allUsedIcons = mutableSetOf() fun main(args: Array) { @@ -34,7 +35,7 @@ fun main(args: Array) { val verbose = argsList.contains("verbose").also { argsList.remove("verbose") } if (argsList.firstOrNull() == "singleChainCheck") { val file = File(File(".."), args.last()) - if (file.exists() && file.parentFile == chainsPath ) { + if (file.exists() && file.parentFile == chainsPath) { println("checking single chain " + args.last()) checkChain(file, true, verbose) } @@ -129,13 +130,26 @@ private fun doChecks(doRPCConnect: Boolean, doIconDownload: Boolean, verbose: Bo checkIcon(it, doIconDownload, allIconCIDs, verbose) } + val unusedIconDownload = mutableSetOf() iconsDownloadPath.listFiles()?.forEach { - if (!allIconCIDs.contains(it.name)) throw UnreferencedIcon(it.name, iconsDownloadPath) + if (!allIconCIDs.contains(it.name)) unusedIconDownload.add(it.name) + } + if (unusedIconDownload.isNotEmpty()) { + throw UnreferencedIcon(unusedIconDownload.joinToString (" ") , iconsDownloadPath) } - allFiles.filter { it.isDirectory }.forEach { _ -> error("should not contain a directory") } + + val unusedIcons = mutableSetOf() + iconsPath.listFiles().forEach { + if (!allUsedIcons.contains(it.name.toString().removeSuffix(".json"))) { + unusedIcons.add(it.toString()) + } + } + if (unusedIcons.isNotEmpty()) { + error("error: unused icons ${unusedIcons.joinToString(" ")}") + } } fun checkIcon(icon: File, withIconDownload: Boolean, allIconCIDs: MutableSet, verbose: Boolean) { @@ -255,9 +269,13 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { } jsonObject["icon"]?.let { + if (it !is String) { + error("icon must be string") + } if (!File(iconsPath, "$it.json").exists()) { error("The Icon $it does not exist - was used in ${chainFile.name}") } + allUsedIcons.add(it) } val nameRegex = Regex("^[a-zA-Z0-9\\-\\.\\(\\) ]+$") @@ -312,6 +330,10 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { throw (ExplorerMustHaveName()) } + if (explorer["icon"] != null) { + allUsedIcons.add(explorer["icon"].toString()) + } + val url = explorer["url"] if (url == null || url !is String || httpPrefixes.none { prefix -> url.startsWith(prefix) }) { throw (ExplorerMustWithHttpsOrHttp()) 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 5d263f1c..647f5eb5 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 @@ -53,4 +53,4 @@ class ChainNameMustBeString: Exception("Name must be string") class IllegalName(type: String,name: String): Exception("Invalid $type: $name") -class UnreferencedIcon(fileName: String, iconsDownloadPath: File): Exception("Found file $fileName in $iconsDownloadPath that is not referenced") \ No newline at end of file +class UnreferencedIcon(fileName: String, iconsDownloadPath: File): Exception("Found unreference $fileName in $iconsDownloadPath") \ No newline at end of file