Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Feature/move subclass in pantheon command #1272

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<RpcApi> {

@Override
public RpcApi convert(final String name) throws RpcApisConversionException {
final String uppercaseName = name.trim().toUpperCase();

return Stream.<Function<String, Optional<RpcApi>>>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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<RpcApi> {

@Override
public RpcApi convert(final String name) throws RpcApisConversionException {
return Stream.<Function<String, Optional<RpcApi>>>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));
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}