org.web3j.protocol.core.methods.response.EthBlockNumber Java Examples

The following examples show how to use org.web3j.protocol.core.methods.response.EthBlockNumber. 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: EthereumRestController.java    From tutorials with MIT License 6 votes vote down vote up
@RequestMapping(value = Constants.API_BLOCK, method = RequestMethod.GET)
public Future<ResponseTransfer> getBlock() {
    ResponseTransfer responseTransfer = new ResponseTransfer();
    Instant start = TimeHelper.start();

    return CompletableFuture.supplyAsync(() -> {
        try {
            EthBlockNumber result = web3Service.getBlockNumber();
            responseTransfer.setMessage(result.toString());
        } catch (Exception e) {
            responseTransfer.setMessage(GENERIC_EXCEPTION);
        }
        return responseTransfer;
    }).thenApplyAsync(result -> {
        result.setPerformance(TimeHelper.stop(start));
        return result;
    });
}
 
Example #2
Source File: TokenRepository.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
public Single<BigInteger> fetchLatestBlockNumber(int chainId)
{
    return Single.fromCallable(() -> {
        try
        {
            EthBlockNumber blk = getService(chainId).ethBlockNumber()
                    .send();
            return blk.getBlockNumber();
        }
        catch (Exception e)
        {
            return BigInteger.ZERO;
        }
    });
}
 
Example #3
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected BigInteger doInBackground(Void... params) {
    if (web3jConnection != null) {
        try {
            EthBlockNumber blockNumber = web3jConnection.ethBlockNumber().send();
            return blockNumber.getBlockNumber();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    return null;
}
 
Example #4
Source File: Web3Service.java    From tutorials with MIT License 5 votes vote down vote up
public EthBlockNumber getBlockNumber() {
    EthBlockNumber result = new EthBlockNumber();
    try {
        result = this.web3j.ethBlockNumber().sendAsync().get();
    } catch (Exception ex) {
        System.out.println(GENERIC_EXCEPTION);
    }
    return result;
}
 
Example #5
Source File: ResponseTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testEthBlockNumber() {
    buildResponse(
            "{\n"
                    + "  \"id\":83,\n"
                    + "  \"jsonrpc\": \"2.0\",\n"
                    + "  \"result\": \"0x4b7\"\n"
                    + "}");

    EthBlockNumber ethBlockNumber = deserialiseResponse(EthBlockNumber.class);
    assertEquals(ethBlockNumber.getBlockNumber(), (BigInteger.valueOf(1207L)));
}
 
Example #6
Source File: JsonRpc2_0Web3j.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, EthBlockNumber> ethBlockNumber() {
    return new Request<>(
            "eth_blockNumber",
            Collections.<String>emptyList(),
            web3jService,
            EthBlockNumber.class);
}
 
Example #7
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private String getBlocNumber() {
    if (web3jConnection != null) {
        try {
            EthBlockNumber blockNumber = web3jConnection.ethBlockNumber().send();
            return blockNumber.getBlockNumber().toString();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    return null;
}
 
Example #8
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private String getBlocNumber() {
    if (web3jConnection != null) {
        try {
            EthBlockNumber blockNumber = web3jConnection.ethBlockNumber().send();
            return blockNumber.getBlockNumber().toString();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    return null;
}
 
Example #9
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected BigInteger doInBackground(Void... params) {
    if (web3jConnection != null) {
        try {
            EthBlockNumber blockNumber = web3jConnection.ethBlockNumber().send();
            return blockNumber.getBlockNumber();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    return null;
}
 
Example #10
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private String getBlockNumber() {
    if (web3jConnection != null) {
        try {
            EthBlockNumber blockNumber = web3jConnection.ethBlockNumber().send();
            return blockNumber.getBlockNumber().toString();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    return null;
}
 
Example #11
Source File: ResponseTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEthBlockNumber() {
    buildResponse(
            "{\n"
                    + "  \"id\":83,\n"
                    + "  \"jsonrpc\": \"2.0\",\n"
                    + "  \"result\": \"0x4b7\"\n"
                    + "}"
    );

    EthBlockNumber ethBlockNumber = deserialiseResponse(EthBlockNumber.class);
    assertThat(ethBlockNumber.getBlockNumber(), equalTo(BigInteger.valueOf(1207L)));
}
 
Example #12
Source File: JsonRpc2_0Web3j.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Request<?, EthBlockNumber> ethBlockNumber() {
    return new Request<>(
            "eth_blockNumber",
            Collections.<String>emptyList(),
            web3jService,
            EthBlockNumber.class);
}
 
Example #13
Source File: CoreIT.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testEthBlockNumber() throws Exception {
    EthBlockNumber ethBlockNumber = web3j.ethBlockNumber().send();
    assertTrue(ethBlockNumber.getBlockNumber().signum() == 1);
}
 
Example #14
Source File: CoreIT.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testEthBlockNumber() throws Exception {
    EthBlockNumber ethBlockNumber = web3j.ethBlockNumber().send();
    assertTrue(ethBlockNumber.getBlockNumber().signum() == 1);
}
 
Example #15
Source File: EthQueryExecutor.java    From eth-jdbc-connector with Apache License 2.0 4 votes vote down vote up
private BigInteger getBlockHeight() throws IOException {
    LOGGER.info("Getting block height ");
    EthBlockNumber block = web3jClient.ethBlockNumber().send();
    return block.getBlockNumber();
}
 
Example #16
Source File: Ethereum.java    From web3j with Apache License 2.0 votes vote down vote up
Request<?, EthBlockNumber> ethBlockNumber(); 
Example #17
Source File: Ethereum.java    From etherscan-explorer with GNU General Public License v3.0 votes vote down vote up
Request<?, EthBlockNumber> ethBlockNumber();