remove unused code
This commit is contained in:
@@ -52,7 +52,6 @@ abstract class Multistream(
|
||||
val chain: Chain,
|
||||
private val upstreams: MutableList<Upstream>,
|
||||
val caches: Caches,
|
||||
val postprocessor: RequestPostprocessor
|
||||
) : Upstream, Lifecycle {
|
||||
|
||||
companion object {
|
||||
@@ -144,23 +143,6 @@ abstract class Multistream(
|
||||
return FilteredApis(chain, upstreams, matcher, i)
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an API that executed directly on a remote.
|
||||
*/
|
||||
open fun getDirectApi(matcher: Selector.Matcher): Mono<Reader<JsonRpcRequest, JsonRpcResponse>> {
|
||||
val apis = getApiSource(matcher)
|
||||
apis.request(1)
|
||||
return Mono.from(apis)
|
||||
.map(Upstream::getApi)
|
||||
.map {
|
||||
RequestPostprocessor.wrap(
|
||||
it,
|
||||
postprocessor
|
||||
)
|
||||
} // TODO do it on upstream init, not each time it's called
|
||||
.switchIfEmpty(Mono.error(Exception("No API available for $chain")))
|
||||
}
|
||||
|
||||
abstract fun getFeeEstimation(): ChainFees
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package io.emeraldpay.dshackle.upstream
|
||||
|
||||
import io.emeraldpay.dshackle.reader.Reader
|
||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
interface RequestPostprocessor {
|
||||
|
||||
fun onReceive(method: String, params: List<Any?>, json: ByteArray)
|
||||
|
||||
class Empty : RequestPostprocessor {
|
||||
override fun onReceive(method: String, params: List<Any?>, json: ByteArray) {}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun wrap(
|
||||
reader: Reader<JsonRpcRequest, JsonRpcResponse>,
|
||||
processor: RequestPostprocessor
|
||||
): Reader<JsonRpcRequest, JsonRpcResponse> {
|
||||
return Wrapper(reader, processor)
|
||||
}
|
||||
}
|
||||
|
||||
class Wrapper(
|
||||
private val reader: Reader<JsonRpcRequest, JsonRpcResponse>,
|
||||
private val processor: RequestPostprocessor
|
||||
) : Reader<JsonRpcRequest, JsonRpcResponse> {
|
||||
|
||||
override fun read(key: JsonRpcRequest): Mono<JsonRpcResponse> {
|
||||
return reader.read(key)
|
||||
.doOnNext {
|
||||
if (it.hasResult()) {
|
||||
val result = it.getResult()
|
||||
processor.onReceive(key.method, key.params, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,8 @@ import reactor.core.publisher.Mono
|
||||
open class BitcoinMultistream(
|
||||
chain: Chain,
|
||||
private val sourceUpstreams: MutableList<BitcoinUpstream>,
|
||||
caches: Caches
|
||||
) : Multistream(chain, sourceUpstreams as MutableList<Upstream>, caches, RequestPostprocessor.Empty()), Lifecycle {
|
||||
caches: Caches,
|
||||
) : Multistream(chain, sourceUpstreams as MutableList<Upstream>, caches), Lifecycle {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(BitcoinMultistream::class.java)
|
||||
@@ -95,6 +95,16 @@ open class BitcoinMultistream(
|
||||
onHeadUpdated(head)
|
||||
return head
|
||||
}
|
||||
/**
|
||||
* Finds an API that executed directly on a remote.
|
||||
*/
|
||||
open fun getDirectApi(matcher: Selector.Matcher): Mono<Reader<JsonRpcRequest, JsonRpcResponse>> {
|
||||
val apis = getApiSource(matcher)
|
||||
apis.request(1)
|
||||
return Mono.from(apis)
|
||||
.map(Upstream::getApi)
|
||||
.switchIfEmpty(Mono.error(Exception("No API available for $chain")))
|
||||
}
|
||||
|
||||
override fun getRoutedApi(matcher: Selector.Matcher): Mono<Reader<JsonRpcRequest, JsonRpcResponse>> {
|
||||
return Mono.just(callRouter)
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2020 EmeraldPay, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.emeraldpay.dshackle.upstream.ethereum
|
||||
|
||||
import io.emeraldpay.dshackle.Global
|
||||
import io.emeraldpay.dshackle.cache.Caches
|
||||
import io.emeraldpay.dshackle.data.BlockId
|
||||
import io.emeraldpay.dshackle.data.DefaultContainer
|
||||
import io.emeraldpay.dshackle.data.TxId
|
||||
import io.emeraldpay.dshackle.upstream.RequestPostprocessor
|
||||
import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
class CacheRequested(
|
||||
private val caches: Caches
|
||||
) : RequestPostprocessor {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(CacheRequested::class.java)
|
||||
}
|
||||
|
||||
override fun onReceive(method: String, params: List<Any?>, json: ByteArray) {
|
||||
try {
|
||||
if (method == "eth_getTransactionReceipt") {
|
||||
cacheTxReceipt(params, json)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
log.warn("Failed to cache result", e)
|
||||
}
|
||||
}
|
||||
|
||||
fun cacheTxReceipt(params: List<Any?>, json: ByteArray) {
|
||||
if (params.size != 1) {
|
||||
return
|
||||
}
|
||||
// note: json could be a `null` value
|
||||
val parsed = Global.objectMapper.readValue(json, TransactionReceiptJson::class.java) ?: return
|
||||
val value = DefaultContainer<TransactionReceiptJson>(
|
||||
TxId.from(parsed.transactionHash),
|
||||
BlockId.from(parsed.blockHash),
|
||||
parsed.blockNumber,
|
||||
json,
|
||||
parsed
|
||||
)
|
||||
caches.cacheReceipt(Caches.Tag.REQUESTED, value)
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ open class EthereumMultistream(
|
||||
chain: Chain,
|
||||
val upstreams: MutableList<EthereumUpstream>,
|
||||
caches: Caches
|
||||
) : Multistream(chain, upstreams as MutableList<Upstream>, caches, CacheRequested(caches)), EthereumLikeMultistream {
|
||||
) : Multistream(chain, upstreams as MutableList<Upstream>, caches), EthereumLikeMultistream {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(EthereumMultistream::class.java)
|
||||
|
||||
@@ -37,7 +37,7 @@ open class EthereumPosMultiStream(
|
||||
chain: Chain,
|
||||
val upstreams: MutableList<EthereumPosUpstream>,
|
||||
caches: Caches
|
||||
) : Multistream(chain, upstreams as MutableList<Upstream>, caches, CacheRequested(caches)), EthereumLikeMultistream {
|
||||
) : Multistream(chain, upstreams as MutableList<Upstream>, caches), EthereumLikeMultistream {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(EthereumPosMultiStream::class.java)
|
||||
|
||||
Reference in New Issue
Block a user