Skip to content

Commit

Permalink
Added support for eip-1191
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansmirnoff committed Apr 16, 2020
1 parent 04e0bf2 commit 13d2cd7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ This web tool should help getting the checksum: https://ethsum.netlify.com
- `community`: Twitter, Reddit, Slack or wherever else people hang out.
- `website`: Official URL of the website.

#### EIP-1191
It was added the option to support [EIP-1191](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1191.md). By default it will be used [ERC-55](https://eips.ethereum.org/EIPS/eip-55).
To allow [EIP-1191](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1191.md) for a particular network, it is needed to update `src/main/org/ethereum/lists/tokens/Main.kt` and add your network in `getEip1191ChainId` function.


# The assembled lists

Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
KOTLIN_VERSION = "1.3.71"
KETHEREUM_VERSION = "0.81.6"
KETHEREUM_VERSION = "0.81.7"
}

repositories {
Expand Down Expand Up @@ -51,6 +51,7 @@ dependencies {

compile "com.github.komputing.kethereum:erc20:${KETHEREUM_VERSION}"
compile "com.github.komputing.kethereum:erc55:${KETHEREUM_VERSION}"
compile "com.github.komputing.kethereum:erc1191:${KETHEREUM_VERSION}"
compile "com.github.komputing.kethereum:model:${KETHEREUM_VERSION}"
compile "com.github.komputing.kethereum:rpc:${KETHEREUM_VERSION}"
compile "com.github.komputing.kethereum:rpc_min3:${KETHEREUM_VERSION}"
Expand Down
22 changes: 17 additions & 5 deletions src/main/kotlin/org/ethereum/lists/tokens/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import org.ethereum.lists.cilib.copyFields
import java.io.File
import java.nio.file.Files
import kotlin.system.exitProcess
import org.kethereum.model.ChainId


val networkMapping = mapOf("etc" to 61, "eth" to 1, "kov" to 42, "rin" to 4, "rop" to 3, "rsk" to 40, "ella" to 64, "esn" to 2, "gor" to 5)
val networkMapping = mapOf("etc" to 61, "eth" to 1, "kov" to 42, "rin" to 4, "rop" to 3, "rsk" to 30, "ella" to 64, "esn" to 2, "gor" to 5)

suspend fun main() {
checkForTokenDefinitionsInWrongPath()

allNetworksTokenDir.listFiles()?.forEach { singleNetworkTokenDirectory ->
val jsonArray = JsonArray<JsonObject>()
val jsonArray = JsonArray<JsonObject>()
singleNetworkTokenDirectory.listFiles()?.forEach {
try {
checkTokenFile(it, true)
try {
val eip1191ChainId = getEip1191ChainId(networkMapping, singleNetworkTokenDirectory.name)
checkTokenFile(it, true, eip1191ChainId)
val jsonObject = it.reader().use { reader ->
Klaxon().parseJsonObject(reader)
}
Expand All @@ -42,6 +44,16 @@ suspend fun main() {
}
}

private fun getEip1191ChainId(networkMapping: Map<String, Int>, networkName: String): ChainId? {
var eip1191ChainId: ChainId? = null
if (networkMapping[networkName] != null){
when(networkName){
"rsk" -> eip1191ChainId = ChainId((networkMapping[networkName]!!).toBigInteger())
}
}
return eip1191ChainId
}

private fun checkForTokenDefinitionsInWrongPath() {
File(".").walk().forEach { path ->
if (path.isDirectory
Expand All @@ -60,4 +72,4 @@ fun JsonArray<*>.writeJSON(pathName: String, filename: String) {
val fullOutFile = File(fullOutDir, "$filename.json")

fullOutFile.writeText(toJsonString(false))
}
}
10 changes: 8 additions & 2 deletions src/main/kotlin/org/ethereum/lists/tokens/TokenChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import org.ethereum.lists.tokens.model.Token
import org.kethereum.erc55.hasValidERC55Checksum
import org.kethereum.erc55.isValid
import org.kethereum.erc55.withERC55Checksum
import org.kethereum.erc1191.hasValidERC1191Checksum
import org.kethereum.erc1191.withERC1191Checksum
import org.kethereum.model.Address
import org.kethereum.model.ChainId
import org.kethereum.rpc.min3.getMin3RPC
import org.komputing.kethereum.erc20.ERC20RPCConnector
import java.io.File
Expand Down Expand Up @@ -37,7 +40,7 @@ val onChainIgnore by lazy {
File("onChainIgnore.lst").readText().split("\n")
}

suspend fun checkTokenFile(file: File, onChainCheck: Boolean = false) {
suspend fun checkTokenFile(file: File, onChainCheck: Boolean = false, eip1191ChainId: ChainId? = null) {
val handle = file.name.removeSuffix(".json")
if (onChainCheck && (notToProcessFiles.contains(handle) || onChainIgnore.contains(handle))) {
return
Expand All @@ -48,9 +51,12 @@ suspend fun checkTokenFile(file: File, onChainCheck: Boolean = false) {
when {
!address.isValid() -> throw InvalidAddress(address)

!address.hasValidERC55Checksum()
(!address.hasValidERC55Checksum() && eip1191ChainId == null)
-> throw InvalidChecksum(address.toString() + " expected: " + address.withERC55Checksum())

(!address.hasValidERC55Checksum() && eip1191ChainId != null && !address.hasValidERC1191Checksum(eip1191ChainId!!))
-> throw InvalidChecksum(address.toString() + " expected: " + address.withERC1191Checksum(eip1191ChainId!!))

file.name != "${address.hex}.json" -> throw InvalidFileName()
}
if (jsonObject["decimals"] !is Int) {
Expand Down

0 comments on commit 13d2cd7

Please sign in to comment.