From 9e9967e61d39343722efb6f00cdb26338fc24cce Mon Sep 17 00:00:00 2001 From: Abdelhamid Bakhta Date: Fri, 12 Apr 2019 14:40:20 +0200 Subject: [PATCH 1/4] clean PantheonCommand class - organize imports - move `RpcApisConverter` and `RpcApisConversionException` to separate files --- .../pegasys/pantheon/cli/PantheonCommand.java | 93 +++++++------------ .../cli/converter/RpcApisConverter.java | 26 ++++++ .../exception/RpcApisConversionException.java | 10 ++ 3 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 4504ebbb2d..f98f62c4dd 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -12,32 +12,32 @@ */ package tech.pegasys.pantheon.cli; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Arrays.asList; -import static tech.pegasys.pantheon.cli.CommandLineUtils.checkOptionDependencies; -import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath; -import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; -import static tech.pegasys.pantheon.controller.PantheonController.DATABASE_PATH; -import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; -import static tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis.DEFAULT_JSON_RPC_APIS; -import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; -import static tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer.DEFAULT_PORT; -import static tech.pegasys.pantheon.metrics.MetricCategory.DEFAULT_METRIC_CATEGORIES; -import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; -import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; -import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.createDefault; - +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.io.Resources; +import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import io.vertx.core.json.DecodeException; +import io.vertx.core.metrics.MetricsOptions; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.config.Configurator; +import picocli.CommandLine; +import picocli.CommandLine.AbstractParseResultHandler; +import picocli.CommandLine.Command; +import picocli.CommandLine.ExecutionException; +import picocli.CommandLine.Option; +import picocli.CommandLine.ParameterException; import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.PublicKeySubCommand.KeyLoader; +import tech.pegasys.pantheon.cli.converter.RpcApisConverter; import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; import tech.pegasys.pantheon.cli.custom.JsonRPCWhitelistHostsProperty; import tech.pegasys.pantheon.cli.custom.RpcAuthFileValidator; import tech.pegasys.pantheon.cli.rlp.RLPSubCommand; import tech.pegasys.pantheon.config.GenesisConfigFile; -import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; -import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; import tech.pegasys.pantheon.controller.KeyPairUtil; import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.ethereum.core.Address; @@ -86,28 +86,24 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; -import java.util.stream.Stream; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.Resources; -import io.vertx.core.Vertx; -import io.vertx.core.VertxOptions; -import io.vertx.core.json.DecodeException; -import io.vertx.core.metrics.MetricsOptions; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.Configurator; -import picocli.CommandLine; -import picocli.CommandLine.AbstractParseResultHandler; -import picocli.CommandLine.Command; -import picocli.CommandLine.ExecutionException; -import picocli.CommandLine.Option; -import picocli.CommandLine.ParameterException; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Arrays.asList; +import static tech.pegasys.pantheon.cli.CommandLineUtils.checkOptionDependencies; +import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath; +import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; +import static tech.pegasys.pantheon.controller.PantheonController.DATABASE_PATH; +import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; +import static tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis.DEFAULT_JSON_RPC_APIS; +import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; +import static tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer.DEFAULT_PORT; +import static tech.pegasys.pantheon.metrics.MetricCategory.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; +import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; +import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.createDefault; @SuppressWarnings("FieldCanBeLocal") // because Picocli injected fields report false positives @Command( @@ -124,29 +120,6 @@ footer = "Pantheon is licensed under the Apache License 2.0") public class PantheonCommand implements DefaultCommandValues, Runnable { - static class RpcApisConverter implements CommandLine.ITypeConverter { - - @Override - public RpcApi convert(final String name) throws RpcApisConversionException { - final String uppercaseName = name.trim().toUpperCase(); - - return Stream.>>of( - RpcApis::valueOf, CliqueRpcApis::valueOf, IbftRpcApis::valueOf) - .map(f -> f.apply(uppercaseName)) - .filter(Optional::isPresent) - .map(Optional::get) - .findFirst() - .orElseThrow(() -> new RpcApisConversionException("Invalid value: " + name)); - } - } - - static class RpcApisConversionException extends Exception { - - public RpcApisConversionException(final String s) { - super(s); - } - } - private final Logger logger; private CommandLine commandLine; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java new file mode 100644 index 0000000000..0c708711a0 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java @@ -0,0 +1,26 @@ +package tech.pegasys.pantheon.cli.converter; + +import picocli.CommandLine; +import tech.pegasys.pantheon.cli.converter.exception.RpcApisConversionException; +import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; +import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; + +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Stream; + +public class RpcApisConverter implements CommandLine.ITypeConverter { + + @Override + public RpcApi convert(final String name) throws RpcApisConversionException { + return Stream.>>of( + RpcApis::valueOf, CliqueRpcApis::valueOf, IbftRpcApis::valueOf) + .map(f -> f.apply(name.trim().toUpperCase())) + .filter(Optional::isPresent) + .map(Optional::get) + .findFirst() + .orElseThrow(() -> new RpcApisConversionException(name)); + } +} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java new file mode 100644 index 0000000000..488b22b2b4 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java @@ -0,0 +1,10 @@ +package tech.pegasys.pantheon.cli.converter.exception; + +import static java.lang.String.format; + +public final class RpcApisConversionException extends Exception { + + public RpcApisConversionException(final String name) { + super(format("Invalid value: %s", name)); + } +} From 2d0e9bce4de2d5b96e80167fc69da1848db14de2 Mon Sep 17 00:00:00 2001 From: Abdelhamid Bakhta Date: Fri, 12 Apr 2019 14:44:25 +0200 Subject: [PATCH 2/4] spotlessApply --- .../pegasys/pantheon/cli/PantheonCommand.java | 65 ++++++++++--------- .../cli/converter/RpcApisConverter.java | 15 ++++- .../exception/RpcApisConversionException.java | 12 ++++ 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index f98f62c4dd..78c59868d0 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -12,23 +12,22 @@ */ package tech.pegasys.pantheon.cli; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.Resources; -import io.vertx.core.Vertx; -import io.vertx.core.VertxOptions; -import io.vertx.core.json.DecodeException; -import io.vertx.core.metrics.MetricsOptions; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.Configurator; -import picocli.CommandLine; -import picocli.CommandLine.AbstractParseResultHandler; -import picocli.CommandLine.Command; -import picocli.CommandLine.ExecutionException; -import picocli.CommandLine.Option; -import picocli.CommandLine.ParameterException; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Arrays.asList; +import static tech.pegasys.pantheon.cli.CommandLineUtils.checkOptionDependencies; +import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath; +import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; +import static tech.pegasys.pantheon.controller.PantheonController.DATABASE_PATH; +import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; +import static tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis.DEFAULT_JSON_RPC_APIS; +import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; +import static tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer.DEFAULT_PORT; +import static tech.pegasys.pantheon.metrics.MetricCategory.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; +import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; +import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.createDefault; + import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.PublicKeySubCommand.KeyLoader; @@ -89,21 +88,23 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Arrays.asList; -import static tech.pegasys.pantheon.cli.CommandLineUtils.checkOptionDependencies; -import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath; -import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; -import static tech.pegasys.pantheon.controller.PantheonController.DATABASE_PATH; -import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; -import static tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis.DEFAULT_JSON_RPC_APIS; -import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; -import static tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer.DEFAULT_PORT; -import static tech.pegasys.pantheon.metrics.MetricCategory.DEFAULT_METRIC_CATEGORIES; -import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; -import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; -import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.createDefault; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.io.Resources; +import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import io.vertx.core.json.DecodeException; +import io.vertx.core.metrics.MetricsOptions; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.config.Configurator; +import picocli.CommandLine; +import picocli.CommandLine.AbstractParseResultHandler; +import picocli.CommandLine.Command; +import picocli.CommandLine.ExecutionException; +import picocli.CommandLine.Option; +import picocli.CommandLine.ParameterException; @SuppressWarnings("FieldCanBeLocal") // because Picocli injected fields report false positives @Command( diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java index 0c708711a0..44f010c4b7 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java @@ -1,6 +1,17 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * 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 tech.pegasys.pantheon.cli.converter; -import picocli.CommandLine; import tech.pegasys.pantheon.cli.converter.exception.RpcApisConversionException; import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; @@ -11,6 +22,8 @@ import java.util.function.Function; import java.util.stream.Stream; +import picocli.CommandLine; + public class RpcApisConverter implements CommandLine.ITypeConverter { @Override diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java index 488b22b2b4..8a3e2a2cc1 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java @@ -1,3 +1,15 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * 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 tech.pegasys.pantheon.cli.converter.exception; import static java.lang.String.format; From aec47350792273615aeb2daab484799be928b47a Mon Sep 17 00:00:00 2001 From: Abdelhamid Bakhta Date: Fri, 12 Apr 2019 15:10:24 +0200 Subject: [PATCH 3/4] register converters --- .../pegasys/pantheon/cli/CommandLineUtils.java | 18 ++++++++++++++++-- .../pegasys/pantheon/cli/PantheonCommand.java | 18 +++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java index 92e6d0487b..fb128bd66f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java @@ -12,10 +12,13 @@ */ package tech.pegasys.pantheon.cli; +import static java.util.Arrays.stream; + import tech.pegasys.pantheon.util.StringUtils; -import java.util.Arrays; +import java.util.AbstractMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.apache.logging.log4j.Logger; @@ -50,7 +53,7 @@ static void checkOptionDependencies( commandLine.getCommandSpec().options().stream() .filter( option -> - Arrays.stream(option.names()).anyMatch(dependentOptionsNames::contains) + stream(option.names()).anyMatch(dependentOptionsNames::contains) && !option.stringValues().isEmpty()) .map(option -> option.names()[0]) .collect( @@ -65,4 +68,15 @@ static void checkOptionDependencies( } } } + + @SafeVarargs + static void registerConverters( + final CommandLine commandLine, Map.Entry... converters) { + stream(converters) + .forEach(entry -> commandLine.registerConverter(entry.getKey(), entry.getValue())); + } + + static Map.Entry entryOf(K key, V value) { + return new AbstractMap.SimpleImmutableEntry<>(key, value); + } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 78c59868d0..0da3d542a4 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -16,6 +16,8 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static tech.pegasys.pantheon.cli.CommandLineUtils.checkOptionDependencies; +import static tech.pegasys.pantheon.cli.CommandLineUtils.entryOf; +import static tech.pegasys.pantheon.cli.CommandLineUtils.registerConverters; import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath; import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; import static tech.pegasys.pantheon.controller.PantheonController.DATABASE_PATH; @@ -571,13 +573,15 @@ public void parse( commandLine.addSubcommand( RLPSubCommand.COMMAND_NAME, new RLPSubCommand(resultHandler.out(), in)); - commandLine.registerConverter(Address.class, Address::fromHexStringStrict); - commandLine.registerConverter(BytesValue.class, BytesValue::fromHexString); - commandLine.registerConverter(Level.class, Level::valueOf); - commandLine.registerConverter(SyncMode.class, SyncMode::fromString); - commandLine.registerConverter(UInt256.class, (arg) -> UInt256.of(new BigInteger(arg))); - commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))); - commandLine.registerConverter(PositiveNumber.class, PositiveNumber::fromString); + registerConverters( + commandLine, + entryOf(Address.class, Address::fromHexStringStrict), + entryOf(BytesValue.class, BytesValue::fromHexString), + entryOf(Level.class, Level::valueOf), + entryOf(SyncMode.class, SyncMode::fromString), + entryOf(UInt256.class, (arg) -> UInt256.of(new BigInteger(arg))), + entryOf(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))), + entryOf(PositiveNumber.class, PositiveNumber::fromString)); // Add performance options UnstableOptionsSubCommand.createUnstableOptions( From 750b74d2ac4a4b2f8902a25f1524f8918bfe7a9d Mon Sep 17 00:00:00 2001 From: Abdelhamid Bakhta Date: Fri, 12 Apr 2019 15:45:08 +0200 Subject: [PATCH 4/4] Revert "register converters" This reverts commit aec47350792273615aeb2daab484799be928b47a. --- .../pegasys/pantheon/cli/CommandLineUtils.java | 18 ++---------------- .../pegasys/pantheon/cli/PantheonCommand.java | 18 +++++++----------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java index fb128bd66f..92e6d0487b 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/CommandLineUtils.java @@ -12,13 +12,10 @@ */ package tech.pegasys.pantheon.cli; -import static java.util.Arrays.stream; - import tech.pegasys.pantheon.util.StringUtils; -import java.util.AbstractMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import org.apache.logging.log4j.Logger; @@ -53,7 +50,7 @@ static void checkOptionDependencies( commandLine.getCommandSpec().options().stream() .filter( option -> - stream(option.names()).anyMatch(dependentOptionsNames::contains) + Arrays.stream(option.names()).anyMatch(dependentOptionsNames::contains) && !option.stringValues().isEmpty()) .map(option -> option.names()[0]) .collect( @@ -68,15 +65,4 @@ static void checkOptionDependencies( } } } - - @SafeVarargs - static void registerConverters( - final CommandLine commandLine, Map.Entry... converters) { - stream(converters) - .forEach(entry -> commandLine.registerConverter(entry.getKey(), entry.getValue())); - } - - static Map.Entry entryOf(K key, V value) { - return new AbstractMap.SimpleImmutableEntry<>(key, value); - } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 0da3d542a4..78c59868d0 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -16,8 +16,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static tech.pegasys.pantheon.cli.CommandLineUtils.checkOptionDependencies; -import static tech.pegasys.pantheon.cli.CommandLineUtils.entryOf; -import static tech.pegasys.pantheon.cli.CommandLineUtils.registerConverters; import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath; import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; import static tech.pegasys.pantheon.controller.PantheonController.DATABASE_PATH; @@ -573,15 +571,13 @@ public void parse( commandLine.addSubcommand( RLPSubCommand.COMMAND_NAME, new RLPSubCommand(resultHandler.out(), in)); - registerConverters( - commandLine, - entryOf(Address.class, Address::fromHexStringStrict), - entryOf(BytesValue.class, BytesValue::fromHexString), - entryOf(Level.class, Level::valueOf), - entryOf(SyncMode.class, SyncMode::fromString), - entryOf(UInt256.class, (arg) -> UInt256.of(new BigInteger(arg))), - entryOf(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))), - entryOf(PositiveNumber.class, PositiveNumber::fromString)); + commandLine.registerConverter(Address.class, Address::fromHexStringStrict); + commandLine.registerConverter(BytesValue.class, BytesValue::fromHexString); + commandLine.registerConverter(Level.class, Level::valueOf); + commandLine.registerConverter(SyncMode.class, SyncMode::fromString); + commandLine.registerConverter(UInt256.class, (arg) -> UInt256.of(new BigInteger(arg))); + commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))); + commandLine.registerConverter(PositiveNumber.class, PositiveNumber::fromString); // Add performance options UnstableOptionsSubCommand.createUnstableOptions(