diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java index 1037944e13..80b07cd8d5 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java @@ -18,7 +18,7 @@ import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonRpcDisabledNode; import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.patheonNodeWithRpcApis; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNodeConfig.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNodeConfig.java index ee7cce71ad..6682fdf70e 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNodeConfig.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNodeConfig.java @@ -15,7 +15,7 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.node; import tech.pegasys.pantheon.ethereum.blockcreation.MiningParameters; import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import java.io.IOException; @@ -69,7 +69,7 @@ public class PantheonNodeConfig { } public static PantheonNodeConfig patheonNodeWithRpcApis( - final String name, final RpcApis... enabledRpcApis) { + final String name, final RpcApi... enabledRpcApis) { final JsonRpcConfiguration jsonRpcConfig = createJsonRpcConfig(); jsonRpcConfig.setRpcApis(Arrays.asList(enabledRpcApis)); final WebSocketConfiguration webSocketConfig = createWebSocketConfig(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index 5bc348554c..8f470b8566 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -12,7 +12,8 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.node; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import java.io.File; import java.io.IOException; @@ -93,7 +94,7 @@ public class ProcessPantheonNodeRunner implements PantheonNodeRunner { waitForPortsFile(dataDir); } - private String apiList(final Collection rpcApis) { + private String apiList(final Collection rpcApis) { return String.join(",", rpcApis.stream().map(RpcApis::getValue).collect(Collectors.toList())); } diff --git a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java index c42872a85c..86d7c0eecc 100644 --- a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java +++ b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java @@ -24,16 +24,23 @@ import tech.pegasys.pantheon.consensus.common.VoteProposer; import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries; +import java.util.Collection; import java.util.HashMap; import java.util.Map; public class CliqueJsonRpcMethodsFactory { - public Map methods(final ProtocolContext context) { + public Map methods( + final ProtocolContext context, final Collection jsonRpcApis) { + final Map rpcMethods = new HashMap<>(); + if (!jsonRpcApis.contains(CliqueRpcApis.CLIQUE)) { + return rpcMethods; + } final MutableBlockchain blockchain = context.getBlockchain(); final WorldStateArchive worldStateArchive = context.getWorldStateArchive(); final BlockchainQueries blockchainQueries = @@ -50,7 +57,6 @@ public class CliqueJsonRpcMethodsFactory { final Propose proposeRpc = new Propose(voteProposer, jsonRpcParameter); final Discard discardRpc = new Discard(voteProposer, jsonRpcParameter); - final Map rpcMethods = new HashMap<>(); rpcMethods.put(cliqueGetSigners.getName(), cliqueGetSigners); rpcMethods.put(cliqueGetSignersAtHash.getName(), cliqueGetSignersAtHash); rpcMethods.put(proposeRpc.getName(), proposeRpc); diff --git a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueRpcApis.java b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueRpcApis.java new file mode 100644 index 0000000000..909c95a657 --- /dev/null +++ b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueRpcApis.java @@ -0,0 +1,33 @@ +/* + * Copyright 2018 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.consensus.clique.jsonrpc; + +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; + +import java.util.Optional; + +public class CliqueRpcApis { + public static final RpcApi CLIQUE = new RpcApi("CLIQUE"); + + public static final Optional valueOf(final String name) { + if (name.equals(CLIQUE.getCliValue())) { + return Optional.of(CLIQUE); + } else { + return Optional.empty(); + } + } + + public static final String getName(final RpcApi rpcapi) { + return rpcapi.getCliValue(); + } +} diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java index d0a8746180..bc155765ed 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java @@ -16,9 +16,11 @@ import tech.pegasys.pantheon.consensus.ibft.IbftContext; import tech.pegasys.pantheon.consensus.ibft.jsonrpc.methods.IbftDiscardValidatorVote; import tech.pegasys.pantheon.consensus.ibft.jsonrpc.methods.IbftProposeValidatorVote; import tech.pegasys.pantheon.ethereum.ProtocolContext; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -26,16 +28,20 @@ public class IbftJsonRpcMethodsFactory { private final JsonRpcParameter jsonRpcParameter = new JsonRpcParameter(); - public Map methods(final ProtocolContext context) { + public Map methods( + final ProtocolContext context, final Collection jsonRpcApis) { final Map rpcMethods = new HashMap<>(); - // @formatter:off - addMethods( - rpcMethods, - new IbftProposeValidatorVote( - context.getConsensusState().getVoteProposer(), jsonRpcParameter), - new IbftDiscardValidatorVote( - context.getConsensusState().getVoteProposer(), jsonRpcParameter)); + + if (jsonRpcApis.contains(IbftRpcApis.IBFT)) { + // @formatter:off + addMethods( + rpcMethods, + new IbftProposeValidatorVote( + context.getConsensusState().getVoteProposer(), jsonRpcParameter), + new IbftDiscardValidatorVote( + context.getConsensusState().getVoteProposer(), jsonRpcParameter)); + } return rpcMethods; } diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftRpcApis.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftRpcApis.java new file mode 100644 index 0000000000..bc25a0deb9 --- /dev/null +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftRpcApis.java @@ -0,0 +1,33 @@ +/* + * Copyright 2018 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.consensus.ibft.jsonrpc; + +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; + +import java.util.Optional; + +public class IbftRpcApis { + public static final RpcApi IBFT = new RpcApi("IBFT"); + + public static final Optional valueOf(final String name) { + if (name.equals(IBFT.getCliValue())) { + return Optional.of(IBFT); + } else { + return Optional.empty(); + } + } + + public static final String getName(final RpcApi rpcapi) { + return rpcapi.getCliValue(); + } +} diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java index 2954c50df0..e75dd35095 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java @@ -95,6 +95,6 @@ public class JsonRpcTestMethodsFactory { transactionPool, miningCoordinator, new HashSet<>(), - JsonRpcConfiguration.DEFAULT_JSON_RPC_APIS); + RpcApis.DEFAULT_JSON_RPC_APIS); } } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfiguration.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfiguration.java index a52f1e7c18..3116965b70 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfiguration.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfiguration.java @@ -12,6 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -20,36 +21,23 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Objects; public class JsonRpcConfiguration { - public static final String DEFAULT_JSON_RPC_HOST = "127.0.0.1"; public static final int DEFAULT_JSON_RPC_PORT = 8545; - public static final Collection DEFAULT_JSON_RPC_APIS = + public static final Collection DEFAULT_JSON_RPC_APIS = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3); private boolean enabled; private int port; private String host; private Collection corsAllowedDomains = Collections.emptyList(); - private Collection rpcApis; - - public enum RpcApis { - DEBUG, - ETH, - MINER, - NET, - WEB3; - - public String getValue() { - return this.name().toLowerCase(); - } - } + private Collection rpcApis; public static JsonRpcConfiguration createDefault() { final JsonRpcConfiguration config = new JsonRpcConfiguration(); config.setEnabled(false); config.setPort(DEFAULT_JSON_RPC_PORT); config.setHost(DEFAULT_JSON_RPC_HOST); - config.rpcApis = DEFAULT_JSON_RPC_APIS; + config.rpcApis = RpcApis.DEFAULT_JSON_RPC_APIS; return config; } @@ -89,14 +77,19 @@ public class JsonRpcConfiguration { } } - public Collection getRpcApis() { + public Collection getRpcApis() { return rpcApis; } - public void setRpcApis(final Collection rpcApis) { + public void setRpcApis(final Collection rpcApis) { this.rpcApis = rpcApis; } + public void addRpcApi(final RpcApi rpcApi) { + this.rpcApis = new ArrayList<>(rpcApis); + rpcApis.add(rpcApi); + } + @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java index bf9aa9676f..a77bfceadb 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java @@ -17,7 +17,6 @@ import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.AdminPeers; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.DebugStorageRangeAt; @@ -96,7 +95,7 @@ public class JsonRpcMethodsFactory { final ProtocolSchedule protocolSchedule, final AbstractMiningCoordinator miningCoordinator, final Set supportedCapabilities, - final Collection rpcApis, + final Collection rpcApis, final FilterManager filterManager) { final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive); @@ -125,7 +124,7 @@ public class JsonRpcMethodsFactory { final TransactionPool transactionPool, final AbstractMiningCoordinator miningCoordinator, final Set supportedCapabilities, - final Collection rpcApis) { + final Collection rpcApis) { final Map enabledMethods = new HashMap<>(); // @formatter:off if (rpcApis.contains(RpcApis.ETH)) { diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java new file mode 100644 index 0000000000..9605b4b2e1 --- /dev/null +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java @@ -0,0 +1,44 @@ +/* + * Copyright 2018 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.ethereum.jsonrpc; + +import com.google.common.base.Objects; + +public class RpcApi { + private final String cliValue; + + public RpcApi(final String cliValue) { + this.cliValue = cliValue; + } + + public String getCliValue() { + return cliValue; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final RpcApi rpcApi = (RpcApi) o; + return Objects.equal(cliValue, rpcApi.cliValue); + } + + @Override + public int hashCode() { + return Objects.hashCode(cliValue); + } +} diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java new file mode 100644 index 0000000000..c2c31be7da --- /dev/null +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java @@ -0,0 +1,47 @@ +/* + * Copyright 2018 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.ethereum.jsonrpc; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Optional; + +public class RpcApis { + public static final RpcApi ETH = new RpcApi("ETH"); + public static final RpcApi DEBUG = new RpcApi("DEBUG"); + public static final RpcApi MINER = new RpcApi("MINER"); + public static final RpcApi NET = new RpcApi("NET"); + public static final RpcApi WEB3 = new RpcApi("WEB3"); + + public static final Collection DEFAULT_JSON_RPC_APIS = Arrays.asList(ETH, NET, WEB3); + + public static final Optional valueOf(final String name) { + if (name.equals(ETH.getCliValue())) { + return Optional.of(ETH); + } else if (name.equals(DEBUG.getCliValue())) { + return Optional.of(DEBUG); + } else if (name.equals(MINER.getCliValue())) { + return Optional.of(MINER); + } else if (name.equals(NET.getCliValue())) { + return Optional.of(NET); + } else if (name.equals(WEB3.getCliValue())) { + return Optional.of(WEB3); + } else { + return Optional.empty(); + } + } + + public static final String getValue(final RpcApi rpcapi) { + return rpcapi.getCliValue(); + } +} diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfiguration.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfiguration.java index 9ac33ba65e..4b157afeff 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfiguration.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfiguration.java @@ -12,8 +12,10 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc.websocket; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -21,16 +23,15 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Objects; public class WebSocketConfiguration { - public static final String DEFAULT_WEBSOCKET_HOST = "127.0.0.1"; public static final int DEFAULT_WEBSOCKET_PORT = 8546; - public static final Collection DEFAULT_WEBSOCKET_APIS = + public static final Collection DEFAULT_WEBSOCKET_APIS = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3); private boolean enabled; private int port; private String host; - private Collection rpcApis; + private Collection rpcApis; public static WebSocketConfiguration createDefault() { final WebSocketConfiguration config = new WebSocketConfiguration(); @@ -67,14 +68,19 @@ public class WebSocketConfiguration { return port; } - public Collection getRpcApis() { + public Collection getRpcApis() { return rpcApis; } - public void setRpcApis(final Collection rpcApis) { + public void setRpcApis(final Collection rpcApis) { this.rpcApis = rpcApis; } + public void addRpcApi(final RpcApi rpcApi) { + this.rpcApis = new ArrayList<>(rpcApis); + rpcApis.add(rpcApi); + } + @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java index b7ff679b7e..cc78960d13 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java @@ -33,7 +33,6 @@ import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterRepository; @@ -94,7 +93,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest { protected final String NET_VERSION = "6986785976597"; - protected static final Collection JSON_RPC_APIS = + protected static final Collection JSON_RPC_APIS = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3); protected MutableBlockchain blockchain; diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfigurationTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfigurationTest.java index f83b430018..2001dc183a 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfigurationTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfigurationTest.java @@ -14,8 +14,6 @@ package tech.pegasys.pantheon.ethereum.jsonrpc; import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; - import com.google.common.collect.Lists; import org.junit.Test; diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index 549c5c76ac..2cab3ce5c9 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -21,7 +21,6 @@ import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries; @@ -142,7 +141,7 @@ public class JsonRpcHttpServiceRpcApisTest { } } - private JsonRpcConfiguration createJsonRpcConfigurationWithRpcApis(final RpcApis... rpcApis) { + private JsonRpcConfiguration createJsonRpcConfigurationWithRpcApis(final RpcApi... rpcApis) { final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault(); config.setCorsAllowedDomains(singletonList("*")); config.setPort(0); @@ -152,7 +151,7 @@ public class JsonRpcHttpServiceRpcApisTest { return config; } - private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final RpcApis... rpcApis) { + private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final RpcApi... rpcApis) { return createJsonRpcHttpServiceWithRpcApis(createJsonRpcConfigurationWithRpcApis(rpcApis)); } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java index ba7ab60698..1b65c0c52b 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java @@ -31,7 +31,6 @@ import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockWithMetadata; @@ -88,7 +87,7 @@ public class JsonRpcHttpServiceTest { protected static P2PNetwork peerDiscoveryMock; protected static BlockchainQueries blockchainQueries; protected static Synchronizer synchronizer; - protected static final Collection JSON_RPC_APIS = + protected static final Collection JSON_RPC_APIS = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3); protected final JsonRpcTestHelper testHelper = new JsonRpcTestHelper(); diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfigurationTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfigurationTest.java index 648fcc50f1..21b0f07382 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfigurationTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfigurationTest.java @@ -14,7 +14,7 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.websocket; import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import org.junit.Test; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/PantheonInfo.java b/pantheon/src/main/java/tech/pegasys/pantheon/PantheonInfo.java index d5f51dd4ca..e70b9dcf55 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/PantheonInfo.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/PantheonInfo.java @@ -2,7 +2,7 @@ package tech.pegasys.pantheon; // This file is generated via a gradle task and should not be edited directly. public class PantheonInfo { - private static final String version = "pantheon/0.0.8-SNAPSHOT"; + private static final String version = "pantheon/0.8.0-SNAPSHOT"; private PantheonInfo() {} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 9afd6779b7..970c2128fe 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -25,9 +25,9 @@ import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcHttpService; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcMethodsFactory; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterRepository; @@ -219,7 +219,7 @@ public class RunnerBuilder { final TransactionPool transactionPool, final AbstractMiningCoordinator miningCoordinator, final Set supportedCapabilities, - final Collection jsonRpcApis, + final Collection jsonRpcApis, final FilterManager filterManager) { final Map methods = new JsonRpcMethodsFactory() @@ -242,7 +242,7 @@ public class RunnerBuilder { @SuppressWarnings("unchecked") final ProtocolContext cliqueProtocolContext = (ProtocolContext) context; - methods.putAll(new CliqueJsonRpcMethodsFactory().methods(cliqueProtocolContext)); + methods.putAll(new CliqueJsonRpcMethodsFactory().methods(cliqueProtocolContext, jsonRpcApis)); } if (context.getConsensusState() instanceof IbftContext) { @@ -250,7 +250,7 @@ public class RunnerBuilder { @SuppressWarnings("unchecked") final ProtocolContext ibftProtocolContext = (ProtocolContext) context; - methods.putAll(new IbftJsonRpcMethodsFactory().methods(ibftProtocolContext)); + methods.putAll(new IbftJsonRpcMethodsFactory().methods(ibftProtocolContext, jsonRpcApis)); } return methods; } 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 d9299e951b..3b0ba31b00 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -17,6 +17,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; +import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; +import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.ethereum.blockcreation.MiningParameters; import tech.pegasys.pantheon.ethereum.core.Address; @@ -25,7 +27,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration.Builder; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; import tech.pegasys.pantheon.util.BlockImporter; @@ -43,6 +46,9 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Stream; import com.google.common.net.HostAndPort; import io.vertx.core.Vertx; @@ -93,19 +99,23 @@ public class PantheonCommand implements Runnable { private static final String CONFIG_FILE_OPTION_NAME = "--config"; - public static class RpcApisEnumConverter implements ITypeConverter { + public static class RpcApisConverter implements ITypeConverter { @Override - public RpcApis convert(final String s) throws RpcApisEnumConvertionException { - try { - return RpcApis.valueOf(s.trim().toUpperCase()); - } catch (final IllegalArgumentException e) { - throw new RpcApisEnumConvertionException("Invalid value: " + s); - } + public RpcApi convert(final String name) throws RpcApisConversionException { + 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)); } } - public static class RpcApisEnumConvertionException extends Exception { - RpcApisEnumConvertionException(final String s) { + public static class RpcApisConversionException extends Exception { + RpcApisConversionException(final String s) { super(s); } } @@ -265,10 +275,11 @@ public class PantheonCommand implements Runnable { paramLabel = "", split = ",", arity = "1..*", - converter = RpcApisEnumConverter.class, + converter = RpcApisConverter.class, description = "Comma separated APIs to enable on JSON-RPC channel. default: ${DEFAULT-VALUE}" ) - private final Collection rpcApis = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3); + private final Collection rpcApis = + Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT); @Option( names = {"--ws-enabled"}, @@ -291,10 +302,11 @@ public class PantheonCommand implements Runnable { paramLabel = "", split = ",", arity = "1..*", - converter = RpcApisEnumConverter.class, + converter = RpcApisConverter.class, description = "Comma separated APIs to enable on WebSocket channel. default: ${DEFAULT-VALUE}" ) - private final Collection wsApis = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3); + private final Collection wsApis = + Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT); @Option( names = {"--dev-mode"}, diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index c75f5b6867..432b0549e9 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -28,6 +28,8 @@ import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.M import tech.pegasys.pantheon.PantheonInfo; import tech.pegasys.pantheon.cli.EthNetworkConfig.Builder; +import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; +import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; import tech.pegasys.pantheon.ethereum.blockcreation.MiningParameters; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Wei; @@ -60,6 +62,20 @@ import org.mockito.ArgumentMatchers; public class PantheonCommandTest extends CommandTestAbstract { @Rule public final TemporaryFolder temp = new TemporaryFolder(); + private static final JsonRpcConfiguration defaultJsonRpcConfiguration; + private static final WebSocketConfiguration defaultWebSocketConfiguration; + + static { + final JsonRpcConfiguration rpcConf = JsonRpcConfiguration.createDefault(); + rpcConf.addRpcApi(CliqueRpcApis.CLIQUE); + rpcConf.addRpcApi(IbftRpcApis.IBFT); + defaultJsonRpcConfiguration = rpcConf; + + final WebSocketConfiguration websocketConf = WebSocketConfiguration.createDefault(); + websocketConf.addRpcApi(CliqueRpcApis.CLIQUE); + websocketConf.addRpcApi(IbftRpcApis.IBFT); + defaultWebSocketConfiguration = websocketConf; + } @Override @Before @@ -109,8 +125,8 @@ public class PantheonCommandTest extends CommandTestAbstract { eq("127.0.0.1"), eq(30303), eq(25), - eq(JsonRpcConfiguration.createDefault()), - eq(WebSocketConfiguration.createDefault()), + eq(defaultJsonRpcConfiguration), + eq(defaultWebSocketConfiguration), any()); final ArgumentCaptor miningArg = @@ -214,12 +230,16 @@ public class PantheonCommandTest extends CommandTestAbstract { jsonRpcConfiguration.setPort(5678); jsonRpcConfiguration.setCorsAllowedDomains(Collections.emptyList()); jsonRpcConfiguration.setRpcApis(JsonRpcConfiguration.DEFAULT_JSON_RPC_APIS); + jsonRpcConfiguration.addRpcApi(CliqueRpcApis.CLIQUE); + jsonRpcConfiguration.addRpcApi(IbftRpcApis.IBFT); final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); webSocketConfiguration.setEnabled(false); webSocketConfiguration.setHost("9.10.11.12"); webSocketConfiguration.setPort(9101); webSocketConfiguration.setRpcApis(WebSocketConfiguration.DEFAULT_WEBSOCKET_APIS); + webSocketConfiguration.addRpcApi(CliqueRpcApis.CLIQUE); + webSocketConfiguration.addRpcApi(IbftRpcApis.IBFT); parseCommand("--config", configFile); @@ -268,6 +288,13 @@ public class PantheonCommandTest extends CommandTestAbstract { final String configFile = Resources.getResource("partial_config.toml").getFile(); parseCommand("--config", configFile); + final JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); + jsonRpcConfiguration.addRpcApi(CliqueRpcApis.CLIQUE); + jsonRpcConfiguration.addRpcApi(IbftRpcApis.IBFT); + + final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); + webSocketConfiguration.addRpcApi(CliqueRpcApis.CLIQUE); + webSocketConfiguration.addRpcApi(IbftRpcApis.IBFT); verify(mockRunnerBuilder) .build( @@ -278,8 +305,8 @@ public class PantheonCommandTest extends CommandTestAbstract { eq("127.0.0.1"), eq(30303), eq(25), - eq(JsonRpcConfiguration.createDefault()), - eq(WebSocketConfiguration.createDefault()), + eq(jsonRpcConfiguration), + eq(webSocketConfiguration), any()); verify(mockControllerBuilder).build(any(), any(), any(), eq(false), any(), eq(false));