Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/main/kotlin/org/ethereum/lists/tokens/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject
import com.beust.klaxon.Klaxon
import java.io.File
import java.nio.file.Files
import kotlin.system.exitProcess
import org.kethereum.model.ChainId

Expand Down Expand Up @@ -67,13 +66,23 @@ fun getChainId(networkName: String) = networkMapping[networkName]?.let {
}

private fun checkForTokenDefinitionsInWrongPath() {
File(".").walk().forEach { path ->
if (path.isDirectory
&& !Files.isSameFile((path.parentFile ?: path).toPath(), allNetworksTokenDir.toPath())
&& !path.absolutePath.contains("/test_tokens/")
) {
path.list()?.firstOrNull { it.startsWith("0x") }?.let {
throw IllegalArgumentException("There is a token definition file ($it) placed in a directory where it does not belong (${path.absolutePath})")
val tokensRoot = allNetworksTokenDir.toPath().toAbsolutePath().normalize()
val testTokensRoot = File("src/test/resources/test_tokens").toPath().toAbsolutePath().normalize()

File(".").walk().forEach { candidate ->
if (!candidate.isDirectory) {
return@forEach
}

val normalizedPath = candidate.toPath().toAbsolutePath().normalize()
val isTokensDir = normalizedPath.startsWith(tokensRoot)
val isTestTokensDir = normalizedPath.startsWith(testTokensRoot)

if (!isTokensDir && !isTestTokensDir) {
candidate.list()?.firstOrNull { it.startsWith("0x") }?.let {
throw IllegalArgumentException(
"There is a token definition file ($it) placed in a directory where it does not belong ($normalizedPath)"
)
}
}
}
Expand All @@ -97,4 +106,4 @@ fun List<JsonObject>.copyFields(fields: List<String>): JsonArray<JsonObject> {
minimalJSONArray.add(minimalJsonObject)
}
return minimalJSONArray
}
}
Loading