Skip to content

Commit

Permalink
Check chainID from RPC matches json
Browse files Browse the repository at this point in the history
  • Loading branch information
ligi committed Nov 18, 2022
1 parent 4273c2d commit a7cd0b6
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.ethereum.lists.chains.model.*
import org.kethereum.erc55.isValid
import org.kethereum.model.Address
import org.kethereum.rpc.HttpEthereumRPC
import java.math.BigInteger
import javax.imageio.ImageIO
import kotlin.io.OnErrorAction.*

Expand Down Expand Up @@ -224,10 +225,10 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
}

val jsonObject = Klaxon().parseJsonObject(chainFile.reader())
val chainAsLong = getNumber(jsonObject, "chainId")
val chainIdAsLong = getNumber(jsonObject, "chainId")

if (chainFile.nameWithoutExtension.startsWith("eip155-")) {
if (chainAsLong.toString() != chainFile.nameWithoutExtension.replace("eip155-", "")) {
if (chainIdAsLong.toString() != chainFile.nameWithoutExtension.replace("eip155-", "")) {
throw (FileNameMustMatchChainId())
}
} else {
Expand Down Expand Up @@ -389,11 +390,24 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
if (it !is String) {
throw (RPCMustBeListOfStrings())
} else {
println("connecting to $it")
val ethereumRPC = HttpEthereumRPC(it)
println("Client:" + ethereumRPC.clientVersion())
println("BlockNumber:" + ethereumRPC.blockNumber())
println("GasPrice:" + ethereumRPC.gasPrice())
var chainId: BigInteger? = null
try {
println("connecting to $it")
val ethereumRPC = HttpEthereumRPC(it)

println("Client:" + ethereumRPC.clientVersion())
println("BlockNumber:" + ethereumRPC.blockNumber())
println("GasPrice:" + ethereumRPC.gasPrice())

chainId = ethereumRPC.chainId()?.value
} catch (e: Exception) {

}
chainId?.let { chainId ->
if (chainIdAsLong != chainId.toLong()) {
error("RPC chainId (${chainId.toLong()}) does not match chainId from json ($chainIdAsLong)")
}
}
}
}
println()
Expand Down

0 comments on commit a7cd0b6

Please sign in to comment.