org.fisco.bcos.web3j.protocol.core.methods.response.NodeVersion Java Examples

The following examples show how to use org.fisco.bcos.web3j.protocol.core.methods.response.NodeVersion. 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: Web3Config.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
/**
 * init Web3j of default group id 1
 */
@Bean
public Web3j getWeb3j(GroupChannelConnectionsConfig groupChannelConnectionsConfig)
        throws Exception {
    Service service = new Service();
    service.setOrgID(orgName);
    service.setGroupId(independentGroupId);
    service.setThreadPool(sdkThreadPool());
    service.setAllChannelConnections(groupChannelConnectionsConfig);
    service.run();
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setTimeout(timeout);
    channelEthereumService.setChannelService(service);
    Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());
    // init node version
    NodeVersion version = web3j.getNodeVersion().send();
    Constants.version = version.getNodeVersion().getVersion();
    Constants.chainId = version.getNodeVersion().getChainID();
    log.info("Chain's clientVersion:{}", Constants.version);
    return web3j;
}
 
Example #2
Source File: FrontInterfaceService.java    From WeBASE-Node-Manager with Apache License 2.0 5 votes vote down vote up
public String getClientVersion(String frontIp, Integer frontPort,
                               Integer groupId) {
    log.debug("start getClientVersion. groupId:{}", groupId);
    NodeVersion.Version clientVersion = getFromSpecificFront(groupId, frontIp, frontPort, FrontRestTools.URI_GET_CLIENT_VERSION, NodeVersion.Version.class);
    log.debug("end getClientVersion. consensusStatus:{}", clientVersion);
    return clientVersion.getVersion();
}
 
Example #3
Source File: Web3SDKConnector.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public static Web3j initWeb3j(Service service) throws BrokerException {
    // init web3j with given group id
    try {
        log.info("begin to initialize web3sdk's Web3j, group id: {}", service.getGroupId());
        StopWatch sw = StopWatch.createStarted();

        // special thread for TransactionSucCallback.onResponse, callback from IO thread directly if not setting
        //service.setThreadPool(poolTaskExecutor);
        service.run();

        ChannelEthereumService channelEthereumService = new ChannelEthereumService();
        channelEthereumService.setChannelService(service);
        channelEthereumService.setTimeout(service.getConnectSeconds() * 1000);
        Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());

        // check connect with getNodeVersion command
        NodeVersion.Version version = web3j.getNodeVersion().send().getNodeVersion();
        String nodeVersion = version.getVersion();
        if (StringUtils.isBlank(nodeVersion)
                || !nodeVersion.contains(FISCO_BCOS_2_X_VERSION_PREFIX)) {
            log.error("init web3sdk failed, mismatch FISCO-BCOS version in node: {}", nodeVersion);
            throw new BrokerException(ErrorCode.WEB3SDK_INIT_ERROR);
        }
        chainID = version.getChainID();

        sw.stop();
        log.info("initialize web3sdk success, group id: {} cost: {} ms", service.getGroupId(), sw.getTime());
        return web3j;
    } catch (Exception e) {
        log.error("init web3sdk failed", e);
        throw new BrokerException(ErrorCode.WEB3SDK_INIT_ERROR);
    }
}
 
Example #4
Source File: Contract.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public static TransactionManager getTheTransactionManager(
        Web3j web3j, Credentials credentials) {
    JsonRpc2_0Web3j jsonRpc2_0Web3j = (JsonRpc2_0Web3j) web3j;
    String chainId = "1";
    int groupId = 1;
    String version = "";
    String supportedVersion = "";
    NodeVersion.Version nodeVersion = null;
    try {
        groupId = jsonRpc2_0Web3j.getGroupId();
        nodeVersion = web3j.getNodeVersion().send().getNodeVersion();
        version = nodeVersion.getVersion();
        supportedVersion = nodeVersion.getSupportedVersion();

        if (EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(version)
                || EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(supportedVersion)) {
            version = EnumNodeVersion.BCOS_2_0_0_RC1.getVersion();
            logger.debug("fisco-bcos version:{}", version);
        } else {
            chainId = nodeVersion.getChainID();
            logger.debug(
                    "fisco-bcos version:{}, supported version:{}", version, supportedVersion);
        }
    } catch (Exception e) {
        logger.error("Query fisco-bcos version failed", e);
    }

    TransactionManager transactionManager =
            EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(version)
                    ? new RawTransactionManager(web3j, credentials)
                    : new ExtendedRawTransactionManager(
                            web3j,
                            credentials,
                            BigInteger.valueOf(groupId),
                            new BigInteger(chainId));

    transactionManager.setNodeVersion(nodeVersion);

    return transactionManager;
}
 
Example #5
Source File: Web3jApITest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void getNodeVersion() throws IOException {
    NodeVersion nodeVersion = web3j.getNodeVersion().send();
    assertNotNull(nodeVersion.getNodeVersion().getBuildTime());
    assertNotNull(nodeVersion.getNodeVersion().getBuildType());
    assertNotNull(nodeVersion.getNodeVersion().getGitBranch());
    assertNotNull(nodeVersion.getNodeVersion().getGitCommit());
    assertNotNull(nodeVersion.getNodeVersion().getVersion());
}
 
Example #6
Source File: TransactionManager.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public NodeVersion.Version getNodeVersion() {
    return nodeVersion;
}
 
Example #7
Source File: TransactionManager.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public void setNodeVersion(NodeVersion.Version nodeVersion) {
    this.nodeVersion = nodeVersion;
}
 
Example #8
Source File: JsonRpc2_0Web3j.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Override
public Request<?, NodeVersion> getNodeVersion() {
    return new Request<>("getClientVersion", Arrays.asList(), web3jService, NodeVersion.class);
}
 
Example #9
Source File: Ethereum.java    From web3sdk with Apache License 2.0 votes vote down vote up
Request<?, NodeVersion> getNodeVersion();