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

The following examples show how to use org.web3j.protocol.core.methods.response.NetVersion. 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: EnsResolver.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private String lookupResolver(String ensName) throws Exception
{
    NetVersion netVersion = web3j.netVersion().send();
    String registryContract = Contracts.resolveRegistryContract(netVersion.getNetVersion());
    byte[] nameHash = NameHash.nameHashAsBytes(ensName);
    Function resolver = getResolver(nameHash);
    return getContractData(EthereumNetworkBase.MAINNET_ID, registryContract, resolver);
}
 
Example #2
Source File: ResponseTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testNetVersion() throws IOException {
    buildResponse(
            "{\n"
                    + "  \"id\":67,\n"
                    + "  \"jsonrpc\": \"2.0\",\n"
                    + "  \"result\": \"59\"\n"
                    + "}");

    NetVersion netVersion = deserialiseResponse(NetVersion.class);
    assertEquals(netVersion.getNetVersion(), ("59"));
}
 
Example #3
Source File: EnsResolverTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testReverseResolve() throws Exception {
    configureSyncing(false);
    configureLatestBlock(System.currentTimeMillis() / 1000); // block timestamp is in seconds

    NetVersion netVersion = new NetVersion();
    netVersion.setResult(Long.toString(ChainIdLong.MAINNET));

    String resolverAddress =
            "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a";
    String contractName =
            "0x0000000000000000000000000000000000000000000000000000000000000020"
                    + TypeEncoder.encode(new Utf8String("web3j.eth"));
    System.err.println(contractName);

    EthCall resolverAddressResponse = new EthCall();
    resolverAddressResponse.setResult(resolverAddress);

    EthCall contractNameResponse = new EthCall();
    contractNameResponse.setResult(contractName);

    when(web3jService.send(any(Request.class), eq(NetVersion.class))).thenReturn(netVersion);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(resolverAddressResponse);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(contractNameResponse);

    assertEquals(
            ensResolver.reverseResolve("0x19e03255f667bdfd50a32722df860b1eeaf4d635"),
            ("web3j.eth"));
}
 
Example #4
Source File: EnsResolverTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolve() throws Exception {
    configureSyncing(false);
    configureLatestBlock(System.currentTimeMillis() / 1000); // block timestamp is in seconds

    NetVersion netVersion = new NetVersion();
    netVersion.setResult(Long.toString(ChainIdLong.MAINNET));

    String resolverAddress =
            "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a";
    String contractAddress =
            "0x00000000000000000000000019e03255f667bdfd50a32722df860b1eeaf4d635";

    EthCall resolverAddressResponse = new EthCall();
    resolverAddressResponse.setResult(resolverAddress);

    EthCall contractAddressResponse = new EthCall();
    contractAddressResponse.setResult(contractAddress);

    when(web3jService.send(any(Request.class), eq(NetVersion.class))).thenReturn(netVersion);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(resolverAddressResponse);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(contractAddressResponse);

    assertEquals(
            ensResolver.resolve("web3j.eth"), ("0x19e03255f667bdfd50a32722df860b1eeaf4d635"));
}
 
Example #5
Source File: EnsResolver.java    From web3j with Apache License 2.0 5 votes vote down vote up
private PublicResolver lookupResolver(String ensName) throws Exception {
    NetVersion netVersion = web3j.netVersion().send();
    String registryContract = Contracts.resolveRegistryContract(netVersion.getNetVersion());

    ENS ensRegistry =
            ENS.load(registryContract, web3j, transactionManager, new DefaultGasProvider());

    byte[] nameHash = NameHash.nameHashAsBytes(ensName);
    String resolverAddress = ensRegistry.resolver(nameHash).send();

    return PublicResolver.load(
            resolverAddress, web3j, transactionManager, new DefaultGasProvider());
}
 
Example #6
Source File: NetVersionTransaction.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public String execute(final NodeRequests node) {
  try {
    final NetVersion result = node.net().netVersion().send();
    assertThat(result).isNotNull();
    if (result.hasError()) {
      throw new RuntimeException(result.getError().getMessage());
    }
    return result.getNetVersion();
  } catch (final Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #7
Source File: ResponseTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNetVersion() throws IOException {
    buildResponse(
            "{\n"
                    + "  \"id\":67,\n"
                    + "  \"jsonrpc\": \"2.0\",\n"
                    + "  \"result\": \"59\"\n"
                    + "}"
    );

    NetVersion netVersion = deserialiseResponse(NetVersion.class);
    assertThat(netVersion.getNetVersion(), is("59"));
}
 
Example #8
Source File: EnsResolverTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testReverseResolve() throws Exception {
    configureSyncing(false);
    configureLatestBlock(System.currentTimeMillis() / 1000);  // block timestamp is in seconds

    NetVersion netVersion = new NetVersion();
    netVersion.setResult(Byte.toString(ChainId.MAINNET));

    String resolverAddress =
            "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a";
    String contractName =
            "0x0000000000000000000000000000000000000000000000000000000000000020"
            + TypeEncoder.encode(new Utf8String("web3j.eth"));
    System.err.println(contractName);

    EthCall resolverAddressResponse = new EthCall();
    resolverAddressResponse.setResult(resolverAddress);

    EthCall contractNameResponse = new EthCall();
    contractNameResponse.setResult(contractName);

    when(web3jService.send(any(Request.class), eq(NetVersion.class)))
            .thenReturn(netVersion);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(resolverAddressResponse);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(contractNameResponse);

    assertThat(ensResolver.reverseResolve("0x19e03255f667bdfd50a32722df860b1eeaf4d635"),
            is("web3j.eth"));
}
 
Example #9
Source File: EnsResolverTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testResolve() throws Exception {
    configureSyncing(false);
    configureLatestBlock(System.currentTimeMillis() / 1000);  // block timestamp is in seconds

    NetVersion netVersion = new NetVersion();
    netVersion.setResult(Byte.toString(ChainId.MAINNET));

    String resolverAddress =
            "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a";
    String contractAddress =
            "0x00000000000000000000000019e03255f667bdfd50a32722df860b1eeaf4d635";

    EthCall resolverAddressResponse = new EthCall();
    resolverAddressResponse.setResult(resolverAddress);

    EthCall contractAddressResponse = new EthCall();
    contractAddressResponse.setResult(contractAddress);

    when(web3jService.send(any(Request.class), eq(NetVersion.class)))
            .thenReturn(netVersion);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(resolverAddressResponse);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(contractAddressResponse);

    assertThat(ensResolver.resolve("web3j.eth"),
            is("0x19e03255f667bdfd50a32722df860b1eeaf4d635"));
}
 
Example #10
Source File: JsonRpc2_0Web3j.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Request<?, NetVersion> netVersion() {
    return new Request<>(
            "net_version",
            Collections.<String>emptyList(),
            web3jService,
            NetVersion.class);
}
 
Example #11
Source File: JsonRpc2_0Web3j.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, NetVersion> netVersion() {
    return new Request<>(
            "net_version",
            Collections.<String>emptyList(),
            web3jService,
            NetVersion.class);
}
 
Example #12
Source File: CoreIT.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testNetVersion() throws Exception {
    NetVersion netVersion = web3j.netVersion().send();
    assertFalse(netVersion.getNetVersion().isEmpty());
}
 
Example #13
Source File: JsonRpc2_0Web3j.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Override
public Request<?, NetVersion> netVersion() {
    return new Request<>(
            "net_version", Collections.<String>emptyList(), web3jService, NetVersion.class);
}
 
Example #14
Source File: CoreIT.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testNetVersion() throws Exception {
    NetVersion netVersion = web3j.netVersion().send();
    assertFalse(netVersion.getNetVersion().isEmpty());
}
 
Example #15
Source File: WebSocketServiceTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testBatchRequestReply() throws Exception {
    BatchRequest request = new BatchRequest(service);
    request.add(
                    new Request<>(
                            "web3_clientVersion",
                            Collections.<String>emptyList(),
                            service,
                            Web3ClientVersion.class))
            .add(
                    new Request<>(
                            "net_version",
                            Collections.<String>emptyList(),
                            service,
                            NetVersion.class));
    request.getRequests().get(0).setId(1L);
    request.getRequests().get(1).setId(1L);

    CompletableFuture<BatchResponse> reply = service.sendBatchAsync(request);

    verify(webSocketClient)
            .send(
                    "["
                            + "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":0},"
                            + "{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":1}"
                            + "]");

    sendClientNetVersionReply();

    assertTrue(reply.isDone());
    BatchResponse response = reply.get();
    assertEquals(response.getResponses().size(), 2);

    assertTrue(response.getResponses().get(0) instanceof Web3ClientVersion);
    Web3ClientVersion web3ClientVersion = (Web3ClientVersion) response.getResponses().get(0);
    assertEquals(web3ClientVersion.getWeb3ClientVersion(), "Mist/v0.9.3/darwin/go1.4.1");

    assertTrue(response.getResponses().get(1) instanceof NetVersion);
    NetVersion netVersion = (NetVersion) response.getResponses().get(1);
    assertEquals(netVersion.getNetVersion(), "59");
}
 
Example #16
Source File: Ethereum.java    From web3j with Apache License 2.0 votes vote down vote up
Request<?, NetVersion> netVersion(); 
Example #17
Source File: Ethereum.java    From etherscan-explorer with GNU General Public License v3.0 votes vote down vote up
Request<?, NetVersion> netVersion();