Search in sources :

Example 21 with ChannelEthereumService

use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.

the class MixContractClient method main.

public static void main(String[] args) throws Exception {
    // init the Service
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.setGroupId(Integer.parseInt(args[0]));
    // run the daemon service
    service.run();
    // init the client keys
    keyPair = Keys.createEcKeyPair();
    credentials = Credentials.create(keyPair);
    logger.info("-----> start test !");
    logger.info("init AOMP ChannelEthereumService");
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    try {
        web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0]));
    } catch (Exception e) {
        System.out.println("\nPlease provide groupID in the first paramters");
        System.exit(0);
    }
    if (args.length > 1) {
        if ("deploy".equals(args[1])) {
            deploymixContract();
        } else {
            String[] params = new String[args.length - 1];
            for (int i = 0; i < params.length; i++) params[i] = args[i + 1];
            testMixContract(params);
        }
    } else {
        System.out.println("\nPlease choose follow commands:\n deploy, create, insert, select, update or remove");
    }
    System.exit(0);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException)

Example 22 with ChannelEthereumService

use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.

the class TestTxDecode method sentTx.

public static TransactionReceipt sentTx() throws Exception {
    // init the Service
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    ECKeyPair keyPair = Keys.createEcKeyPair();
    Credentials credentials = Credentials.create(keyPair);
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    service.setGroupId(1);
    Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());
    RemoteCall<TableTest> deploy = TableTest.deploy(web3j, credentials, new StaticGasProvider(new BigInteger("30000000"), new BigInteger("30000000")));
    TableTest tableTest = deploy.send();
    tableTest.create().send();
    String name = "fruit";
    int item_id = 1;
    String item_name = "apple";
    RemoteCall<TransactionReceipt> insert = tableTest.insert(name, BigInteger.valueOf(item_id), item_name);
    TransactionReceipt txReceipt = insert.send();
    return txReceipt;
}
Also used : StaticGasProvider(org.fisco.bcos.web3j.tx.gas.StaticGasProvider) ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Example 23 with ChannelEthereumService

use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.

the class PerformanceDTTest method initialize.

public void initialize(String groupId) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.setGroupId(Integer.parseInt(groupId));
    service.run();
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    Web3AsyncThreadPoolSize.web3AsyncCorePoolSize = 3000;
    Web3AsyncThreadPoolSize.web3AsyncPoolSize = 2000;
    ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
    Web3j web3 = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId));
    Credentials credentials = GenCredential.create();
    dagTransfer = DagTransfer.load(dagTransferAddr, web3, credentials, new StaticGasProvider(new BigInteger("30000000"), new BigInteger("30000000")));
    transactionManager = Contract.getTheTransactionManager(web3, credentials);
}
Also used : StaticGasProvider(org.fisco.bcos.web3j.tx.gas.StaticGasProvider) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) BigInteger(java.math.BigInteger) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Example 24 with ChannelEthereumService

use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.

the class PerformanceRPC method main.

public static void main(String[] args) throws Exception {
    try {
        if (args.length < 3) {
            Usage();
        }
        int groupId = Integer.valueOf(args[0]);
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Service service = context.getBean(Service.class);
        service.setGroupId(groupId);
        service.run();
        System.out.println("Start test...");
        System.out.println("===================================================================");
        ChannelEthereumService channelEthereumService = new ChannelEthereumService();
        channelEthereumService.setChannelService(service);
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
        Web3j web3j = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, groupId);
        Integer count = Integer.parseInt(args[1]);
        Integer qps = Integer.parseInt(args[2]);
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(200);
        threadPool.setMaxPoolSize(500);
        threadPool.setQueueCapacity(count);
        threadPool.initialize();
        PerformanceRpcCollector collector = new PerformanceRpcCollector();
        collector.setTotal(count);
        RateLimiter limiter = RateLimiter.create(qps);
        Integer area = count / 10;
        final Integer total = count;
        System.out.println("Start test,total:" + count);
        for (Integer i = 0; i < count; ++i) {
            threadPool.execute(new Runnable() {

                @Override
                public void run() {
                    limiter.acquire();
                    Response response = new Response();
                    try {
                        int random = new SecureRandom().nextInt(50000);
                        int methodNum = 10;
                        Long startTime = System.nanoTime();
                        switch(random % methodNum) {
                            // 1. call getPendingTxSize
                            case 0:
                                response = web3j.getPendingTxSize().send();
                                break;
                            // 2. call getBlockNumber
                            case 1:
                                response = web3j.getBlockNumber().send();
                                break;
                            // 3. call getSyncStatus
                            case 2:
                                response = web3j.getSyncStatus().send();
                                break;
                            // 5. call getSealerList
                            case 4:
                                response = web3j.getSealerList().send();
                                break;
                            // 6. call getTotalTransactionCount
                            case 5:
                                response = web3j.getTotalTransactionCount().send();
                                break;
                            // 7. call getObserverList
                            case 6:
                                response = web3j.getObserverList().send();
                                break;
                            // 8. call getBlockHashByNumber
                            case 7:
                                BigInteger blockNumber = web3j.getBlockNumber().send().getBlockNumber();
                                DefaultBlockParameter blockParam = DefaultBlockParameter.valueOf(blockNumber);
                                response = web3j.getBlockHashByNumber(blockParam).send();
                                break;
                            // 9. call getSystemConfigByKey
                            case 8:
                                response = web3j.getSystemConfigByKey("tx_count_limit").send();
                                break;
                            // 10. call getPbftView
                            case 9:
                                response = web3j.getPbftView().send();
                                break;
                            default:
                                // default call getPbftView
                                response = web3j.getPbftView().send();
                        }
                        Long cost = System.nanoTime() - startTime;
                        collector.onMessage(response, cost);
                    } catch (Exception e) {
                        logger.error("test rpc interface failed, error info: {}", e.getMessage());
                        Error error = new Error();
                        error.setCode(1);
                        response.setError(error);
                        collector.onMessage(response, 0L);
                    }
                    int current = sended.incrementAndGet();
                    if (current >= area && ((current % area) == 0)) {
                        System.out.println("Already sended: " + current + "/" + total + " RPC Requests");
                    }
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.fisco.bcos.channel.client.Service) SecureRandom(java.security.SecureRandom) Error(org.fisco.bcos.web3j.protocol.core.Response.Error) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) RateLimiter(com.google.common.util.concurrent.RateLimiter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Response(org.fisco.bcos.web3j.protocol.core.Response) DefaultBlockParameter(org.fisco.bcos.web3j.protocol.core.DefaultBlockParameter) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 25 with ChannelEthereumService

use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService 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

ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)27 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)25 ApplicationContext (org.springframework.context.ApplicationContext)24 Service (org.fisco.bcos.channel.client.Service)23 Web3j (org.fisco.bcos.web3j.protocol.Web3j)17 BigInteger (java.math.BigInteger)15 Credentials (org.fisco.bcos.web3j.crypto.Credentials)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)10 RateLimiter (com.google.common.util.concurrent.RateLimiter)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)9 Random (java.util.Random)6 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)5 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)4 SecureRandom (java.security.SecureRandom)2 ECKeyPair (org.fisco.bcos.web3j.crypto.ECKeyPair)2 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)2 DefaultBlockParameter (org.fisco.bcos.web3j.protocol.core.DefaultBlockParameter)2 ContractGasProvider (org.fisco.bcos.web3j.tx.gas.ContractGasProvider)2