From 8c1649c48e20d9c00cfb3fc31f2228b574d97075 Mon Sep 17 00:00:00 2001 From: oke11o Date: Wed, 19 Feb 2025 16:00:01 +0100 Subject: [PATCH] eth_subscribe: fix preparing filter (#634) --- .../ethereum/EthereumEgressSubscription.kt | 9 +++++--- .../EthereumEgressSubscriptionSpec.groovy | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt index 149fbd1c..76d3a695 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt @@ -106,11 +106,14 @@ open class EthereumEgressSubscription( log.debug("Ignore invalid topic: $topics with error ${t.message}") emptyList() } - is Collection<*> -> topics.mapNotNull { + is Collection<*> -> topics.mapNotNull { topic -> try { - Hex32.from(it.toString()) + when (topic) { + is Collection<*> -> topic.firstOrNull()?.toString()?.let { Hex32.from(it) } + else -> topic?.toString()?.let { Hex32.from(it) } + } } catch (t: Throwable) { - log.debug("Ignore invalid topic: $topics with error ${t.message}") + log.debug("Ignore invalid topic: $topic with error ${t.message}") null } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy index 052e7a57..17e6565a 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy @@ -176,6 +176,29 @@ class EthereumEgressSubscriptionSpec extends Specification { ] } + def "read full logs request with array of topics or null"() { + setup: + def ethereumSubscribe = new EthereumEgressSubscription(TestingCommons.emptyMultistream() as GenericMultistream, Schedulers.boundedElastic(), Stub(PendingTxesSource)) + when: + def act = ethereumSubscribe.readLogsRequest([ + address: "0x298d492e8c1d909d3f63bc4a36c66c64acb3d695", + topics : [ + ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"], + null, + ["0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"] + ] + ]) + + then: + act.address == [ + Address.from("0x298d492e8c1d909d3f63bc4a36c66c64acb3d695") + ] + act.topics == [ + Hex32.from("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), + Hex32.from("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925") + ] + } + def "get available subscriptions"() { when: def up1 = TestingCommons.upstream("test")