eth_subscribe: fix preparing filter (#635)

This commit is contained in:
oke11o
2025-02-21 11:07:06 +01:00
committed by GitHub
parent 8c1649c48e
commit 60045d6511
2 changed files with 48 additions and 6 deletions

View File

@@ -37,6 +37,7 @@ open class ConnectLogs(
}
constructor(upstream: Multistream, scheduler: Scheduler) : this(upstream, ConnectBlockUpdates(upstream, scheduler))
private val produceLogs = ProduceLogs(upstream)
fun start(matcher: Selector.Matcher): Flux<LogMessage> {
@@ -65,12 +66,15 @@ open class ConnectLogs(
logs.filter {
val goodAddress =
sortedAddresses.isEmpty() || sortedAddresses.binarySearch(it.address, ADDR_COMPARATOR) >= 0
val goodTopic = sortedTopics.isEmpty() || (
it.topics.isNotEmpty() && sortedTopics.binarySearch(
it.topics[0],
TOPIC_COMPARATOR,
) >= 0
)
val goodTopic = when {
sortedTopics.isEmpty() -> true
it.topics.size < sortedTopics.size -> false
else -> sortedTopics.indices.all { index ->
it.topics[index].let { logTopic ->
sortedTopics.binarySearch(logTopic, TOPIC_COMPARATOR) >= 0
}
}
}
goodAddress && goodTopic
}
}