Search in sources :

Example 1 with JsonRpcMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory in project besu by hyperledger.

the class RunnerBuilder method jsonRpcMethods.

private Map<String, JsonRpcMethod> jsonRpcMethods(final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final BesuController besuController, final P2PNetwork network, final BlockchainQueries blockchainQueries, final Synchronizer synchronizer, final TransactionPool transactionPool, final MiningCoordinator miningCoordinator, final ObservableMetricsSystem metricsSystem, final Set<Capability> supportedCapabilities, final Collection<String> jsonRpcApis, final FilterManager filterManager, final Optional<AccountLocalConfigPermissioningController> accountAllowlistController, final Optional<NodeLocalConfigPermissioningController> nodeAllowlistController, final PrivacyParameters privacyParameters, final JsonRpcConfiguration jsonRpcConfiguration, final WebSocketConfiguration webSocketConfiguration, final MetricsConfiguration metricsConfiguration, final NatService natService, final Map<String, BesuPlugin> namedPlugins, final Path dataDir, final RpcEndpointServiceImpl rpcEndpointServiceImpl) {
    final Map<String, JsonRpcMethod> methods = new JsonRpcMethodsFactory().methods(BesuInfo.nodeName(identityString), ethNetworkConfig.getNetworkId(), besuController.getGenesisConfigOptions(), network, blockchainQueries, synchronizer, protocolSchedule, protocolContext, filterManager, transactionPool, miningCoordinator, metricsSystem, supportedCapabilities, accountAllowlistController, nodeAllowlistController, jsonRpcApis, privacyParameters, jsonRpcConfiguration, webSocketConfiguration, metricsConfiguration, natService, namedPlugins, dataDir, besuController.getProtocolManager().ethContext().getEthPeers());
    methods.putAll(besuController.getAdditionalJsonRpcMethods(jsonRpcApis));
    var pluginMethods = rpcEndpointServiceImpl.getPluginMethods(jsonRpcConfiguration.getRpcApis());
    var overriddenMethods = methods.keySet().stream().filter(pluginMethods::containsKey).collect(Collectors.toList());
    if (overriddenMethods.size() > 0) {
        throw new RuntimeException("You can not override built in methods " + overriddenMethods);
    }
    methods.putAll(pluginMethods);
    return methods;
}
Also used : JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory)

Example 2 with JsonRpcMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory in project besu by hyperledger.

the class JsonRpcHttpServiceLoginTest method initServerAndClient.

@BeforeClass
public static void initServerAndClient() throws Exception {
    peerDiscoveryMock = mock(P2PNetwork.class);
    blockchainQueries = mock(BlockchainQueries.class);
    synchronizer = mock(Synchronizer.class);
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID);
    rpcMethods = spy(new JsonRpcMethodsFactory().methods(CLIENT_VERSION, CHAIN_ID, genesisConfigOptions, peerDiscoveryMock, blockchainQueries, synchronizer, MainnetProtocolSchedule.fromConfig(genesisConfigOptions), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.empty(), Optional.empty(), JSON_RPC_APIS, mock(PrivacyParameters.class), mock(JsonRpcConfiguration.class), mock(WebSocketConfiguration.class), mock(MetricsConfiguration.class), natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class)));
    service = createJsonRpcHttpService();
    jwtAuth = service.authenticationService.get().getJwtAuthProvider();
    service.start().join();
    // Build an OkHttp client.
    client = new OkHttpClient();
    baseUrl = service.url();
}
Also used : Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) OkHttpClient(okhttp3.OkHttpClient) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) FilterManager(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) HashSet(java.util.HashSet) BeforeClass(org.junit.BeforeClass)

Example 3 with JsonRpcMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory in project besu by hyperledger.

the class JsonRpcHttpServiceRpcApisTest method createJsonRpcHttpServiceWithRpcApis.

private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final JsonRpcConfiguration config) throws Exception {
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    final Map<String, JsonRpcMethod> rpcMethods = spy(new JsonRpcMethodsFactory().methods(CLIENT_VERSION, NETWORK_ID, new StubGenesisConfigOptions(), mock(P2PNetwork.class), blockchainQueries, mock(Synchronizer.class), ProtocolScheduleFixture.MAINNET, mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), Optional.of(mock(NodeLocalConfigPermissioningController.class)), config.getRpcApis(), mock(PrivacyParameters.class), mock(JsonRpcConfiguration.class), mock(WebSocketConfiguration.class), mock(MetricsConfiguration.class), natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class)));
    final JsonRpcHttpService jsonRpcHttpService = new JsonRpcHttpService(vertx, folder.newFolder().toPath(), config, new NoOpMetricsSystem(), natService, rpcMethods, HealthService.ALWAYS_HEALTHY, HealthService.ALWAYS_HEALTHY);
    jsonRpcHttpService.start().join();
    baseUrl = jsonRpcHttpService.url();
    return jsonRpcHttpService;
}
Also used : NodeLocalConfigPermissioningController(org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) HashMap(java.util.HashMap) AccountLocalConfigPermissioningController(org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) HashSet(java.util.HashSet)

Example 4 with JsonRpcMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory in project besu by hyperledger.

the class JsonRpcHttpServiceRpcApisTest method createJsonRpcHttpService.

private JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfiguration jsonRpcConfiguration, final WebSocketConfiguration webSocketConfiguration, final P2PNetwork p2pNetwork, final MetricsConfiguration metricsConfiguration, final NatService natService) throws Exception {
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    jsonRpcConfiguration.setPort(0);
    webSocketConfiguration.setPort(0);
    final Map<String, JsonRpcMethod> rpcMethods = spy(new JsonRpcMethodsFactory().methods(CLIENT_VERSION, NETWORK_ID, new StubGenesisConfigOptions(), p2pNetwork, blockchainQueries, mock(Synchronizer.class), ProtocolScheduleFixture.MAINNET, mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), Optional.of(mock(NodeLocalConfigPermissioningController.class)), jsonRpcConfiguration.getRpcApis(), mock(PrivacyParameters.class), jsonRpcConfiguration, webSocketConfiguration, metricsConfiguration, natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class)));
    final JsonRpcHttpService jsonRpcHttpService = new JsonRpcHttpService(vertx, folder.newFolder().toPath(), jsonRpcConfiguration, new NoOpMetricsSystem(), natService, rpcMethods, HealthService.ALWAYS_HEALTHY, HealthService.ALWAYS_HEALTHY);
    jsonRpcHttpService.start().join();
    baseUrl = jsonRpcHttpService.url();
    return jsonRpcHttpService;
}
Also used : NodeLocalConfigPermissioningController(org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) HashMap(java.util.HashMap) AccountLocalConfigPermissioningController(org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) HashSet(java.util.HashSet)

Example 5 with JsonRpcMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory in project besu by hyperledger.

the class AbstractJsonRpcHttpServiceTest method getRpcMethods.

protected Map<String, JsonRpcMethod> getRpcMethods(final JsonRpcConfiguration config, final BlockchainSetupUtil blockchainSetupUtil) {
    final ProtocolContext protocolContext = mock(ProtocolContext.class);
    final Synchronizer synchronizerMock = mock(Synchronizer.class);
    final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class);
    final TransactionPool transactionPoolMock = mock(TransactionPool.class);
    final PoWMiningCoordinator miningCoordinatorMock = mock(PoWMiningCoordinator.class);
    when(transactionPoolMock.addLocalTransaction(any(Transaction.class))).thenReturn(ValidationResult.valid());
    // nonce too low tests uses a tx with nonce=16
    when(transactionPoolMock.addLocalTransaction(argThat(tx -> tx.getNonce() == 16))).thenReturn(ValidationResult.invalid(TransactionInvalidReason.NONCE_TOO_LOW));
    final GasPricePendingTransactionsSorter pendingTransactionsMock = mock(GasPricePendingTransactionsSorter.class);
    when(transactionPoolMock.getPendingTransactions()).thenReturn(pendingTransactionsMock);
    final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
    final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchainSetupUtil.getBlockchain(), blockchainSetupUtil.getWorldArchive());
    final FilterIdGenerator filterIdGenerator = mock(FilterIdGenerator.class);
    final FilterRepository filterRepository = new FilterRepository();
    when(filterIdGenerator.nextId()).thenReturn("0x1");
    filterManager = new FilterManagerBuilder().blockchainQueries(blockchainQueries).transactionPool(transactionPoolMock).filterIdGenerator(filterIdGenerator).filterRepository(filterRepository).build();
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    final NatService natService = new NatService(Optional.empty());
    return new JsonRpcMethodsFactory().methods(CLIENT_VERSION, NETWORK_ID, new StubGenesisConfigOptions(), peerDiscoveryMock, blockchainQueries, synchronizerMock, blockchainSetupUtil.getProtocolSchedule(), protocolContext, filterManager, transactionPoolMock, miningCoordinatorMock, new NoOpMetricsSystem(), supportedCapabilities, Optional.empty(), Optional.empty(), JSON_RPC_APIS, privacyParameters, config, mock(WebSocketConfiguration.class), mock(MetricsConfiguration.class), natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class));
}
Also used : ValidationResult(org.hyperledger.besu.ethereum.mainnet.ValidationResult) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) URL(java.net.URL) FilterRepository(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BlockchainSetupUtil(org.hyperledger.besu.ethereum.core.BlockchainSetupUtil) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) FilterManagerBuilder(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder) Map(java.util.Map) After(org.junit.After) BigInteger(java.math.BigInteger) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) ClassRule(org.junit.ClassRule) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) MediaType(okhttp3.MediaType) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) Collection(java.util.Collection) Set(java.util.Set) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) Optional(java.util.Optional) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ChainResources(org.hyperledger.besu.testutil.BlockTestUtil.ChainResources) HashMap(java.util.HashMap) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) EthProtocol(org.hyperledger.besu.ethereum.eth.EthProtocol) HashSet(java.util.HashSet) FilterManager(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager) HealthService(org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Before(org.junit.Before) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Vertx(io.vertx.core.Vertx) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) Mockito.when(org.mockito.Mockito.when) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) OkHttpClient(okhttp3.OkHttpClient) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) FilterIdGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterIdGenerator) Transaction(org.hyperledger.besu.ethereum.core.Transaction) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) NatService(org.hyperledger.besu.nat.NatService) TemporaryFolder(org.junit.rules.TemporaryFolder) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) NatService(org.hyperledger.besu.nat.NatService) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) FilterManagerBuilder(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) Transaction(org.hyperledger.besu.ethereum.core.Transaction) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) FilterRepository(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository) FilterIdGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterIdGenerator) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) HashSet(java.util.HashSet)

Aggregations

JsonRpcMethodsFactory (org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory)12 StubGenesisConfigOptions (org.hyperledger.besu.config.StubGenesisConfigOptions)11 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)11 HashSet (java.util.HashSet)10 Capability (org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability)10 FilterManager (org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager)9 PoWMiningCoordinator (org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator)9 PrivacyParameters (org.hyperledger.besu.ethereum.core.PrivacyParameters)9 EthPeers (org.hyperledger.besu.ethereum.eth.manager.EthPeers)9 TransactionPool (org.hyperledger.besu.ethereum.eth.transactions.TransactionPool)9 P2PNetwork (org.hyperledger.besu.ethereum.p2p.network.P2PNetwork)9 MetricsConfiguration (org.hyperledger.besu.metrics.prometheus.MetricsConfiguration)9 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)8 WebSocketConfiguration (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration)8 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)8 Synchronizer (org.hyperledger.besu.ethereum.core.Synchronizer)8 Before (org.junit.Before)6 JsonRpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod)5 HashMap (java.util.HashMap)4 OkHttpClient (okhttp3.OkHttpClient)4