From 874e53fc6f6c844a781f32e7c05ac49fe6ba1f4f Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Wed, 24 Apr 2024 18:02:43 +0300 Subject: [PATCH] rest support improvement --- src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt | 4 ++-- .../dshackle/upstream/calls/DefaultBeaconChainMethods.kt | 9 +++++---- .../dshackle/upstream/restclient/RestHttpReader.kt | 2 +- .../dshackle/upstream/restclient/RestRequestParser.kt | 4 ++-- .../emeraldpay/dshackle/upstream/rpcclient/CallParams.kt | 6 +++--- .../dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt | 6 +++--- .../upstream/restclient/RestRequestParserTest.kt | 4 ++-- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 27ce1351..4b2e445c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -383,8 +383,8 @@ open class NativeCall( ParsedCallDetails( item.method, RestParams( - item.restData.headersList.map { it.key to it.value }.toMap(), - item.restData.queryParamsList.map { it.key to it.value }.toMap(), + item.restData.headersList.map { Pair(it.key, it.value) }, + item.restData.queryParamsList.map { Pair(it.key, it.value) }, item.restData.pathParamsList, item.restData.payload.toByteArray(), ), diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBeaconChainMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBeaconChainMethods.kt index 0ba8372c..2c40c18d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBeaconChainMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBeaconChainMethods.kt @@ -67,9 +67,10 @@ class DefaultBeaconChainMethods : CallMethods { getMethod("/eth/v1/debug/fork_choice"), ) - private val eventMethods = setOf( - getMethod("/eth/v1/events"), - ) +// not supported +// private val eventMethods = setOf( +// getMethod("/eth/v1/events"), +// ) // need to think up what to do with these methods, probably hardcode them? private val nodeMethods = setOf( @@ -108,7 +109,7 @@ class DefaultBeaconChainMethods : CallMethods { ) private val allowedMethods: Set = - beaconMethods + builderMethods + configMethods + debugMethods + eventMethods + nodeMethods + validatorMethods + beaconMethods + builderMethods + configMethods + debugMethods + nodeMethods + validatorMethods + rewardMethods override fun createQuorumFor(method: String): CallQuorum { return AlwaysQuorum() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestHttpReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestHttpReader.kt index 9ff947ec..406bb7c9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestHttpReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestHttpReader.kt @@ -73,7 +73,7 @@ class RestHttpReader( val response = httpClient.headers { headers -> restParams.headers.forEach { - headers.add(it.key, it.value) + headers.add(it.first, it.second) } } .request(HttpMethod.valueOf(restMethod)) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParser.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParser.kt index a301e07b..6a7a9506 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParser.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParser.kt @@ -30,10 +30,10 @@ object RestRequestParser { return builder.append(path, i, path.length).toString() } - fun transformQueryParams(queryParams: Map): String { + fun transformQueryParams(queryParams: List>): String { if (queryParams.isEmpty()) { return "" } - return "?".plus(queryParams.entries.joinToString("&") { "${it.key}=${it.value}" }) + return "?".plus(queryParams.joinToString("&") { "${it.first}=${it.second}" }) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/CallParams.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/CallParams.kt index e94e5d41..bd031edd 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/CallParams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/CallParams.kt @@ -40,13 +40,13 @@ data class ObjectParams(val obj: Map) : JsonRpcParams() { } data class RestParams( - val headers: Map, - val queryParams: Map, + val headers: List>, + val queryParams: List>, val pathParams: List, val payload: ByteArray, ) : CallParams { companion object { - fun emptyParams() = RestParams(emptyMap(), emptyMap(), emptyList(), ByteArray(0)) + fun emptyParams() = RestParams(emptyList(), emptyList(), emptyList(), ByteArray(0)) } override fun toJson(id: Int, method: String): ByteArray { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt index c5126b73..22f1c6d4 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt @@ -152,12 +152,12 @@ class JsonRpcGrpcClient( ) } - private fun mapKeyValue(entries: Map) = + private fun mapKeyValue(entries: List>) = entries.map { BlockchainOuterClass.KeyValue .newBuilder() - .setKey(it.key) - .setValue(it.value) + .setKey(it.first) + .setValue(it.second) .build() } } diff --git a/src/test/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParserTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParserTest.kt index a9854b81..938f01bc 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParserTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/upstream/restclient/RestRequestParserTest.kt @@ -10,7 +10,7 @@ class RestRequestParserTest { @Test fun `transform query params into string`() { - val queryParams = mapOf( + val queryParams = listOf( "first" to "coolParam", "second" to "moreCoolParam", ) @@ -22,7 +22,7 @@ class RestRequestParserTest { @Test fun `transform query params into empty string`() { - val result = RestRequestParser.transformQueryParams(emptyMap()) + val result = RestRequestParser.transformQueryParams(emptyList()) assertEquals("", result) }