solution: code cleanup
This commit is contained in:
@@ -8,7 +8,6 @@ import io.infinitape.etherjar.rpc.json.ResponseJson
|
|||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import reactor.core.publisher.Mono
|
import reactor.core.publisher.Mono
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
open class EthereumApi(
|
open class EthereumApi(
|
||||||
val rpcClient: RpcClient,
|
val rpcClient: RpcClient,
|
||||||
@@ -28,14 +27,14 @@ open class EthereumApi(
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun <JS, RS> executeAndConvert(rpcCall: RpcCall<JS, RS>): Mono<RS> {
|
open fun <JS, RS> executeAndConvert(rpcCall: RpcCall<JS, RS>): Mono<RS> {
|
||||||
return execute(0, rpcCall.method, rpcCall.params as List<Any>)
|
val convertToJS = java.util.function.Function<ByteArray, Mono<JS>> { resp ->
|
||||||
.flatMap {
|
val jsonValue: JS? = jacksonRpcConverter.fromJson(resp.inputStream(), rpcCall.jsonType, Int::class.java)
|
||||||
val jsonValue: JS? = jacksonRpcConverter.fromJson(it.inputStream(), rpcCall.jsonType, Int::class.java);
|
|
||||||
if (jsonValue == null) Mono.empty<JS>()
|
if (jsonValue == null) Mono.empty<JS>()
|
||||||
else Mono.just(jsonValue)
|
else Mono.just(jsonValue)
|
||||||
}.map {
|
|
||||||
rpcCall.converter.apply(it)
|
|
||||||
}
|
}
|
||||||
|
return execute(0, rpcCall.method, rpcCall.params as List<Any>)
|
||||||
|
.flatMap(convertToJS)
|
||||||
|
.map(rpcCall.converter::apply)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun execute(id: Int, method: String, params: List<Any>): Mono<ByteArray> {
|
open fun execute(id: Int, method: String, params: List<Any>): Mono<ByteArray> {
|
||||||
|
|||||||
Reference in New Issue
Block a user