From 2e9e51eb41e46ab13e9639a8a311d95b2d7b5601 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 26 Feb 2022 11:11:26 -0300 Subject: [PATCH] Remove GetTradeStatistics service from grpc.proto This protobuf definition and service stub has been in place since the start of work on the API, but was never fully implmented, nor intended to be included in the API beta & v1 releases. Its presence added a useless section to the gRPC API Reference doc. https://ghubstan.github.io/slate Based on branch `7-more-grpcproto-comments`, PR https://github.com/bisq-network/bisq/pull/6068. --- core/src/main/java/bisq/core/api/CoreApi.java | 6 -- .../grpc/GrpcGetTradeStatisticsService.java | 72 ------------------- .../java/bisq/daemon/grpc/GrpcServer.java | 2 - proto/src/main/proto/grpc.proto | 17 ----- 4 files changed, 97 deletions(-) delete mode 100644 daemon/src/main/java/bisq/daemon/grpc/GrpcGetTradeStatisticsService.java diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index 1294d2820e5..67aeb2a900c 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -30,7 +30,6 @@ import bisq.core.trade.model.TradeModel; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.model.bsq_swap.BsqSwapTrade; -import bisq.core.trade.statistics.TradeStatistics3; import bisq.core.trade.statistics.TradeStatisticsManager; import bisq.common.app.Version; @@ -47,7 +46,6 @@ import com.google.common.util.concurrent.FutureCallback; -import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Set; @@ -442,10 +440,6 @@ public void removeWalletPassword(String password) { walletsService.removeWalletPassword(password); } - public List getTradeStatistics() { - return new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet()); - } - public int getNumConfirmationsForMostRecentTransaction(String addressString) { return walletsService.getNumConfirmationsForMostRecentTransaction(addressString); } diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcGetTradeStatisticsService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcGetTradeStatisticsService.java deleted file mode 100644 index 553ff1b30f5..00000000000 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcGetTradeStatisticsService.java +++ /dev/null @@ -1,72 +0,0 @@ -package bisq.daemon.grpc; - -import bisq.core.api.CoreApi; -import bisq.core.trade.statistics.TradeStatistics3; - -import bisq.proto.grpc.GetTradeStatisticsReply; -import bisq.proto.grpc.GetTradeStatisticsRequest; - -import io.grpc.ServerInterceptor; -import io.grpc.stub.StreamObserver; - -import javax.inject.Inject; - -import java.util.HashMap; -import java.util.Optional; -import java.util.stream.Collectors; - -import lombok.extern.slf4j.Slf4j; - -import static bisq.daemon.grpc.interceptor.GrpcServiceRateMeteringConfig.getCustomRateMeteringInterceptor; -import static bisq.proto.grpc.GetTradeStatisticsGrpc.GetTradeStatisticsImplBase; -import static bisq.proto.grpc.GetTradeStatisticsGrpc.getGetTradeStatisticsMethod; -import static java.util.concurrent.TimeUnit.SECONDS; - - - -import bisq.daemon.grpc.interceptor.CallRateMeteringInterceptor; -import bisq.daemon.grpc.interceptor.GrpcCallRateMeter; - -@Slf4j -class GrpcGetTradeStatisticsService extends GetTradeStatisticsImplBase { - - private final CoreApi coreApi; - private final GrpcExceptionHandler exceptionHandler; - - @Inject - public GrpcGetTradeStatisticsService(CoreApi coreApi, GrpcExceptionHandler exceptionHandler) { - this.coreApi = coreApi; - this.exceptionHandler = exceptionHandler; - } - - @Override - public void getTradeStatistics(GetTradeStatisticsRequest req, - StreamObserver responseObserver) { - try { - var tradeStatistics = coreApi.getTradeStatistics().stream() - .map(TradeStatistics3::toProtoTradeStatistics3) - .collect(Collectors.toList()); - - var reply = GetTradeStatisticsReply.newBuilder().addAllTradeStatistics(tradeStatistics).build(); - responseObserver.onNext(reply); - responseObserver.onCompleted(); - } catch (Throwable cause) { - exceptionHandler.handleException(log, cause, responseObserver); - } - } - - final ServerInterceptor[] interceptors() { - Optional rateMeteringInterceptor = rateMeteringInterceptor(); - return rateMeteringInterceptor.map(serverInterceptor -> - new ServerInterceptor[]{serverInterceptor}).orElseGet(() -> new ServerInterceptor[0]); - } - - final Optional rateMeteringInterceptor() { - return getCustomRateMeteringInterceptor(coreApi.getConfig().appDataDir, this.getClass()) - .or(() -> Optional.of(CallRateMeteringInterceptor.valueOf( - new HashMap<>() {{ - put(getGetTradeStatisticsMethod().getFullMethodName(), new GrpcCallRateMeter(1, SECONDS)); - }} - ))); - } -} diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcServer.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcServer.java index f031539e067..9b109560447 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcServer.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcServer.java @@ -56,7 +56,6 @@ public GrpcServer(CoreContext coreContext, GrpcPriceService priceService, GrpcShutdownService shutdownService, GrpcVersionService versionService, - GrpcGetTradeStatisticsService tradeStatisticsService, GrpcTradesService tradesService, GrpcWalletsService walletsService) { this.server = ServerBuilder.forPort(config.apiPort) @@ -67,7 +66,6 @@ public GrpcServer(CoreContext coreContext, .addService(interceptForward(paymentAccountsService, paymentAccountsService.interceptors())) .addService(interceptForward(priceService, priceService.interceptors())) .addService(shutdownService) - .addService(interceptForward(tradeStatisticsService, tradeStatisticsService.interceptors())) .addService(interceptForward(tradesService, tradesService.interceptors())) .addService(interceptForward(versionService, versionService.interceptors())) .addService(interceptForward(walletsService, walletsService.interceptors())) diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 1595202ac34..eaeb95fac6b 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -444,22 +444,6 @@ message MarketPriceReply { double price = 1; // The most recently available market price. } -/* -* GetTradeStatistics service is not implemented. It's stub will be remove from the gRPC daemon. -*/ -service GetTradeStatistics { - // Not implemented. - rpc GetTradeStatistics (GetTradeStatisticsRequest) returns (GetTradeStatisticsReply) { - } -} - -message GetTradeStatisticsRequest { -} - -message GetTradeStatisticsReply { - repeated TradeStatistics3 TradeStatistics = 1; -} - service ShutdownServer { // Shut down a local Bisq daemon. rpc Stop (StopRequest) returns (StopReply) { @@ -469,7 +453,6 @@ service ShutdownServer { message StopRequest { } - message StopReply { }