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 e733ac3dc8..26993e6d39 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -31,13 +31,12 @@ 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,10 +85,8 @@ 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; @@ -124,29 +121,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..44f010c4b7 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/RpcApisConverter.java @@ -0,0 +1,39 @@ +/* + * 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 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; + +import picocli.CommandLine; + +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..8a3e2a2cc1 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/exception/RpcApisConversionException.java @@ -0,0 +1,22 @@ +/* + * 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; + +public final class RpcApisConversionException extends Exception { + + public RpcApisConversionException(final String name) { + super(format("Invalid value: %s", name)); + } +}