From a03325a6191018bfdb4ff896c312a61f4c9db48c Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Mon, 19 Aug 2019 22:36:29 -0400 Subject: [PATCH] solution: rename grpc target to method --- src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt | 4 +--- src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt | 2 +- .../emeraldpay/dshackle/upstream/EthereumGrpcTransport.kt | 3 +-- .../kotlin/io/emeraldpay/dshackle/upstream/GrpcUpstream.kt | 2 +- .../io/emeraldpay/dshackle/upstream/UpstreamValidator.kt | 1 - .../groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy | 4 ++-- .../io/emeraldpay/dshackle/test/EthereumApiMock.groovy | 2 +- .../dshackle/upstream/EthereumGrpcTransportSpec.groovy | 6 +++--- 8 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt index 01e55783..40bf007d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt @@ -3,8 +3,6 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common import io.emeraldpay.dshackle.upstream.* -import io.emeraldpay.grpc.Chain -import io.grpc.stub.StreamObserver import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service import reactor.core.publisher.Mono @@ -24,7 +22,7 @@ class Describe( val targets = chainUpstreams.getSupportedTargets() val chainDescription = BlockchainOuterClass.DescribeChain.newBuilder() .setChain(Common.ChainRef.forNumber(chain.id)) - .addAllSupportedTargets(targets) + .addAllSupportedMethods(targets) .setStatus(status) chainUpstreams.getAll().let { ups -> ups.forEach { up -> diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 7f364335..855a930c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -80,7 +80,7 @@ class NativeCall( val matcher = Selector.convertToMatcher(request.selector) val apis = upstream.getApis(matcher) return request.itemsList.toFlux().map { - val method = it.target + val method = it.method val params = it.payload.toStringUtf8() val callQuorum = upstream.targets?.getQuorumFor(method) ?: AlwaysQuorum() callQuorum.init(upstream.getHead()) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/EthereumGrpcTransport.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/EthereumGrpcTransport.kt index 7c53467e..73eb5b76 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/EthereumGrpcTransport.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/EthereumGrpcTransport.kt @@ -89,8 +89,7 @@ class EthereumGrpcTransport( val params = objectMapper.writeValueAsBytes(call.params) val nativeCallItem = BlockchainOuterClass.NativeCallItem.newBuilder() .setId(id) - .setMethod("POST") - .setTarget(call.method) + .setMethod(call.method) .setPayload(ByteString.copyFrom(params)) .build() req.addItems(nativeCallItem) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/GrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/GrpcUpstream.kt index 388b7778..34901960 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/GrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/GrpcUpstream.kt @@ -112,7 +112,7 @@ open class GrpcUpstream( } fun init(conf: BlockchainOuterClass.DescribeChain) { - supportedMethods.addAll(conf.supportedTargetsList) + supportedMethods.addAll(conf.supportedMethodsList) val nodes = NodeDetailsList() conf.nodesList.forEach { node -> val node = NodeDetailsList.NodeDetails(node.quorum, diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamValidator.kt index 193204ef..fc67cd63 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamValidator.kt @@ -26,7 +26,6 @@ class UpstreamValidator( } return UpstreamAvailability.OK } catch (e: Throwable) { - e.printStackTrace() return UpstreamAvailability.UNAVAILABLE } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy index 025190cb..45f2b8e0 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy @@ -155,7 +155,7 @@ class NativeCallSpec extends Specification { .addAllItems([1, 2].collect { id -> return BlockchainOuterClass.NativeCallItem.newBuilder() .setId(id) - .setTarget("eth_test") + .setMethod("eth_test") .build() }) .build() @@ -178,7 +178,7 @@ class NativeCallSpec extends Specification { .addAllItems([1, 2].collect { id -> return BlockchainOuterClass.NativeCallItem.newBuilder() .setId(id) - .setTarget("eth_test") + .setMethod("eth_test") .build() }) .build() diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumApiMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumApiMock.groovy index eac1ef7a..3eb615e6 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumApiMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumApiMock.groovy @@ -54,7 +54,7 @@ class EthereumApiMock extends EthereumApi { def nativeCall(BlockchainOuterClass.NativeCallRequest request, StreamObserver responseObserver) { request.itemsList.forEach { req -> - def resp = execute(req.id, req.target, objectMapper.readerFor(List).readValue(req.payload.toByteArray())) + def resp = execute(req.id, req.method, objectMapper.readerFor(List).readValue(req.payload.toByteArray())) resp.subscribe { def proto = BlockchainOuterClass.NativeCallReplyItem.newBuilder() .setId(req.id) diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/EthereumGrpcTransportSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/EthereumGrpcTransportSpec.groovy index 037f2306..8cdc53ec 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/EthereumGrpcTransportSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/EthereumGrpcTransportSpec.groovy @@ -58,7 +58,7 @@ class EthereumGrpcTransportSpec extends Specification { chain.number == Chain.ETHEREUM.id itemsCount == 1 with(getItems(0)) { - target == "eth_test" + method == "eth_test" payload.toStringUtf8() == "[1]" } } @@ -106,11 +106,11 @@ class EthereumGrpcTransportSpec extends Specification { chain.number == Chain.ETHEREUM.id itemsCount == 2 with(getItems(0)) { - target == "eth_test" + method == "eth_test" payload.toStringUtf8() == "[1]" } with(getItems(1)) { - target == "eth_test2" + method == "eth_test2" payload.toStringUtf8() == "[2,\"3\"]" } }