boolean isSynced() throws Exception { EthSyncing ethSyncing = web3j.ethSyncing().send(); if (ethSyncing.isSyncing()) { return false; } else { EthBlock ethBlock = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send(); long timestamp = ethBlock.getBlock().getTimestamp().longValueExact() * 1000; return System.currentTimeMillis() - syncThreshold < timestamp; } }
@Test public void testEthSyncing() { buildResponse( "{\n" + " \"id\":1,\n" + " \"jsonrpc\": \"2.0\",\n" + " \"result\": false\n" + "}" ); EthSyncing ethSyncing = deserialiseResponse(EthSyncing.class); assertThat(ethSyncing.isSyncing(), is(false)); }
@InvokeOnHeader(Web3jConstants.ETH_SYNCING) void ethSyncing(Message message) throws IOException { Request<?, EthSyncing> request = web3j.ethSyncing(); setRequestId(message, request); EthSyncing response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.isSyncing()); } }
boolean isSyncing = ethSyncing.isSyncing(); System.out.println(isSyncing);