use of org.web3j.protocol.Web3jService in project besu by hyperledger.
the class BesuNode method nodeRequests.
private NodeRequests nodeRequests() {
Optional<WebSocketService> websocketService = Optional.empty();
if (nodeRequests == null) {
final Web3jService web3jService;
if (useWsForJsonRpc) {
final String url = wsRpcBaseUrl().orElse("ws://" + LOCALHOST + ":" + 8546);
final Map<String, String> headers = new HashMap<>();
if (token != null) {
headers.put("Authorization", "Bearer " + token);
}
final WebSocketClient wsClient = new WebSocketClient(URI.create(url), headers);
web3jService = new WebSocketService(wsClient, false);
try {
((WebSocketService) web3jService).connect();
} catch (final ConnectException e) {
throw new RuntimeException(e);
}
websocketService = Optional.of((WebSocketService) web3jService);
} else {
final String url = jsonRpcBaseUrl().orElse(HTTP + LOCALHOST + ":" + 8545);
web3jService = new HttpService(url);
if (token != null) {
((HttpService) web3jService).addHeader("Authorization", "Bearer " + token);
}
}
final ConsensusType bftType = getGenesisConfig().map(gc -> gc.toLowerCase().contains("ibft") ? ConsensusType.IBFT2 : ConsensusType.QBFT).orElse(ConsensusType.IBFT2);
nodeRequests = new NodeRequests(new JsonRpc2_0Web3j(web3jService, 2000, Async.defaultExecutorService()), new CliqueRequestFactory(web3jService), new BftRequestFactory(web3jService, bftType), new PermissioningJsonRpcRequestFactory(web3jService), new AdminRequestFactory(web3jService), new PrivacyRequestFactory(web3jService), new CustomRequestFactory(web3jService), new MinerRequestFactory(web3jService), new TxPoolRequestFactory(web3jService), websocketService, loginRequestFactory());
}
return nodeRequests;
}
Aggregations