From bd25744768b462da2b1c898638ff878242cdaa88 Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Wed, 17 Nov 2021 21:48:00 -0500 Subject: [PATCH] solution: actual version in RPC fix: #73 --- src/main/kotlin/io/emeraldpay/dshackle/Config.kt | 7 +++++++ src/main/kotlin/io/emeraldpay/dshackle/Global.kt | 2 ++ .../dshackle/upstream/calls/DefaultBitcoinMethods.kt | 8 +++++++- .../dshackle/upstream/calls/DefaultEthereumMethods.kt | 5 ++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Config.kt b/src/main/kotlin/io/emeraldpay/dshackle/Config.kt index b27dc9da..86ad40d8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Config.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Config.kt @@ -59,6 +59,13 @@ open class Config( init { configFilePath = getConfigPath() + Global.version = env.getProperty("version.app", Global.version).let { + if (it.contains("SNAPSHOT")) { + listOfNotNull(it, env.getProperty("version.commit")).joinToString("-") + } else { + it + } + } } fun getConfigPath(): File { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt index fac11f1e..1ec1c3df 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt @@ -72,6 +72,8 @@ class Global { @JvmStatic val objectMapper: ObjectMapper = createObjectMapper() + var version: String = "DEV" + val control: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor() private fun createObjectMapper(): ObjectMapper { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt index e7c27276..38a873d7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt @@ -15,6 +15,7 @@ */ package io.emeraldpay.dshackle.upstream.calls +import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.quorum.AlwaysQuorum import io.emeraldpay.dshackle.quorum.BroadcastQuorum import io.emeraldpay.dshackle.quorum.CallQuorum @@ -25,6 +26,11 @@ import java.util.Collections class DefaultBitcoinMethods : CallMethods { + private val networkinfo = Global.objectMapper.writeValueAsBytes(mapOf( + "version" to 210100, + "subversion" to "/EmeraldDshackle:${Global.version}/" + )) + private val freshMethods = listOf( "getblock", "gettransaction", "gettxout", @@ -77,7 +83,7 @@ class DefaultBitcoinMethods : CallMethods { override fun executeHardcoded(method: String): ByteArray { return when (method) { "getconnectioncount" -> "42".toByteArray() - "getnetworkinfo" -> "{\"version\": 700000, \"subversion\": \"/EmeraldDshackle:v0.9/\"}".toByteArray() + "getnetworkinfo" -> networkinfo else -> throw RpcException(-32601, "Method not found") } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt index b00b3c57..c1e0557b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt @@ -16,6 +16,7 @@ */ package io.emeraldpay.dshackle.upstream.calls +import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.quorum.AlwaysQuorum import io.emeraldpay.dshackle.quorum.BroadcastQuorum import io.emeraldpay.dshackle.quorum.CallQuorum @@ -32,6 +33,8 @@ class DefaultEthereumMethods( private val chain: Chain ) : CallMethods { + private val version = "\"EmeraldDshackle/${Global.version}\"" + private val anyResponseMethods = listOf( "eth_gasPrice", "eth_call", @@ -178,7 +181,7 @@ class DefaultEthereumMethods( "true" } "web3_clientVersion" -> { - "\"EmeraldDshackle/v0.9\"" + version } "eth_protocolVersion" -> { "\"0x3f\""