mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
Check if icons are referenced
also remove one unreferenced icon
This commit is contained in:
parent
6d16398f74
commit
8f9a9327c6
Binary file not shown.
Before Width: | Height: | Size: 86 KiB |
|
@ -4,15 +4,10 @@ import com.beust.klaxon.JsonArray
|
|||
import java.io.File
|
||||
import com.beust.klaxon.JsonObject
|
||||
import com.beust.klaxon.Klaxon
|
||||
import com.squareup.moshi.Moshi
|
||||
import io.ipfs.kotlin.IPFS
|
||||
import io.ipfs.kotlin.IPFSConfiguration
|
||||
import okhttp3.OkHttpClient
|
||||
import org.ethereum.lists.chains.model.*
|
||||
import org.kethereum.erc55.isValid
|
||||
import org.kethereum.model.Address
|
||||
import org.kethereum.rpc.HttpEthereumRPC
|
||||
import java.time.Duration
|
||||
import kotlin.io.OnErrorAction.*
|
||||
|
||||
val parsedShortNames = mutableSetOf<String>()
|
||||
|
@ -97,8 +92,13 @@ private fun doChecks(doRPCConnect: Boolean, doIconDownload: Boolean) {
|
|||
}
|
||||
|
||||
val allIcons = iconsPath.listFiles() ?: return
|
||||
val allIconCIDs = mutableSetOf<String>()
|
||||
allIcons.forEach {
|
||||
checkIcon(it, doIconDownload)
|
||||
checkIcon(it, doIconDownload, allIconCIDs)
|
||||
}
|
||||
|
||||
iconsDownloadPath.listFiles().forEach {
|
||||
if (!allIconCIDs.contains(it.name)) throw UnreferencedIcon(it.name, iconsDownloadPath)
|
||||
}
|
||||
|
||||
allFiles.filter { it.isDirectory }.forEach { _ ->
|
||||
|
@ -106,7 +106,7 @@ private fun doChecks(doRPCConnect: Boolean, doIconDownload: Boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
fun checkIcon(icon: File, withIconDownload: Boolean) {
|
||||
fun checkIcon(icon: File, withIconDownload: Boolean, allIconCIDs: MutableSet<String>) {
|
||||
println("checking Icon " + icon.name)
|
||||
val obj: JsonArray<*> = Klaxon().parseJsonArray(icon.reader())
|
||||
println("found variants " + obj.size)
|
||||
|
@ -121,6 +121,8 @@ fun checkIcon(icon: File, withIconDownload: Boolean) {
|
|||
error("url must start with ipfs://")
|
||||
}
|
||||
|
||||
allIconCIDs.add(url.removePrefix("ipfs://"))
|
||||
|
||||
if (withIconDownload) {
|
||||
|
||||
|
||||
|
@ -329,7 +331,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
fun String.normalizeName() = replace(" ","").uppercase()
|
||||
fun String.normalizeName() = replace(" ", "").uppercase()
|
||||
|
||||
/*
|
||||
moshi fails for extra commas
|
||||
|
@ -359,6 +361,6 @@ private fun getNumber(jsonObject: JsonObject, field: String): Long {
|
|||
return when (val chainId = jsonObject[field]) {
|
||||
is Int -> chainId.toLong()
|
||||
is Long -> chainId
|
||||
else -> throw(Exception("not a number at $field"))
|
||||
else -> throw (Exception("not a number at $field"))
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package org.ethereum.lists.chains.model
|
||||
|
||||
import java.io.File
|
||||
|
||||
class FileNameMustMatchChainId : Exception("chainId must match the filename")
|
||||
class ExtensionMustBeJSON : Exception("filename extension must be json")
|
||||
class ShouldHaveNoExtraFields(fields: Set<String>) : Exception("should have no extra field $fields")
|
||||
|
@ -34,3 +36,5 @@ class NativeCurrencySymbolMustHaveLessThan7Chars: Exception("Native currency sym
|
|||
class NativeCurrencyCanOnlyHaveSymbolNameAndDecimals: Exception("Native currency can only have symbol decimals and name")
|
||||
class NativeCurrencyDecimalMustBeInt: Exception("Native currency decimals must be int")
|
||||
class NativeCurrencyNameMustBeString: Exception("Native currency name must be string")
|
||||
|
||||
class UnreferencedIcon(fileName: String, iconsDownloadPath: File): Exception("Found file $fileName in $iconsDownloadPath that is not referenced")
|
Loading…
Reference in New Issue
Block a user