rest support improvement

This commit is contained in:
a10zn8
2024-04-24 18:02:43 +03:00
parent 99aacf8979
commit 874e53fc6f
7 changed files with 18 additions and 17 deletions

View File

@@ -383,8 +383,8 @@ open class NativeCall(
ParsedCallDetails( ParsedCallDetails(
item.method, item.method,
RestParams( RestParams(
item.restData.headersList.map { it.key to it.value }.toMap(), item.restData.headersList.map { Pair(it.key, it.value) },
item.restData.queryParamsList.map { it.key to it.value }.toMap(), item.restData.queryParamsList.map { Pair(it.key, it.value) },
item.restData.pathParamsList, item.restData.pathParamsList,
item.restData.payload.toByteArray(), item.restData.payload.toByteArray(),
), ),

View File

@@ -67,9 +67,10 @@ class DefaultBeaconChainMethods : CallMethods {
getMethod("/eth/v1/debug/fork_choice"), getMethod("/eth/v1/debug/fork_choice"),
) )
private val eventMethods = setOf( // not supported
getMethod("/eth/v1/events"), // private val eventMethods = setOf(
) // getMethod("/eth/v1/events"),
// )
// need to think up what to do with these methods, probably hardcode them? // need to think up what to do with these methods, probably hardcode them?
private val nodeMethods = setOf( private val nodeMethods = setOf(
@@ -108,7 +109,7 @@ class DefaultBeaconChainMethods : CallMethods {
) )
private val allowedMethods: Set<String> = private val allowedMethods: Set<String> =
beaconMethods + builderMethods + configMethods + debugMethods + eventMethods + nodeMethods + validatorMethods beaconMethods + builderMethods + configMethods + debugMethods + nodeMethods + validatorMethods + rewardMethods
override fun createQuorumFor(method: String): CallQuorum { override fun createQuorumFor(method: String): CallQuorum {
return AlwaysQuorum() return AlwaysQuorum()

View File

@@ -73,7 +73,7 @@ class RestHttpReader(
val response = httpClient.headers { headers -> val response = httpClient.headers { headers ->
restParams.headers.forEach { restParams.headers.forEach {
headers.add(it.key, it.value) headers.add(it.first, it.second)
} }
} }
.request(HttpMethod.valueOf(restMethod)) .request(HttpMethod.valueOf(restMethod))

View File

@@ -30,10 +30,10 @@ object RestRequestParser {
return builder.append(path, i, path.length).toString() return builder.append(path, i, path.length).toString()
} }
fun transformQueryParams(queryParams: Map<String, String>): String { fun transformQueryParams(queryParams: List<Pair<String, String>>): String {
if (queryParams.isEmpty()) { if (queryParams.isEmpty()) {
return "" return ""
} }
return "?".plus(queryParams.entries.joinToString("&") { "${it.key}=${it.value}" }) return "?".plus(queryParams.joinToString("&") { "${it.first}=${it.second}" })
} }
} }

View File

@@ -40,13 +40,13 @@ data class ObjectParams(val obj: Map<Any, Any>) : JsonRpcParams() {
} }
data class RestParams( data class RestParams(
val headers: Map<String, String>, val headers: List<Pair<String, String>>,
val queryParams: Map<String, String>, val queryParams: List<Pair<String, String>>,
val pathParams: List<String>, val pathParams: List<String>,
val payload: ByteArray, val payload: ByteArray,
) : CallParams { ) : CallParams {
companion object { 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 { override fun toJson(id: Int, method: String): ByteArray {

View File

@@ -152,12 +152,12 @@ class JsonRpcGrpcClient(
) )
} }
private fun mapKeyValue(entries: Map<String, String>) = private fun mapKeyValue(entries: List<Pair<String, String>>) =
entries.map { entries.map {
BlockchainOuterClass.KeyValue BlockchainOuterClass.KeyValue
.newBuilder() .newBuilder()
.setKey(it.key) .setKey(it.first)
.setValue(it.value) .setValue(it.second)
.build() .build()
} }
} }

View File

@@ -10,7 +10,7 @@ class RestRequestParserTest {
@Test @Test
fun `transform query params into string`() { fun `transform query params into string`() {
val queryParams = mapOf( val queryParams = listOf(
"first" to "coolParam", "first" to "coolParam",
"second" to "moreCoolParam", "second" to "moreCoolParam",
) )
@@ -22,7 +22,7 @@ class RestRequestParserTest {
@Test @Test
fun `transform query params into empty string`() { fun `transform query params into empty string`() {
val result = RestRequestParser.transformQueryParams(emptyMap()) val result = RestRequestParser.transformQueryParams(emptyList())
assertEquals("", result) assertEquals("", result)
} }