mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
Check chainID from RPC matches json
This commit is contained in:
parent
4273c2d1b8
commit
a7cd0b6871
|
@ -8,6 +8,7 @@ import org.ethereum.lists.chains.model.*
|
||||||
import org.kethereum.erc55.isValid
|
import org.kethereum.erc55.isValid
|
||||||
import org.kethereum.model.Address
|
import org.kethereum.model.Address
|
||||||
import org.kethereum.rpc.HttpEthereumRPC
|
import org.kethereum.rpc.HttpEthereumRPC
|
||||||
|
import java.math.BigInteger
|
||||||
import javax.imageio.ImageIO
|
import javax.imageio.ImageIO
|
||||||
import kotlin.io.OnErrorAction.*
|
import kotlin.io.OnErrorAction.*
|
||||||
|
|
||||||
|
@ -224,10 +225,10 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val jsonObject = Klaxon().parseJsonObject(chainFile.reader())
|
val jsonObject = Klaxon().parseJsonObject(chainFile.reader())
|
||||||
val chainAsLong = getNumber(jsonObject, "chainId")
|
val chainIdAsLong = getNumber(jsonObject, "chainId")
|
||||||
|
|
||||||
if (chainFile.nameWithoutExtension.startsWith("eip155-")) {
|
if (chainFile.nameWithoutExtension.startsWith("eip155-")) {
|
||||||
if (chainAsLong.toString() != chainFile.nameWithoutExtension.replace("eip155-", "")) {
|
if (chainIdAsLong.toString() != chainFile.nameWithoutExtension.replace("eip155-", "")) {
|
||||||
throw (FileNameMustMatchChainId())
|
throw (FileNameMustMatchChainId())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -389,11 +390,24 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
|
||||||
if (it !is String) {
|
if (it !is String) {
|
||||||
throw (RPCMustBeListOfStrings())
|
throw (RPCMustBeListOfStrings())
|
||||||
} else {
|
} else {
|
||||||
println("connecting to $it")
|
var chainId: BigInteger? = null
|
||||||
val ethereumRPC = HttpEthereumRPC(it)
|
try {
|
||||||
println("Client:" + ethereumRPC.clientVersion())
|
println("connecting to $it")
|
||||||
println("BlockNumber:" + ethereumRPC.blockNumber())
|
val ethereumRPC = HttpEthereumRPC(it)
|
||||||
println("GasPrice:" + ethereumRPC.gasPrice())
|
|
||||||
|
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()
|
println()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user