From 6ff75f0e7c6610434f726e04f862dfceb5a5c522 Mon Sep 17 00:00:00 2001 From: Vyacheslav Date: Sat, 12 Aug 2023 11:15:56 +0300 Subject: [PATCH] eth_getLogs call selector supports blockHash parameter (#279) --- .../dshackle/upstream/calls/EthereumCallSelector.kt | 10 +++------- .../upstream/calls/EthereumCallSelectorSpec.groovy | 7 ++++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt index 78d85f04..130d406e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt @@ -116,12 +116,8 @@ class EthereumCallSelector( return if (blockTag.startsWith("{") && list[pos] is Map<*, *>) { val obj = list[pos] as Map<*, *> when { - paramName != null -> { - return if (obj.containsKey(paramName)) { - blockSelectorByTag(obj[paramName].toString(), head) - } else { - Mono.empty() - } + paramName != null && obj.containsKey(paramName) -> { + return blockSelectorByTag(obj[paramName].toString(), head) } obj.containsKey("blockNumber") -> { return blockSelectorByTag(obj["blockNumber"].toString(), head) @@ -143,7 +139,7 @@ class EthereumCallSelector( val minHeight: Long? = when (tag) { "latest" -> head.getCurrentHeight() "pending" -> null - "earliest" -> 0L // for earliest it doesn't nothing, we expect to have 0 block + "earliest" -> 0L // for earliest it does nothing, we expect to have 0 block else -> if (tag.startsWith("0x") || tag.toLongOrNull() != null) { return if (tag.length == 66) { // 32-byte hash is represented as 0x + 64 characters blockByHash(tag) diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelectorSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelectorSpec.groovy index cc86ff57..fa9c943a 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelectorSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelectorSpec.groovy @@ -341,7 +341,11 @@ class EthereumCallSelectorSpec extends Specification { def "Get height matcher for getLogs and eth_newFilter method"() { setup: - def cache = Stub(Caches) + def cache = Mock(Caches) { caches -> + caches.getLastHeightByHash() >> Mock(HeightByHashMemCache) { memCache -> + memCache.read(BlockId.from("0xa29ddfc1b37d0b6d0c4a670fa54778656e890d8bbc1b3a6f7d913bc9eb5e03a1")) >> Mono.just(46208179L) + } + } def callSelector = new EthereumCallSelector(cache) def head = Mock(Head) { _ * getCurrentHeight() >> 17654321L @@ -361,6 +365,7 @@ class EthereumCallSelectorSpec extends Specification { "eth_getLogs" | '[{"toBlock":"0xfbfe3b"}]' | 16514619L "eth_getLogs" | '[{"toBlock":"latest"}]' | 17654321L "eth_getLogs" | '[{"toBlock":"earliest"}]' | 0L + "eth_getLogs" | '[{"blockHash":"0xa29ddfc1b37d0b6d0c4a670fa54778656e890d8bbc1b3a6f7d913bc9eb5e03a1"}]' | 46208179L "eth_newFilter" | '[{"toBlock":"0xfbfe2b", "toBlock":"0xfbfe3b"}]' | 16514619L "eth_newFilter" | '[{"toBlock":"0xfbfe3b", "toBlock":"latest"}]' | 17654321L "eth_newFilter" | '[{"toBlock":"0xfbfe3b", "toBlock":"earliest"}]' | 0L