org.web3j.protocol.core.methods.response.Web3ClientVersion Java Examples
The following examples show how to use
org.web3j.protocol.core.methods.response.Web3ClientVersion.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 6 votes |
@Test public void testCancelRequestAfterTimeout() { when(executorService.schedule( any(Runnable.class), eq(WebSocketService.REQUEST_TIMEOUT), eq(TimeUnit.SECONDS))) .then( invocation -> { Runnable runnable = invocation.getArgument(0, Runnable.class); runnable.run(); return null; }); CompletableFuture<Web3ClientVersion> reply = service.sendAsync(request, Web3ClientVersion.class); assertTrue(reply.isDone()); assertThrows(ExecutionException.class, () -> reply.get()); }
Example #2
Source File: TransactionHandler.java From alpha-wallet-android with MIT License | 6 votes |
public TransactionHandler(int networkId) { String nodeURL = EthRPCNodes.getNodeURLByNetworkId(networkId); OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.connectTimeout(20, TimeUnit.SECONDS); builder.readTimeout(20, TimeUnit.SECONDS); HttpService service = new HttpService(nodeURL, builder.build(), false); mWeb3 = Web3j.build(service); try { Web3ClientVersion web3ClientVersion = mWeb3.web3ClientVersion().sendAsync().get(); System.out.println(web3ClientVersion.getWeb3ClientVersion()); } catch (Exception e) { e.printStackTrace(); } }
Example #3
Source File: TransactionHandler.java From alpha-wallet-android with MIT License | 6 votes |
public TransactionHandler(int networkId) { String nodeURL = EthereumNetworkBase.getNetworkByChain(networkId).rpcServerUrl; OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.connectTimeout(20, TimeUnit.SECONDS); builder.readTimeout(20, TimeUnit.SECONDS); HttpService service = new HttpService(nodeURL, builder.build(), false); mWeb3 = Web3j.build(service); try { Web3ClientVersion web3ClientVersion = mWeb3.web3ClientVersion().sendAsync().get(); System.out.println(web3ClientVersion.getWeb3ClientVersion()); } catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: WebSocketServiceTest.java From client-sdk-java with Apache License 2.0 | 6 votes |
@Test(expected = ExecutionException.class) public void testCancelRequestAfterTimeout() throws Exception { when(executorService.schedule( any(Runnable.class), eq(WebSocketService.REQUEST_TIMEOUT), eq(TimeUnit.SECONDS))) .then(invocation -> { Runnable runnable = invocation.getArgumentAt(0, Runnable.class); runnable.run(); return null; }); CompletableFuture<Web3ClientVersion> reply = service.sendAsync( request, Web3ClientVersion.class); assertTrue(reply.isDone()); reply.get(); }
Example #5
Source File: WebSocketServiceTest.java From client-sdk-java with Apache License 2.0 | 6 votes |
@Test public void testSyncRequest() throws Exception { CountDownLatch requestSent = new CountDownLatch(1); // Wait for a request to be sent doAnswer(invocation -> { requestSent.countDown(); return null; }).when(webSocketClient).send(anyString()); // Send reply asynchronously runAsync(() -> { try { requestSent.await(2, TimeUnit.SECONDS); sendGethVersionReply(); } catch (Exception e) { throw new RuntimeException(e); } }); Web3ClientVersion reply = service.send(request, Web3ClientVersion.class); assertEquals(reply.getWeb3ClientVersion(), "geth-version"); }
Example #6
Source File: UnixDomainSocketTest.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Test public void testSlowResponse() throws Exception { String response = "{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n"; unixDomainSocket = new UnixDomainSocket(reader, writer, response.length()); final LinkedList<String> segments = new LinkedList<>(); // 1st part of response segments.add(response.substring(0, 50)); // rest of response segments.add(response.substring(50)); doAnswer(invocation -> { String segment = segments.poll(); if (segment == null) { return 0; } else { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append(segment); return segment.length(); } }).when(reader).read(any(CharBuffer.class)); IpcService ipcService = new IpcService() { @Override protected IOFacade getIO() { return unixDomainSocket; } }; ipcService.send(new Request(), Web3ClientVersion.class); }
Example #7
Source File: EthereumNetworkManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override protected String doInBackground(Void... params) { Web3ClientVersion web3ClientVersion = null; try { web3ClientVersion = web3jConnection.web3ClientVersion().send(); String clientVersion = web3ClientVersion.getWeb3ClientVersion(); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #8
Source File: IpcServiceTest.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Test public void testSend() throws IOException { when(ioFacade.read()).thenReturn( "{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n"); ipcService.send(new Request(), Web3ClientVersion.class); verify(ioFacade).write("{\"jsonrpc\":\"2.0\",\"method\":null,\"params\":null,\"id\":0}"); }
Example #9
Source File: WalletSendFunds.java From client-sdk-java with Apache License 2.0 | 5 votes |
private Web3j getEthereumClient() { String clientAddress = console.readLine( "Please confirm address of running Ethereum client you wish to send " + "the transfer request to [" + HttpService.DEFAULT_URL + "]: ") .trim(); Web3j web3j; if (clientAddress.equals("")) { web3j = Web3j.build(new HttpService()); } else { web3j = Web3j.build(new HttpService(clientAddress)); } try { Web3ClientVersion web3ClientVersion = web3j.web3ClientVersion().sendAsync().get(); if (web3ClientVersion.hasError()) { exitError("Unable to process response from client: " + web3ClientVersion.getError()); } else { console.printf("Connected successfully to client: %s%n", web3ClientVersion.getWeb3ClientVersion()); return web3j; } } catch (InterruptedException | ExecutionException e) { exitError("Problem encountered verifying client: " + e.getMessage()); } throw new RuntimeException("Application exit failure"); }
Example #10
Source File: EthereumNetworkManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override protected String doInBackground(Void... params) { Web3ClientVersion web3ClientVersion = null; try { web3ClientVersion = web3jConnection.web3ClientVersion().send(); String clientVersion = web3ClientVersion.getWeb3ClientVersion(); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #11
Source File: EthereumNetworkManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override protected String doInBackground(Void... params) { Web3ClientVersion web3ClientVersion = null; try { web3ClientVersion = web3jConnection.web3ClientVersion().send(); String clientVersion = web3ClientVersion.getWeb3ClientVersion(); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #12
Source File: AbstractDemo.java From web3j_demo with Apache License 2.0 | 5 votes |
public void run() throws Exception { // show client details Web3ClientVersion client = web3j .web3ClientVersion() .sendAsync() .get(); System.out.println("Connected to " + client.getWeb3ClientVersion() + "\n"); }
Example #13
Source File: Web3jUtils.java From web3j_demo with Apache License 2.0 | 5 votes |
public static String getClientVersion(Web3j web3j) throws InterruptedException, ExecutionException { Web3ClientVersion client = web3j .web3ClientVersion() .sendAsync() .get(); return client.getWeb3ClientVersion(); }
Example #14
Source File: CoreIT.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testWeb3ClientVersion() throws Exception { Web3ClientVersion web3ClientVersion = web3j.web3ClientVersion().send(); String clientVersion = web3ClientVersion.getWeb3ClientVersion(); System.out.println("Ethereum client version: " + clientVersion); assertFalse(clientVersion.isEmpty()); }
Example #15
Source File: JsonRpc2_0Web3j.java From web3j with Apache License 2.0 | 5 votes |
@Override public Request<?, Web3ClientVersion> web3ClientVersion() { return new Request<>( "web3_clientVersion", Collections.<String>emptyList(), web3jService, Web3ClientVersion.class); }
Example #16
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testAddedWebSocketListener() throws Exception { doAnswer( invocation -> { listener = invocation.getArgument(0, WebSocketListener.class); return null; }) .when(webSocketClient) .setListener(any()); final CountDownLatch onMessageCountDownLatch = new CountDownLatch(1); final CountDownLatch onCloseCountDownLatch = new CountDownLatch(1); final CountDownLatch onErrorCountDownLatch = new CountDownLatch(1); service.connect( message -> onMessageCountDownLatch.countDown(), throwable -> onErrorCountDownLatch.countDown(), onCloseCountDownLatch::countDown); service.sendAsync(request, Web3ClientVersion.class); listener.onMessage( "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":1}"); assertTrue(onMessageCountDownLatch.await(2L, TimeUnit.SECONDS)); listener.onError(new Exception()); assertTrue(onErrorCountDownLatch.await(2L, TimeUnit.SECONDS)); listener.onClose(); assertTrue(onCloseCountDownLatch.await(2L, TimeUnit.SECONDS)); }
Example #17
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testNoLongerWaitingForResponseAfterReply() throws Exception { service.sendAsync(request, Web3ClientVersion.class); sendGethVersionReply(); assertFalse(service.isWaitingForReply(1)); }
Example #18
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testSendWebSocketRequest() throws Exception { service.sendAsync(request, Web3ClientVersion.class); verify(webSocketClient) .send( "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":1}"); }
Example #19
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testThrowExceptionIfUnexpectedIdIsReceived() { service.sendAsync(request, Web3ClientVersion.class); assertThrows( IOException.class, () -> service.onWebSocketMessage( "{\"jsonrpc\":\"2.0\",\"id\":12345,\"result\":\"geth-version\"}")); }
Example #20
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testReceiveReply() throws Exception { CompletableFuture<Web3ClientVersion> reply = service.sendAsync(request, Web3ClientVersion.class); sendGethVersionReply(); assertTrue(reply.isDone()); assertEquals("geth-version", reply.get().getWeb3ClientVersion()); }
Example #21
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testReceiveError() throws Exception { CompletableFuture<Web3ClientVersion> reply = service.sendAsync(request, Web3ClientVersion.class); sendErrorReply(); assertTrue(reply.isDone()); Web3ClientVersion version = reply.get(); assertTrue(version.hasError()); assertEquals(new Response.Error(-1, "Error message"), version.getError()); }
Example #22
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testCloseRequestWhenConnectionIsClosed() { CompletableFuture<Web3ClientVersion> reply = service.sendAsync(request, Web3ClientVersion.class); service.onWebSocketClose(); assertTrue(reply.isDone()); assertThrows(ExecutionException.class, () -> reply.get()); }
Example #23
Source File: WebSocketServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testSyncRequest() throws Exception { CountDownLatch requestSent = new CountDownLatch(1); // Wait for a request to be sent doAnswer( invocation -> { requestSent.countDown(); return null; }) .when(webSocketClient) .send(anyString()); // Send reply asynchronously runAsync( () -> { try { requestSent.await(2, TimeUnit.SECONDS); sendGethVersionReply(); } catch (Exception e) { throw new RuntimeException(e); } }); Web3ClientVersion reply = service.send(request, Web3ClientVersion.class); assertEquals(reply.getWeb3ClientVersion(), "geth-version"); }
Example #24
Source File: ResponseTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testWeb3ClientVersion() { buildResponse( "{\n" + " \"id\":67,\n" + " \"jsonrpc\":\"2.0\",\n" + " \"result\": \"Mist/v0.9.3/darwin/go1.4.1\"\n" + "}"); Web3ClientVersion web3ClientVersion = deserialiseResponse(Web3ClientVersion.class); assertEquals(web3ClientVersion.getWeb3ClientVersion(), ("Mist/v0.9.3/darwin/go1.4.1")); }
Example #25
Source File: UnixDomainSocketTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testSlowResponse() throws Exception { String response = "{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n"; unixDomainSocket = new UnixDomainSocket(reader, writer, response.length()); final LinkedList<String> segments = new LinkedList<>(); // 1st part of response segments.add(response.substring(0, 50)); // rest of response segments.add(response.substring(50)); doAnswer( invocation -> { String segment = segments.poll(); if (segment == null) { return 0; } else { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append(segment); return segment.length(); } }) .when(reader) .read(any(CharBuffer.class)); IpcService ipcService = new IpcService() { @Override protected IOFacade getIO() { return unixDomainSocket; } }; ipcService.send(new Request(), Web3ClientVersion.class); }
Example #26
Source File: IpcServiceTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testSend() throws IOException { when(ioFacade.read()) .thenReturn( "{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n"); ipcService.send(new Request(), Web3ClientVersion.class); verify(ioFacade).write("{\"jsonrpc\":\"2.0\",\"method\":null,\"params\":null,\"id\":0}"); }
Example #27
Source File: WebSocketServiceTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Test public void testReceiveError() throws Exception { CompletableFuture<Web3ClientVersion> reply = service.sendAsync( request, Web3ClientVersion.class); sendErrorReply(); assertTrue(reply.isDone()); Web3ClientVersion version = reply.get(); assertTrue(version.hasError()); assertEquals( new Response.Error(-1, "Error message"), version.getError()); }
Example #28
Source File: JsonRpc2_0Web3j.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Override public Request<?, Web3ClientVersion> web3ClientVersion() { return new Request<>( "web3_clientVersion", Collections.<String>emptyList(), web3jService, Web3ClientVersion.class); }
Example #29
Source File: WebSocketServiceTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Test public void testNoLongerWaitingForResponseAfterReply() throws Exception { service.sendAsync(request, Web3ClientVersion.class); sendGethVersionReply(); assertFalse(service.isWaitingForReply(1)); }
Example #30
Source File: WebSocketServiceTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Test public void testSendWebSocketRequest() throws Exception { service.sendAsync(request, Web3ClientVersion.class); verify(webSocketClient).send( "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":1}"); }