Search in sources :

Example 1 with JsonRpc2_0Web3j

use of org.fisco.bcos.web3j.protocol.core.JsonRpc2_0Web3j in project web3sdk by FISCO-BCOS.

the class Contract method getTheTransactionManager.

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;
}
Also used : EnumNodeVersion(org.fisco.bcos.fisco.EnumNodeVersion) NodeVersion(org.fisco.bcos.web3j.protocol.core.methods.response.NodeVersion) BigInteger(java.math.BigInteger) JsonRpc2_0Web3j(org.fisco.bcos.web3j.protocol.core.JsonRpc2_0Web3j) ContractCallException(org.fisco.bcos.web3j.tx.exceptions.ContractCallException) IOException(java.io.IOException) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException)

Example 2 with JsonRpc2_0Web3j

use of org.fisco.bcos.web3j.protocol.core.JsonRpc2_0Web3j in project web3sdk by FISCO-BCOS.

the class Contract method registerEventLogPushFilter.

public void registerEventLogPushFilter(TransactionDecoder decoder, EventLogUserParams params, EventLogPushWithDecodeCallback callback) {
    Web3jService service = ((JsonRpc2_0Web3j) web3j).web3jService();
    ChannelEthereumService channelEthereumService = (ChannelEthereumService) service;
    // set timeout
    // filter.setTimeout(channelEthereumService.getTimeout());
    callback.setDecoder(decoder);
    channelEthereumService.getChannelService().registerEventLogFilter(params, callback);
}
Also used : Web3jService(org.fisco.bcos.web3j.protocol.Web3jService) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) JsonRpc2_0Web3j(org.fisco.bcos.web3j.protocol.core.JsonRpc2_0Web3j)

Aggregations

JsonRpc2_0Web3j (org.fisco.bcos.web3j.protocol.core.JsonRpc2_0Web3j)2 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 EnumNodeVersion (org.fisco.bcos.fisco.EnumNodeVersion)1 Web3jService (org.fisco.bcos.web3j.protocol.Web3jService)1 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)1 NodeVersion (org.fisco.bcos.web3j.protocol.core.methods.response.NodeVersion)1 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)1 ContractCallException (org.fisco.bcos.web3j.tx.exceptions.ContractCallException)1