From 21cb0f009c7acfd47431a63f75b7b56751b3ad6c Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Thu, 21 Nov 2024 23:35:57 +0000 Subject: [PATCH] solution: upgrade EtherJar to the latest (v0.12.1) --- gradle.properties | 2 +- src/main/kotlin/io/emeraldpay/dshackle/Global.kt | 5 ++--- .../io/emeraldpay/dshackle/proxy/ReadRpcJson.kt | 2 +- .../dshackle/proxy/WebsocketHandler.kt | 4 ++-- .../ethereum/subscribe/AggregatedPendingTxes.kt | 2 +- .../upstream/ethereum/subscribe/ConnectLogs.kt | 4 ++-- .../dshackle/proxy/WebsocketHandlerSpec.groovy | 2 +- .../dshackle/rpc/TrackERC20AddressSpec.groovy | 16 ++++++++++------ .../upstream/ethereum/DataReadersSpec.groovy | 4 +++- .../upstream/ethereum/ERC20BalanceTest.kt | 6 +++--- 10 files changed, 26 insertions(+), 21 deletions(-) diff --git a/gradle.properties b/gradle.properties index fa8c62ff7..f860f43b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ grpcVersion=1.54.1 nettyVersion=4.1.92.Final nettyTcnativeVersion=2.0.61.Final detektVersion=1.22.0 -etherjarVersion=0.11.1 +etherjarVersion=0.12.1 groovyVersion=3.0.17 protocVersion=3.18.0 slf4jVersion=2.0.7 diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt index 37eb33738..a3fae76ba 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt @@ -28,10 +28,9 @@ import io.emeraldpay.dshackle.upstream.bitcoin.data.EsploraUnspent import io.emeraldpay.dshackle.upstream.bitcoin.data.EsploraUnspentDeserializer import io.emeraldpay.dshackle.upstream.bitcoin.data.RpcUnspent import io.emeraldpay.dshackle.upstream.bitcoin.data.RpcUnspentDeserializer -import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.TransactionIdSerializer import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.etherjar.domain.TransactionId +import io.emeraldpay.etherjar.rpc.EtherjarModule import java.text.SimpleDateFormat import java.util.Locale import java.util.TimeZone @@ -89,7 +88,6 @@ class Global { private fun createObjectMapper(): ObjectMapper { val module = SimpleModule("EmeraldDshackle", Version(1, 0, 0, null, null, null)) module.addSerializer(JsonRpcResponse::class.java, JsonRpcResponse.ResponseJsonSerializer()) - module.addSerializer(TransactionId::class.java, TransactionIdSerializer()) module.addDeserializer(EsploraUnspent::class.java, EsploraUnspentDeserializer()) module.addDeserializer(RpcUnspent::class.java, RpcUnspentDeserializer()) @@ -97,6 +95,7 @@ class Global { val objectMapper = ObjectMapper() objectMapper.registerModule(module) + objectMapper.registerModule(EtherjarModule()) objectMapper.registerModule(Jdk8Module()) objectMapper.registerModule(JavaTimeModule()) objectMapper.registerModule(KotlinModule.Builder().build()) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt index b97eac09d..29260a96d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt @@ -21,9 +21,9 @@ import com.google.protobuf.ByteString import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse +import io.emeraldpay.etherjar.rpc.RequestJson import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.etherjar.rpc.RpcResponseError -import io.emeraldpay.etherjar.rpc.json.RequestJson import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.io.IOException diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt index d84ec56cf..c26f7283a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt @@ -23,8 +23,8 @@ import io.emeraldpay.dshackle.config.ProxyConfig import io.emeraldpay.dshackle.monitoring.accesslog.AccessLogHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.rpc.NativeSubscribe -import io.emeraldpay.etherjar.rpc.json.RequestJson -import io.emeraldpay.etherjar.rpc.json.ResponseJson +import io.emeraldpay.etherjar.rpc.RequestJson +import io.emeraldpay.etherjar.rpc.ResponseJson import io.netty.buffer.ByteBufInputStream import org.reactivestreams.Publisher import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt index af259bc05..532ccec40 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt @@ -32,7 +32,7 @@ class AggregatedPendingTxes( private val track = ExpiringSet( Duration.ofSeconds(30), - HexDataComparator() as Comparator, + HexDataComparator() as Comparator, 10_000 ) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt index e9233194b..24fd36659 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt @@ -33,8 +33,8 @@ open class ConnectLogs( companion object { private val log = LoggerFactory.getLogger(ConnectLogs::class.java) - private val ADDR_COMPARATOR = HexDataComparator() - private val TOPIC_COMPARATOR = HexDataComparator() + private val ADDR_COMPARATOR = HexDataComparator
() + private val TOPIC_COMPARATOR = HexDataComparator() } constructor(upstream: EthereumMultistream) : this(upstream, ConnectBlockUpdates(upstream)) diff --git a/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy index 10e745feb..4bfab7a36 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy @@ -18,7 +18,7 @@ package io.emeraldpay.dshackle.proxy import io.emeraldpay.dshackle.monitoring.accesslog.AccessLogHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.rpc.NativeSubscribe -import io.emeraldpay.etherjar.rpc.json.RequestJson +import io.emeraldpay.etherjar.rpc.RequestJson import io.emeraldpay.api.Chain import io.micrometer.core.instrument.Counter import reactor.core.publisher.Flux diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy index ba562b718..f755cbed6 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy @@ -167,9 +167,10 @@ class TrackERC20AddressSpec extends Specification { def "Check balance when event happens"() { setup: + def tokenAddress = Address.from("0x54EEdeAC495271D0F6B175474e89094C44Da98B9") def events = [ new LogMessage( - Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9"), + tokenAddress, BlockHash.from("0x0c0d2969c843d0b61fbab1b2302cf24d6681b2ae0a140a3c2908990d048f7631"), 13668750, HexData.from("0x0000000000000000000000000000000000000000000000000000000048f2fc7b"), @@ -188,11 +189,14 @@ class TrackERC20AddressSpec extends Specification { 1 * connect() >> Flux.fromIterable(events) } def logs = Mock(ConnectLogs) { - 1 * create( - [Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9")], - [Hex32.from("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")] - ) >> { args -> + 1 * create(_, _) >> { args -> println("ConnectLogs.create $args") + if (args[0].size() != 1 || args[0][0] != tokenAddress) { + throw new IllegalArgumentException("Invalid address: ${args[0][0]}") + } + if (args[1].size() != 1 || !Hex32.from("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef").equals(args[1][0])) { + throw new IllegalArgumentException("Invalid topic: ${args[1].size()} ${args[1][0]}") + } logsConnect } } @@ -214,7 +218,7 @@ class TrackERC20AddressSpec extends Specification { blockchain = Chain.ETHEREUM name = "TEST" type = TokensConfig.Type.ERC20 - address = Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9") + address = tokenAddress } ]) TrackERC20Address track = new TrackERC20Address(mup, tokens) diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DataReadersSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DataReadersSpec.groovy index f7b6496c6..966a2f601 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DataReadersSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DataReadersSpec.groovy @@ -146,7 +146,9 @@ class DataReadersSpec extends Specification { .block(Duration.ofSeconds(1)) .with { new String(it) } then: - act == '{"blockHash":"0x40d15edaff9acdabd2a1c96fd5f683b3300aad34e7015f34def3c56ba8a7ffb5","blockNumber":"0x64","transactionHash":"0x40d15edaff9acdabd2a1c96fd5f683b3300aad34e7015f34def3c56ba8a7ffb5","logs":[]}' + act.contains('"blockHash":"0x40d15edaff9acdabd2a1c96fd5f683b3300aad34e7015f34def3c56ba8a7ffb5"') + act.contains('"transactionHash":"0x40d15edaff9acdabd2a1c96fd5f683b3300aad34e7015f34def3c56ba8a7ffb5"') + act.contains('"blockNumber":"0x64"') } def "Produce empty on non-existing tx"() { diff --git a/src/test/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceTest.kt index cfac15d37..bf14e2bce 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceTest.kt @@ -25,7 +25,7 @@ class ERC20BalanceTest : ShouldSpec({ listOf( TransactionCallJson().also { json -> json.to = Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9") - json.data = HexData.from("0x70a0823100000000000000000000000016c15c65ad00b6dfbcc2cb8a7b6c2d0103a3883b") + json.input = HexData.from("0x70a0823100000000000000000000000016c15c65ad00b6dfbcc2cb8a7b6c2d0103a3883b") }, "latest" ) @@ -51,7 +51,7 @@ class ERC20BalanceTest : ShouldSpec({ listOf( TransactionCallJson().also { json -> json.to = Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9") - json.data = HexData.from("0x70a0823100000000000000000000000016c15c65ad00b6dfbcc2cb8a7b6c2d0103a3883b") + json.input = HexData.from("0x70a0823100000000000000000000000016c15c65ad00b6dfbcc2cb8a7b6c2d0103a3883b") }, "latest" ) @@ -79,7 +79,7 @@ class ERC20BalanceTest : ShouldSpec({ listOf( TransactionCallJson().also { json -> json.to = Address.from("0x54eedeac495271d0f6b175474e89094c44da0000") - json.data = HexData.from("0x70a0823100000000000000000000000016c15c65ad00b6dfbcc2cb8a7b6c2d0103a3883b") + json.input = HexData.from("0x70a0823100000000000000000000000016c15c65ad00b6dfbcc2cb8a7b6c2d0103a3883b") }, "latest" )