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;
}
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();
}
}
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;
}
Aggregations