diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetServices.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetServices.java index cbcaabc455..8d5658543c 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetServices.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetServices.java @@ -24,15 +24,30 @@ public class NetServices implements JsonRpcMethod { - private final ImmutableMap> services; + private final JsonRpcConfiguration jsonRpcConfiguration; + private final WebSocketConfiguration webSocketConfiguration; + private final P2PNetwork p2pNetwork; + private final MetricsConfiguration metricsConfiguration; public NetServices( final JsonRpcConfiguration jsonRpcConfiguration, final WebSocketConfiguration webSocketConfiguration, final P2PNetwork p2pNetwork, final MetricsConfiguration metricsConfiguration) { + this.jsonRpcConfiguration = jsonRpcConfiguration; + this.webSocketConfiguration = webSocketConfiguration; + this.p2pNetwork = p2pNetwork; + this.metricsConfiguration = metricsConfiguration; + } - ImmutableMap.Builder> servicesMapBuilder = + @Override + public String getName() { + return "net_services"; + } + + @Override + public JsonRpcResponse response(final JsonRpcRequest req) { + final ImmutableMap.Builder> servicesMapBuilder = ImmutableMap.builder(); if (jsonRpcConfiguration.isEnabled()) { @@ -47,15 +62,12 @@ public NetServices( webSocketConfiguration.getHost(), webSocketConfiguration.getPort())); } if (p2pNetwork.isP2pEnabled()) { - if (p2pNetwork.isP2pEnabled()) { - p2pNetwork - .getLocalEnode() - .ifPresent( - enode -> { + p2pNetwork + .getLocalEnode() + .ifPresent( + enode -> servicesMapBuilder.put( - "p2p", createServiceDetailsMap(enode.getIp(), enode.getListeningPort())); - }); - } + "p2p", createServiceDetailsMap(enode.getIp(), enode.getListeningPort()))); } if (metricsConfiguration.isEnabled()) { servicesMapBuilder.put( @@ -63,17 +75,7 @@ public NetServices( createServiceDetailsMap(metricsConfiguration.getHost(), metricsConfiguration.getPort())); } - services = servicesMapBuilder.build(); - } - - @Override - public String getName() { - return "net_services"; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequest req) { - return new JsonRpcSuccessResponse(req.getId(), services); + return new JsonRpcSuccessResponse(req.getId(), servicesMapBuilder.build()); } private ImmutableMap createServiceDetailsMap(final String host, final int port) {