Search in sources :

Example 1 with Credentials

use of org.fisco.bcos.web3j.crypto.Credentials in project web3sdk by FISCO-BCOS.

the class SolidityFunctionWrapper method generateJavaFiles.

void generateJavaFiles(String contractName, String bin, String smBin, String abi, String destinationDir, String basePackageName, Map<String, String> addresses) throws IOException, ClassNotFoundException, UnsupportedOperationException {
    String className = Strings.capitaliseFirstLetter(contractName);
    logger.info("bin: {}", bin);
    logger.info("smBin: {}", smBin);
    if (bin.length() > maxSolidityBinSize) {
        throw new UnsupportedOperationException(" contract binary too long, max support is 256k, now is " + Integer.valueOf(bin.length()));
    }
    List<AbiDefinition> abiDefinitions = loadContractDefinition(abi);
    TypeSpec.Builder classBuilder = createClassBuilder(className, bin, smBin, abi);
    classBuilder.addMethod(buildBinaryMethod(smBin));
    classBuilder.addMethod(buildReturnTransactionDecoder());
    classBuilder.addMethod(buildConstructor(Credentials.class, CREDENTIALS, false));
    classBuilder.addMethod(buildConstructor(Credentials.class, CREDENTIALS, true));
    classBuilder.addMethod(buildConstructor(TransactionManager.class, TRANSACTION_MANAGER, false));
    classBuilder.addMethod(buildConstructor(TransactionManager.class, TRANSACTION_MANAGER, true));
    classBuilder.addFields(buildFuncNameConstants(abiDefinitions));
    classBuilder.addMethods(buildFunctionDefinitions(className, classBuilder, abiDefinitions));
    classBuilder.addMethod(buildLoad(className, Credentials.class, CREDENTIALS, false));
    classBuilder.addMethod(buildLoad(className, TransactionManager.class, TRANSACTION_MANAGER, false));
    classBuilder.addMethod(buildLoad(className, Credentials.class, CREDENTIALS, true));
    classBuilder.addMethod(buildLoad(className, TransactionManager.class, TRANSACTION_MANAGER, true));
    if (!bin.equals(Contract.BIN_NOT_PROVIDED)) {
        classBuilder.addMethods(buildDeployMethods(className, classBuilder, abiDefinitions));
    }
    write(basePackageName, classBuilder.build(), destinationDir);
}
Also used : AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) TransactionManager(org.fisco.bcos.web3j.tx.TransactionManager) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Credentials(org.fisco.bcos.web3j.crypto.Credentials) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 2 with Credentials

use of org.fisco.bcos.web3j.crypto.Credentials in project web3sdk by FISCO-BCOS.

the class GenCredential method create.

public static Credentials create(String privKey) {
    try {
        ECKeyPair keyPair = createKeyPair(privKey);
        if (keyPair == null)
            return null;
        Credentials credentials = Credentials.create(keyPair);
        return credentials;
    } catch (Exception e) {
        System.out.println("init credential from private key failed ");
        logger.error("init credential from private key failed, error msg:" + e.getMessage());
        return null;
    }
}
Also used : ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Example 3 with Credentials

use of org.fisco.bcos.web3j.crypto.Credentials in project web3sdk by FISCO-BCOS.

the class PerfomanceTableModify method main.

public static void main(String[] args) throws Exception {
    try {
        String groupId = args[3];
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Service service = context.getBean(Service.class);
        service.setGroupId(Integer.parseInt(groupId));
        service.run();
        System.out.println("Start test...");
        System.out.println("===================================================================");
        ChannelEthereumService channelEthereumService = new ChannelEthereumService();
        channelEthereumService.setChannelService(service);
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
        Web3j web3 = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId));
        Credentials credentials = Credentials.create("b83261efa42895c38c6c2364ca878f43e77f3cddbc922bf57d0d48070f79feb6");
        BigInteger gasPrice = new BigInteger("30000000");
        BigInteger gasLimit = new BigInteger("30000000");
        String command = args[0];
        Integer count = 0;
        Integer qps = 0;
        switch(command) {
            case "trans":
                count = Integer.parseInt(args[1]);
                qps = Integer.parseInt(args[2]);
                break;
            default:
                System.out.println("Args: <trans> <Total> <QPS>");
        }
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(200);
        threadPool.setMaxPoolSize(500);
        threadPool.setQueueCapacity(count);
        threadPool.initialize();
        System.out.println("Deploying contract...");
        TableTest tabletest = TableTest.deploy(web3, credentials, gasPrice, gasLimit).send();
        PerfomanceCollector collector = new PerfomanceCollector();
        collector.setTotal(count);
        RateLimiter limiter = RateLimiter.create(qps);
        Integer area = count / 10;
        final Integer total = count;
        Random random = new Random(System.currentTimeMillis());
        System.out.println("Start test,total:" + count);
        for (Integer i = 0; i < count; ++i) {
            threadPool.execute(new Runnable() {

                @Override
                public void run() {
                    limiter.acquire();
                    PerfomanceTableTestCallback callback = new PerfomanceTableTestCallback();
                    callback.setCollector(collector);
                    try {
                        long _id = getNextID();
                        Random r = new Random();
                        long l1 = r.nextLong();
                        tabletest.update("fruit" + l1 % TableTestClient.modevalue, BigInteger.valueOf(_id), "apple" + getId(), callback);
                    } catch (Exception e) {
                        TransactionReceipt receipt = new TransactionReceipt();
                        receipt.setStatus("-1");
                        callback.onResponse(receipt);
                        logger.error("Error sending:", e);
                    }
                    int current = sended.incrementAndGet();
                    if (current >= area && ((current % area) == 0)) {
                        System.out.println("Already sended: " + current + "/" + total + " transactions");
                    }
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.fisco.bcos.channel.client.Service) 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) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) Random(java.util.Random) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Example 4 with Credentials

use of org.fisco.bcos.web3j.crypto.Credentials in project web3sdk by FISCO-BCOS.

the class PerformanceOk method main.

public static void main(String[] args) throws Exception {
    try {
        String groupId = args[3];
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Service service = context.getBean(Service.class);
        service.setGroupId(Integer.parseInt(groupId));
        service.run();
        System.out.println("Start test...");
        System.out.println("===================================================================");
        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 = Credentials.create("b83261efa42895c38c6c2364ca878f43e77f3cddbc922bf57d0d48070f79feb6");
        BigInteger gasPrice = new BigInteger("30000000");
        BigInteger gasLimit = new BigInteger("30000000");
        String command = args[0];
        Integer count = 0;
        Integer qps = 0;
        switch(command) {
            case "trans":
                count = Integer.parseInt(args[1]);
                qps = Integer.parseInt(args[2]);
                break;
            default:
                System.out.println("Args: <trans> <Total> <QPS>");
        }
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(200);
        threadPool.setMaxPoolSize(500);
        threadPool.setQueueCapacity(count);
        threadPool.initialize();
        System.out.println("Deploying contract...");
        Ok ok = Ok.deploy(web3, credentials, gasPrice, gasLimit).send();
        PerformanceCollector collector = new PerformanceCollector();
        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();
                    PerformanceOkCallback callback = new PerformanceOkCallback();
                    callback.setCollector(collector);
                    try {
                        ok.trans(new BigInteger("4"), callback);
                    } catch (Exception e) {
                        TransactionReceipt receipt = new TransactionReceipt();
                        receipt.setStatus("-1");
                        callback.onResponse(receipt);
                        logger.info(e.getMessage());
                    }
                    int current = sended.incrementAndGet();
                    if (current >= area && ((current % area) == 0)) {
                        System.out.println("Already sended: " + current + "/" + total + " transactions");
                    }
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
        ;
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.fisco.bcos.channel.client.Service) 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) 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) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Example 5 with Credentials

use of org.fisco.bcos.web3j.crypto.Credentials in project web3sdk by FISCO-BCOS.

the class PerfomanceTableInsert method main.

public static void main(String[] args) throws Exception {
    try {
        String groupId = args[3];
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Service service = context.getBean(Service.class);
        service.setGroupId(Integer.parseInt(groupId));
        service.run();
        System.out.println("Start test...");
        System.out.println("===================================================================");
        ChannelEthereumService channelEthereumService = new ChannelEthereumService();
        channelEthereumService.setChannelService(service);
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
        Web3j web3 = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId));
        Credentials credentials = Credentials.create("b83261efa42895c38c6c2364ca878f43e77f3cddbc922bf57d0d48070f79feb6");
        BigInteger gasPrice = new BigInteger("30000000");
        BigInteger gasLimit = new BigInteger("30000000");
        String command = args[0];
        Integer count = 0;
        Integer qps = 0;
        switch(command) {
            case "trans":
                count = Integer.parseInt(args[1]);
                qps = Integer.parseInt(args[2]);
                break;
            default:
                System.out.println("Args: <trans> <Total> <QPS>");
        }
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(200);
        threadPool.setMaxPoolSize(500);
        threadPool.setQueueCapacity(count);
        threadPool.initialize();
        System.out.println("Deploying contract...");
        TableTest tabletest = TableTest.deploy(web3, credentials, gasPrice, gasLimit).send();
        PerfomanceCollector collector = new PerfomanceCollector();
        collector.setTotal(count);
        RateLimiter limiter = RateLimiter.create(qps);
        Integer area = count / 10;
        final Integer total = count;
        Random random = new Random(System.currentTimeMillis());
        System.out.println("Start test,total:" + count);
        for (Integer i = 0; i < count; ++i) {
            threadPool.execute(new Runnable() {

                @Override
                public void run() {
                    limiter.acquire();
                    PerfomanceTableTestCallback callback = new PerfomanceTableTestCallback();
                    callback.setCollector(collector);
                    try {
                        long _id = getNextID();
                        tabletest.insert("fruit" + _id % TableTestClient.modevalue, BigInteger.valueOf(_id), "apple" + getId(), callback);
                    } catch (Exception e) {
                        TransactionReceipt receipt = new TransactionReceipt();
                        receipt.setStatus("-1");
                        callback.onResponse(receipt);
                        logger.error("Error sending:", e);
                    }
                    int current = sended.incrementAndGet();
                    if (current >= area && ((current % area) == 0)) {
                        System.out.println("Already sended: " + current + "/" + total + " transactions");
                    }
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.fisco.bcos.channel.client.Service) 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) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) Random(java.util.Random) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Aggregations

Credentials (org.fisco.bcos.web3j.crypto.Credentials)20 BigInteger (java.math.BigInteger)14 ApplicationContext (org.springframework.context.ApplicationContext)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 Service (org.fisco.bcos.channel.client.Service)12 Web3j (org.fisco.bcos.web3j.protocol.Web3j)12 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)12 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)10 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)9 RateLimiter (com.google.common.util.concurrent.RateLimiter)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Random (java.util.Random)7 ECKeyPair (org.fisco.bcos.web3j.crypto.ECKeyPair)6 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)2 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)2 TransactionManager (org.fisco.bcos.web3j.tx.TransactionManager)2 ContractGasProvider (org.fisco.bcos.web3j.tx.gas.ContractGasProvider)2