Search in sources :

Example 1 with ModuleDescription

use of co.rsk.rpc.ModuleDescription in project rskj by rsksmart.

the class Web3Impl method rpc_modules.

@Override
public Map<String, String> rpc_modules() {
    logger.debug("rpc_modules...");
    Map<String, String> map = new HashMap<>();
    for (ModuleDescription module : config.getRpcModules()) {
        if (module.isEnabled()) {
            map.put(module.getName(), module.getVersion());
        }
    }
    return map;
}
Also used : ModuleDescription(co.rsk.rpc.ModuleDescription)

Example 2 with ModuleDescription

use of co.rsk.rpc.ModuleDescription in project rskj by rsksmart.

the class Web3HttpServerTest method smokeTest.

private void smokeTest(String contentType, String host, InetAddress rpcAddress, List<String> rpcHost) throws Exception {
    Web3 web3Mock = Mockito.mock(Web3.class);
    String mockResult = "output";
    Mockito.when(web3Mock.web3_sha3(Mockito.anyString())).thenReturn(mockResult);
    CorsConfiguration mockCorsConfiguration = Mockito.mock(CorsConfiguration.class);
    Mockito.when(mockCorsConfiguration.hasHeader()).thenReturn(true);
    Mockito.when(mockCorsConfiguration.getHeader()).thenReturn("*");
    // new ServerSocket(0).getLocalPort();
    int randomPort = 9999;
    List<ModuleDescription> filteredModules = Collections.singletonList(new ModuleDescription("web3", "1.0", true, Collections.emptyList(), Collections.emptyList()));
    JsonRpcWeb3FilterHandler filterHandler = new JsonRpcWeb3FilterHandler("*", rpcAddress, rpcHost);
    JsonRpcWeb3ServerHandler serverHandler = new JsonRpcWeb3ServerHandler(web3Mock, filteredModules);
    Web3HttpServer server = new Web3HttpServer(InetAddress.getLoopbackAddress(), randomPort, 0, Boolean.TRUE, mockCorsConfiguration, filterHandler, serverHandler);
    server.start();
    try {
        Response response = sendJsonRpcMessage(randomPort, contentType, host);
        JsonNode jsonRpcResponse = OBJECT_MAPPER.readTree(response.body().string());
        assertThat(response.code(), is(HttpResponseStatus.OK.code()));
        assertThat(jsonRpcResponse.at("/result").asText(), is(mockResult));
    } finally {
        server.stop();
    }
}
Also used : CorsConfiguration(co.rsk.rpc.CorsConfiguration) ModuleDescription(co.rsk.rpc.ModuleDescription) Web3(org.ethereum.rpc.Web3) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with ModuleDescription

use of co.rsk.rpc.ModuleDescription in project rskj by rsksmart.

the class RskSystemProperties method getRpcModules.

public List<ModuleDescription> getRpcModules() {
    if (this.moduleDescriptions != null) {
        return this.moduleDescriptions;
    }
    List<ModuleDescription> modules = new ArrayList<>();
    if (!configFromFiles.hasPath("rpc.modules")) {
        return modules;
    }
    List<? extends ConfigObject> list = configFromFiles.getObjectList("rpc.modules");
    for (ConfigObject configObject : list) {
        Config configElement = configObject.toConfig();
        String name = configElement.getString("name");
        String version = configElement.getString("version");
        boolean enabled = configElement.getBoolean("enabled");
        List<String> enabledMethods = null;
        List<String> disabledMethods = null;
        if (configElement.hasPath("methods.enabled")) {
            enabledMethods = configElement.getStringList("methods.enabled");
        }
        if (configElement.hasPath("methods.disabled")) {
            disabledMethods = configElement.getStringList("methods.disabled");
        }
        modules.add(new ModuleDescription(name, version, enabled, enabledMethods, disabledMethods));
    }
    this.moduleDescriptions = modules;
    return modules;
}
Also used : ModuleDescription(co.rsk.rpc.ModuleDescription) Config(com.typesafe.config.Config) ArrayList(java.util.ArrayList) ConfigObject(com.typesafe.config.ConfigObject)

Aggregations

ModuleDescription (co.rsk.rpc.ModuleDescription)3 CorsConfiguration (co.rsk.rpc.CorsConfiguration)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Config (com.typesafe.config.Config)1 ConfigObject (com.typesafe.config.ConfigObject)1 ArrayList (java.util.ArrayList)1 Web3 (org.ethereum.rpc.Web3)1