diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt index 3739bd1b..dafeb3e7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt @@ -41,7 +41,7 @@ class AggregatedCallMethods( override fun getQuorumFor(method: String): CallQuorum { return delegates.find { it.isAllowed(method) || it.isHardcoded(method) - }?.getQuorumFor(method) ?: throw IllegalStateException("No quorum for $method") + }?.getQuorumFor(method) ?: throw IllegalStateException("No executor delegate for $method") } /** diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt index 5e2b04b5..59b13f72 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt @@ -76,7 +76,8 @@ class DefaultEthereumMethods( "eth_coinbase", "eth_mining", "eth_hashrate", - "eth_accounts" + "eth_accounts", + "eth_chainId" ) override fun getQuorumFor(method: String): CallQuorum { @@ -125,6 +126,23 @@ class DefaultEthereumMethods( else -> throw RpcException(-32602, "Invalid chain") } } + "eth_chainId" -> { + when { + Chain.ETHEREUM == chain -> { + "0x0" + } + Chain.ETHEREUM_CLASSIC == chain -> { + "0x3d" + } + Chain.TESTNET_MORDEN == chain -> { + "0x3c" + } + Chain.TESTNET_KOVAN == chain -> { + "0x2a" + } + else -> throw RpcException(-32602, "Invalid chain") + } + } "net_peerCount" -> { "\"0x2a\"" } diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethodsSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethodsSpec.groovy new file mode 100644 index 00000000..aa6240f3 --- /dev/null +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethodsSpec.groovy @@ -0,0 +1,26 @@ +package io.emeraldpay.dshackle.upstream.calls + +import io.emeraldpay.grpc.Chain +import spock.lang.Specification + +class DefaultEthereumMethodsSpec extends Specification { + + def "eth_chainId is hardcoded"() { + setup: + def methods = new DefaultEthereumMethods(Chain.ETHEREUM) + when: + def act = methods.isHardcoded("eth_chainId") + then: + act + } + + def "Provides hardcoded correct chainId"() { + expect: + new String(new DefaultEthereumMethods(chain).executeHardcoded("eth_chainId")) == id + where: + chain | id + Chain.ETHEREUM | "0x0" + Chain.ETHEREUM_CLASSIC | "0x3d" + Chain.TESTNET_KOVAN | "0x2a" + } +}