Java源码示例:org.web3j.protocol.core.methods.response.NetVersion
示例1
@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);
}
}
示例2
@Override
public Request<?, NetVersion> netVersion() {
return new Request<>(
"net_version",
Collections.<String>emptyList(),
web3jService,
NetVersion.class);
}
示例3
@Override
public Request<?, NetVersion> netVersion() {
return new Request<>(
"net_version",
Collections.<String>emptyList(),
web3jService,
NetVersion.class);
}
示例4
@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"));
}
示例5
@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"));
}
示例6
@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"));
}
示例7
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);
}
示例8
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());
}
示例9
@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"));
}
示例10
@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"));
}
示例11
@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"));
}
示例12
@Test
public void testNetVersion() throws Exception {
NetVersion netVersion = web3j.netVersion().send();
assertFalse(netVersion.getNetVersion().isEmpty());
}
示例13
@Test
public void testNetVersion() throws Exception {
NetVersion netVersion = web3j.netVersion().send();
assertFalse(netVersion.getNetVersion().isEmpty());
}
示例14
@Override
public Request<?, NetVersion> netVersion() {
return new Request<>(
"net_version", Collections.<String>emptyList(), web3jService, NetVersion.class);
}
示例15
@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");
}
示例16
Request<?, NetVersion> netVersion();
示例17
Request<?, NetVersion> netVersion();