Skip to content

Commit

Permalink
solution: upgrade EtherJar to the latest (v0.12.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
splix committed Nov 27, 2024
1 parent c4098f8 commit 21cb0f0
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/io/emeraldpay/dshackle/Global.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,14 +88,14 @@ 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())
module.addDeserializer(JsonRpcRequest::class.java, JsonRpcRequest.Deserializer())

val objectMapper = ObjectMapper()
objectMapper.registerModule(module)
objectMapper.registerModule(EtherjarModule())
objectMapper.registerModule(Jdk8Module())
objectMapper.registerModule(JavaTimeModule())
objectMapper.registerModule(KotlinModule.Builder().build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AggregatedPendingTxes(

private val track = ExpiringSet<TransactionId>(
Duration.ofSeconds(30),
HexDataComparator() as Comparator<TransactionId>,
HexDataComparator<TransactionId>() as Comparator<TransactionId>,
10_000
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address>()
private val TOPIC_COMPARATOR = HexDataComparator<Hex32>()
}

constructor(upstream: EthereumMultistream) : this(upstream, ConnectBlockUpdates(upstream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
}
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down

0 comments on commit 21cb0f0

Please sign in to comment.