problem: routed api is not executed first
This commit is contained in:
@@ -19,14 +19,17 @@ package io.emeraldpay.dshackle.rpc
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.google.protobuf.ByteString
|
||||
import io.emeraldpay.api.proto.BlockchainOuterClass
|
||||
import io.emeraldpay.dshackle.BlockchainType
|
||||
import io.emeraldpay.dshackle.SilentException
|
||||
import io.emeraldpay.dshackle.upstream.*
|
||||
import io.emeraldpay.dshackle.quorum.AlwaysQuorum
|
||||
import io.emeraldpay.dshackle.quorum.CallQuorum
|
||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
||||
import io.emeraldpay.grpc.Chain
|
||||
import io.infinitape.etherjar.rpc.RpcException
|
||||
import io.infinitape.etherjar.rpc.RpcResponseError
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
@@ -116,17 +119,25 @@ open class NativeCall(
|
||||
}
|
||||
|
||||
fun fetch(ctx: CallContext<ParsedCallDetails>): Mono<CallContext<ByteArray>> {
|
||||
// ctx.upstream.getRoutedApi(ctx.matcher)
|
||||
// .flatMap { api ->
|
||||
// api.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params))
|
||||
// }.switchIfEmpty(
|
||||
// Mono.just(ctx).flatMap(this::executeOnRemote)
|
||||
// )
|
||||
//TODO use routed api
|
||||
return executeOnRemote(ctx)
|
||||
return ctx.upstream.getRoutedApi(ctx.matcher)
|
||||
.flatMap { api ->
|
||||
api.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params))
|
||||
.flatMap(JsonRpcResponse::requireResult)
|
||||
.map {
|
||||
ctx.withPayload(it)
|
||||
}
|
||||
}.switchIfEmpty(
|
||||
Mono.just(ctx).flatMap(this::executeOnRemote)
|
||||
)
|
||||
.onErrorMap {
|
||||
CallFailure(ctx.id, it)
|
||||
}
|
||||
}
|
||||
|
||||
fun executeOnRemote(ctx: CallContext<ParsedCallDetails>): Mono<CallContext<ByteArray>> {
|
||||
if (!ctx.upstream.getMethods().isAllowed(ctx.payload.method)) {
|
||||
return Mono.error(RpcException(RpcResponseError.CODE_METHOD_NOT_EXIST, "Unsupported method"))
|
||||
}
|
||||
//TODO move to routed api
|
||||
val apis = ctx.getApis()
|
||||
apis.request(1)
|
||||
|
||||
@@ -101,7 +101,7 @@ abstract class Multistream(
|
||||
val apis = getApiSource(matcher)
|
||||
apis.request(1)
|
||||
return Mono.from(apis)
|
||||
.switchIfEmpty(Mono.error(Exception("No API available")))
|
||||
.switchIfEmpty(Mono.error(Exception("No API available for $chain")))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.upstream.bitcoin
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import io.emeraldpay.dshackle.cache.Caches
|
||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||
import io.emeraldpay.dshackle.reader.EmptyReader
|
||||
import io.emeraldpay.dshackle.reader.Reader
|
||||
import io.emeraldpay.dshackle.upstream.*
|
||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||
@@ -74,7 +75,7 @@ open class BitcoinMultistream(
|
||||
|
||||
override fun getRoutedApi(matcher: Selector.Matcher): Mono<Reader<JsonRpcRequest, JsonRpcResponse>> {
|
||||
//TODO
|
||||
return getDirectApi(matcher)
|
||||
return Mono.just(EmptyReader())
|
||||
}
|
||||
|
||||
open fun getReader(): BitcoinReader {
|
||||
|
||||
@@ -119,9 +119,7 @@ open class EthereumMultistream(
|
||||
}
|
||||
|
||||
override fun getRoutedApi(matcher: Selector.Matcher): Mono<Reader<JsonRpcRequest, JsonRpcResponse>> {
|
||||
return getDirectApi(matcher).map { api ->
|
||||
NativeCallRouter(objectMapper, reader, api, getMethods())
|
||||
}
|
||||
return Mono.just(NativeCallRouter(objectMapper, reader, getMethods()))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,6 @@ import java.math.BigInteger
|
||||
class NativeCallRouter(
|
||||
private val objectMapper: ObjectMapper,
|
||||
private val reader: EthereumReader,
|
||||
private val directApi: Reader<JsonRpcRequest, JsonRpcResponse>,
|
||||
private val methods: CallMethods
|
||||
) : Reader<JsonRpcRequest, JsonRpcResponse> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user