Search in sources :

Example 21 with Service

use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.

the class GMOkTransaction method main.

public static void main(String[] args) throws Exception {
    EncryptType encryptType = new EncryptType(1);
    String groupId = "1";
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    System.out.println("===================================================================");
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    channelEthereumService.setTimeout(10000);
    Web3j web3 = Web3j.build(channelEthereumService, Integer.parseInt(groupId));
    BigInteger gasPrice = new BigInteger("300000000");
    BigInteger gasLimit = new BigInteger("3000000000");
    Credentials credentials1 = GenCredential.create("a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6");
    ContractGasProvider contractGasProvider = new StaticGasProvider(gasPrice, gasLimit);
    final Ok okDemo = Ok.deploy(web3, credentials1, contractGasProvider).send();
    for (int i = 0; i < 1; i++) {
        System.out.println("####contract address is: " + okDemo.getContractAddress());
        TransactionReceipt receipt = okDemo.trans(new BigInteger("4")).send();
        System.out.println(" balance = " + okDemo.get().send().intValue());
    }
    System.exit(0);
}
Also used : StaticGasProvider(org.fisco.bcos.web3j.tx.gas.StaticGasProvider) 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) ContractGasProvider(org.fisco.bcos.web3j.tx.gas.ContractGasProvider) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) EncryptType(org.fisco.bcos.web3j.crypto.EncryptType) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Example 22 with Service

use of org.fisco.bcos.channel.client.Service 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 23 with Service

use of org.fisco.bcos.channel.client.Service 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 24 with Service

use of org.fisco.bcos.channel.client.Service 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 25 with Service

use of org.fisco.bcos.channel.client.Service 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)

Aggregations

Service (org.fisco.bcos.channel.client.Service)34 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)34 ApplicationContext (org.springframework.context.ApplicationContext)33 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)23 Web3j (org.fisco.bcos.web3j.protocol.Web3j)17 BigInteger (java.math.BigInteger)13 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 DateTimeFormatter (java.time.format.DateTimeFormatter)8 ChannelRequest (org.fisco.bcos.channel.dto.ChannelRequest)8 Random (java.util.Random)6 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)5 ChannelResponse (org.fisco.bcos.channel.dto.ChannelResponse)4 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)4 SecureRandom (java.security.SecureRandom)2 HashSet (java.util.HashSet)2