From fc488e1aabf47b000b9489452c3b3192f569ee9a Mon Sep 17 00:00:00 2001 From: KirillPamPam Date: Tue, 11 Apr 2023 14:37:17 +0400 Subject: [PATCH] Apply method matcher for direct reader (#200) --- .../kotlin/io/emeraldpay/dshackle/upstream/Selector.kt | 4 ++-- .../dshackle/upstream/ethereum/EthereumDirectReader.kt | 7 ++++++- .../upstream/ethereum/EthereumCachingReaderSpec.groovy | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt index a61e94e2..7ce6172f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt @@ -127,7 +127,7 @@ class Selector { fun describeInternal(): String } - class MultiMatcher( + data class MultiMatcher( private val matchers: Collection ) : Matcher { override fun matches(up: Upstream): Boolean { @@ -156,7 +156,7 @@ class Selector { } } - class MethodMatcher( + data class MethodMatcher( val method: String ) : Matcher { override fun matches(up: Upstream): Boolean { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt index 53290dfe..c49886f6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt @@ -172,7 +172,12 @@ class EthereumDirectReader( return Mono.just(quorumReaderFactory) .map { it.create( - up.getApiSource(matcher), + up.getApiSource( + Selector.Builder() + .withMatcher(matcher) + .forMethod(request.method) + .build() + ), callMethodsFactory.create().createQuorumFor(request.method), // we do not use Signer for internal requests because it doesn't make much sense null, diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy index 005e14e9..470957da 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy @@ -113,7 +113,9 @@ class EthereumDirectReaderSpec extends Specification { transactions = [] } def up = Mock(Multistream) { - 1 * getApiSource(new Selector.HeightMatcher(100)) >> Stub(ApiSource) + 1 * getApiSource( + new Selector.Builder().withMatcher(new Selector.HeightMatcher(100)).forMethod("eth_getBlockByNumber").build() + ) >> Stub(ApiSource) } def calls = Mock(Factory) { 1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM)