rest support improvement
This commit is contained in:
@@ -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(),
|
||||
),
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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}" })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user