private BigInteger getLatestBlockIndex() throws IOException { return neow3j.getBlockCount().send().getBlockIndex(); }
public BigInteger getBlockIndex() { return getResult(); }
@Test public void testErrorResponseComplexData() { buildResponse( "{" + " \"jsonrpc\":\"2.0\"," + " \"id\":1," + " \"error\":{" + " \"code\":-32602," + " \"message\":\"Invalid address length, expected 40 got 64 bytes\"," + " \"data\":{\"foo\":\"bar\"}" + " }" + "}" ); NeoBlockCount ethBlock = deserialiseResponse(NeoBlockCount.class); assertTrue(ethBlock.hasError()); assertThat(ethBlock.getError().getData(), equalTo("{\"foo\":\"bar\"}")); }
@Test public void testErrorResponse() { buildResponse( "{" + " \"jsonrpc\":\"2.0\"," + " \"id\":1," + " \"error\":{" + " \"code\":-32602," + " \"message\":\"Invalid address length, expected 40 got 64 bytes\"," + " \"data\":null" + " }" + "}" ); NeoBlockCount ethBlock = deserialiseResponse(NeoBlockCount.class); assertTrue(ethBlock.hasError()); assertThat(ethBlock.getError(), equalTo( new Response.Error(-32602, "Invalid address length, expected 40 got 64 bytes"))); }
@Test public void testGetBlockCount() { buildResponse( "{\n" + " \"id\":67,\n" + " \"jsonrpc\":\"2.0\",\n" + " \"result\": 1234\n" + "}" ); NeoBlockCount neoBlockCount = deserialiseResponse(NeoBlockCount.class); assertThat(neoBlockCount.getBlockIndex(), is(notNullValue())); assertThat(neoBlockCount.getBlockIndex(), is(BigInteger.valueOf(1234))); }
private BigInteger getBlockNumber( BlockParameter defaultBlockParameter) throws IOException { if (defaultBlockParameter instanceof BlockParameterIndex) { return ((BlockParameterIndex) defaultBlockParameter).getBlockIndex(); } else { if (defaultBlockParameter instanceof BlockParameterName) { if (defaultBlockParameter.getValue() == BlockParameterName.EARLIEST.getValue()) { return BigInteger.ZERO; } } NeoBlockCount latestNeoBlock = neow3j.getBlockCount().send(); return latestNeoBlock.getBlockIndex(); } }