Skip to content

Commit

Permalink
Sort chains by chainID in json files - closes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
ligi committed Jul 11, 2021
1 parent 4fe1b85 commit 449a39e
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/kotlin/org/ethereum/lists/chains/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,25 @@ private fun createOutputFiles() {
val chainJSONArray = JsonArray<JsonObject>()
val miniChainJSONArray = JsonArray<JsonObject>()

allChainFiles.forEach {
val jsonObject = Klaxon().parseJsonObject(it.reader())
chainJSONArray.add(jsonObject)
fullJSONFile.writeText(chainJSONArray.toJsonString())
prettyJSONFile.writeText(chainJSONArray.toJsonString(prettyPrint = true))

val miniJSON = JsonObject()
listOf("name", "chainId", "shortName", "networkId", "nativeCurrency", "rpc", "faucets", "infoURL").forEach { field ->
jsonObject[field]?.let { content ->
miniJSON[field] = content
allChainFiles
.map { Klaxon().parseJsonObject(it.reader()) }
.sortedBy { (it["chainId"] as Number).toLong() }
.forEach { jsonObject ->
chainJSONArray.add(jsonObject)
fullJSONFile.writeText(chainJSONArray.toJsonString())
prettyJSONFile.writeText(chainJSONArray.toJsonString(prettyPrint = true))

val miniJSON = JsonObject()
listOf("name", "chainId", "shortName", "networkId", "nativeCurrency", "rpc", "faucets", "infoURL").forEach { field ->
jsonObject[field]?.let { content ->
miniJSON[field] = content
}
}
}
miniChainJSONArray.add(miniJSON)
miniChainJSONArray.add(miniJSON)

miniJSONFile.writeText(miniChainJSONArray.toJsonString())
prettyMiniJSONFile.writeText(miniChainJSONArray.toJsonString(prettyPrint = true))
}
miniJSONFile.writeText(miniChainJSONArray.toJsonString())
prettyMiniJSONFile.writeText(miniChainJSONArray.toJsonString(prettyPrint = true))
}

File(buildPath, "index.html").writeText(
"""
Expand Down

0 comments on commit 449a39e

Please sign in to comment.