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(
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(),
),

View File

@@ -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<String> =
beaconMethods + builderMethods + configMethods + debugMethods + eventMethods + nodeMethods + validatorMethods
beaconMethods + builderMethods + configMethods + debugMethods + nodeMethods + validatorMethods + rewardMethods
override fun createQuorumFor(method: String): CallQuorum {
return AlwaysQuorum()

View File

@@ -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))

View File

@@ -30,10 +30,10 @@ object RestRequestParser {
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()) {
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(
val headers: Map<String, String>,
val queryParams: Map<String, String>,
val headers: List<Pair<String, String>>,
val queryParams: List<Pair<String, String>>,
val pathParams: List<String>,
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 {

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 {
BlockchainOuterClass.KeyValue
.newBuilder()
.setKey(it.key)
.setValue(it.value)
.setKey(it.first)
.setValue(it.second)
.build()
}
}

View File

@@ -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)
}