Java Code Examples for org.fisco.bcos.channel.client.Service

The following examples show how to use org.fisco.bcos.channel.client.Service. These examples are extracted from open source projects. 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 Project: WeBASE-Front   Source File: Web3Config.java    License: 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 Project: WeBASE-Front   Source File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // 获取spring配置文件,生成上下文
  context = new ClassPathXmlApplicationContext("applicationContext.xml");
  //   ((ClassPathXmlApplicationContext) context).start();

  Service service = context.getBean(Service.class);
  service.run();

  System.out.println("start...");
  System.out.println("===================================================================");

  ChannelEthereumService channelEthereumService = new ChannelEthereumService();
  channelEthereumService.setChannelService(service);

  web3j = Web3j.build(channelEthereumService, service.getGroupId());
  // EthBlockNumber ethBlockNumber = web3.ethBlockNumber().send();

  Ok ok = Ok.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit)).send();
  address = ok.getContractAddress();
  blockNumber = ok.getTransactionReceipt().get().getBlockNumber();
  blockHash = ok.getTransactionReceipt().get().getBlockHash();
  txHash = ok.getTransactionReceipt().get().getTransactionHash();
}
 
Example 3
Source Project: WeBASE-Front   Source File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // 获取spring配置文件,生成上下文
  context = new ClassPathXmlApplicationContext("applicationContext.xml");
  //   ((ClassPathXmlApplicationContext) context).start();

  Service service = context.getBean(Service.class);
  service.run();

  System.out.println("start...");
  System.out.println("===================================================================");

  ChannelEthereumService channelEthereumService = new ChannelEthereumService();
  channelEthereumService.setChannelService(service);

  web3j = Web3j.build(channelEthereumService, service.getGroupId());
  // EthBlockNumber ethBlockNumber = web3.ethBlockNumber().send();

}
 
Example 4
Source Project: WeBASE-Front   Source File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // 获取spring配置文件,生成上下文
  context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
  //   ((ClassPathXmlApplicationContext) context).start();

  Service service = context.getBean(Service.class);
  service.run();

  System.out.println("start...");
  System.out.println("===================================================================");

  ChannelEthereumService channelEthereumService = new ChannelEthereumService();
  channelEthereumService.setChannelService(service);
  channelEthereumService.setTimeout(10000);
  web3j = Web3j.build(channelEthereumService, service.getGroupId());
  // EthBlockNumber ethBlockNumber = web3.ethBlockNumber().send();

}
 
Example 5
Source Project: WeBASE-Front   Source File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // 获取spring配置文件,生成上下文
    context = new ClassPathXmlApplicationContext("applicationContext.xml");
    //   ((ClassPathXmlApplicationContext) context).start();

    Service service = context.getBean(Service.class);
    service.run();

    System.out.println("start...");
    System.out.println("===================================================================");

    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);

    web3j = Web3j.build(channelEthereumService, service.getGroupId());
    // EthBlockNumber ethBlockNumber = web3.ethBlockNumber().send();
//
//    Ok ok = Ok.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit)).send();
//    address = ok.getContractAddress();
//    blockNumber = ok.getTransactionReceipt().get().getBlockNumber();
//    blockHash = ok.getTransactionReceipt().get().getBlockHash();
//    txHash = ok.getTransactionReceipt().get().getTransactionHash();
  }
 
Example 6
public boolean loadConfig() throws Exception {
    System.out.println("please wait ...");
    Service service;
    try {
        context = new ClassPathXmlApplicationContext("classpath:node/application.xml");
        service = context.getBean(Service.class);
        service.run();
    } catch (Exception e) {
        logger.error("load config failed, error msg: " + e.getMessage());
        throw new Exception("load config failed, error msg: " + e.getMessage());
    }

    credentials = GenCredential.create();

    // channel eth service
    ChannelEthereumService channelService = new ChannelEthereumService();
    channelService.setChannelService(service);
    channelService.setTimeout(5000);
    web3j = Web3j.build(channelService, service.getGroupId());
    return true;
}
 
Example 7
Source Project: web3sdk   Source File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {

	context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

  Service service = context.getBean(Service.class);
  service.run();

  ChannelEthereumService channelEthereumService = new ChannelEthereumService();
  channelEthereumService.setChannelService(service);

  System.out.println("EncryptType =>  " + EncryptType.getEncryptType());

  web3j = Web3j.build(channelEthereumService, service.getGroupId());
  credentials = GenCredential.create();
  Ok ok = Ok.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit)).send();
  blockNumber = ok.getTransactionReceipt().get().getBlockNumber();
  blockHash = ok.getTransactionReceipt().get().getBlockHash();
  txHash = ok.getTransactionReceipt().get().getTransactionHash();
}
 
Example 8
Source Project: web3sdk   Source File: PerformanceDTTest.java    License: Apache License 2.0 6 votes vote down vote up
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);

    web3 =
            Web3j.build(
                    channelEthereumService,
                    15 * 100,
                    scheduledExecutorService,
                    Integer.parseInt(groupId));
    credentials = GenCredential.create();
    transactionManager = Contract.getTheTransactionManager(web3, credentials);
}
 
Example 9
Source Project: WeBASE-Front   Source File: EventRegisterInitTask.java    License: Apache License 2.0 5 votes vote down vote up
private void registerContractEvent(ContractEventInfo rInfo) {
	log.debug("start registerContractEvent infoId:{}", rInfo.getId());
	List<String> topicList = FrontUtils.string2ListStr(rInfo.getTopicList());
	String exchangeName = rInfo.getExchangeName();
	String queueName = rInfo.getQueueName();
	String appId = rInfo.getAppId();
	int groupId = rInfo.getGroupId();
	String eventRoutingKey = rInfo.getRoutingKey();
	String contractAddress = rInfo.getContractAddress();
	String abi = rInfo.getContractAbi();
	String fromBlock = rInfo.getFromBlock();
	String toBlock = rInfo.getToBlock();
	// 传入abi作decoder:
	TransactionDecoder decoder = new TransactionDecoder(abi);
	// init EventLogUserParams for register
	EventLogUserParams params = RabbitMQUtils.initSingleEventLogUserParams(
			fromBlock, toBlock, contractAddress, topicList);
	// bind queue to exchange by routing key "queueName_event"
	mqService.bindQueue2Exchange(exchangeName, queueName, eventRoutingKey);
	ContractEventCallback callBack =
			new ContractEventCallback(mqPublisher, exchangeName,
					eventRoutingKey, decoder, groupId, appId);
	org.fisco.bcos.channel.client.Service service = serviceMap.get(groupId);
	service.registerEventLogFilter(params, callBack);
	callBack.setRunning(true);
	CONTRACT_EVENT_CALLBACK_MAP.put(rInfo.getId(), callBack);
	log.debug("end registerContractEvent successful infoId:{}", rInfo.getId());
}
 
Example 10
Source Project: WeBASE-Collect-Bee   Source File: Web3jV2BeanConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Web3j getWeb3j() throws Exception {
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    Service service = getService();
    service.run();
    channelEthereumService.setChannelService(service);
    // default sync transactions timeout: 30s
    channelEthereumService.setTimeout(30000);
    return Web3j.build(channelEthereumService, service.getGroupId());
}
 
Example 11
Source Project: WeBASE-Collect-Bee   Source File: Web3jV2BeanConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Service getService() {
    GroupChannelConnectionsConfig groupChannelConnectionsConfig = getGroupChannelConnections();
    Service channelService = new Service();
    channelService.setGroupId(systemEnvironmentConfig.getGroupId());
    channelService.setAllChannelConnections(groupChannelConnectionsConfig);
    // set some default connect timeout seconds
    channelService.setConnectSeconds(20);
    channelService.setConnectSleepPerMillis(10);
    return channelService;
}
 
Example 12
Source Project: WeEvent   Source File: Web3SDKConnector.java    License: 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 13
Source Project: WeEvent   Source File: Web3SDKConnector.java    License: Apache License 2.0 5 votes vote down vote up
public static Service initService(Long groupId, FiscoConfig fiscoConfig) throws BrokerException {
    log.info("begin to initialize web3sdk's Service, group id: {}", groupId);

    try {
        int web3sdkTimeout = fiscoConfig.getWeb3sdkTimeout();

        Service service = new Service();
        // change jdk.tls.namedGroups will cause https's bug: ERR_SSL_VERSION_OR_CIPHER_MISMATCH
        service.setSetJavaOpt(false);
        // group info
        service.setOrgID(fiscoConfig.getOrgId());
        service.setGroupId(groupId.intValue());
        service.setConnectSeconds(web3sdkTimeout / 1000);
        // reconnect idle time 100ms
        service.setConnectSleepPerMillis(100);

        // connect key and string
        GroupChannelConnectionsConfig connectionsConfig = new GroupChannelConnectionsConfig();
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        connectionsConfig.setCaCert(resolver.getResource("classpath:" + fiscoConfig.getCaCrtPath()));
        connectionsConfig.setSslCert(resolver.getResource("classpath:" + fiscoConfig.getSdkCrtPath()));
        connectionsConfig.setSslKey(resolver.getResource("classpath:" + fiscoConfig.getSdkKeyPath()));

        ChannelConnections channelConnections = new ChannelConnections();
        channelConnections.setGroupId(groupId.intValue());
        channelConnections.setConnectionsStr(Arrays.asList(fiscoConfig.getNodes().split(";")));
        connectionsConfig.setAllChannelConnections(Collections.singletonList(channelConnections));

        service.setAllChannelConnections(connectionsConfig);
        return service;
    } catch (Exception e) {
        log.error("init web3sdk's Service failed", e);
        throw new BrokerException(ErrorCode.WEB3SDK_INIT_SERVICE_ERROR);
    }
}
 
Example 14
Source Project: amdb-proxy   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	logger.debug("Run AMDB Server");
	
	context = new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml" });
	Service service = context.getBean("DBChannelService", Service.class);
	
	try {
		service.run();
	} catch (Exception e) {
	    logger.debug("errmsg:",e);
	}
}
 
Example 15
Source Project: web3sdk   Source File: Channel2Server.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Param: topic");
        return;
    }
    String topic = args[0];
    logger.debug("init Server");
    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    Set<String> topics = new HashSet<String>();
    topics.add(topic);
    service.setTopics(topics);
    PushCallback cb = new PushCallback();
    service.setPushCallback(cb);
    System.out.println("3s...");
    Thread.sleep(1000);
    System.out.println("2s...");
    Thread.sleep(1000);
    System.out.println("1s...");
    Thread.sleep(1000);

    System.out.println("start test");
    System.out.println("===================================================================");

    service.run();
}
 
Example 16
Source Project: web3sdk   Source File: Channel2ServerUpdateTopics.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Param: topic");
        return;
    }
    String topic = args[0];
    logger.debug("init Server");
    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    PushCallback cb = new PushCallback();
    service.setPushCallback(cb);
    System.out.println("3s...");
    Thread.sleep(1000);
    System.out.println("2s...");
    Thread.sleep(1000);
    System.out.println("1s...");
    Thread.sleep(1000);

    System.out.println("start test");
    System.out.println("===================================================================");
    service.run();

    Thread.sleep(10000);

    System.out.println("set topics");
    System.out.println("===================================================================");
    Set<String> topics = new HashSet<String>();
    topics.add(topic);
    service.setTopics(topics);
    service.updateTopicsToNode();
}
 
Example 17
Source Project: web3sdk   Source File: Channel2ServerNeedVerify.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Param: topic");
        return;
    }
    String topic = args[0];
    logger.debug("init Server");
    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

    Service service = context.getBean(Service.class);
    service.setNeedVerifyTopics(topic);

    PushCallback cb = new PushCallback();
    service.setPushCallback(cb);
    System.out.println("3s...");
    Thread.sleep(1000);
    System.out.println("2s...");
    Thread.sleep(1000);
    System.out.println("1s...");
    Thread.sleep(1000);

    System.out.println("start test");
    System.out.println("===================================================================");

    service.run();
}
 
Example 18
Source Project: web3sdk   Source File: StartGroup.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        Usage();
    }

    int groupID = Integer.valueOf(args[0]);

    System.out.println(" Start Group operation, groupID: " + groupID);

    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.setGroupId(1);
    service.run();

    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);

    Web3j web3j = Web3j.build(channelEthereumService, 1);

    org.fisco.bcos.web3j.protocol.core.methods.response.StartGroup startGroup =
            web3j.startGroup(groupID).send();
    logger.info("  StartGroup result: {}", startGroup);

    System.out.println(" StartGroup result: " + startGroup.getStatus());

    System.exit(0);
}
 
Example 19
Source Project: web3sdk   Source File: GenerateGroup.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        Usage();
    }

    int groupID = Integer.valueOf(args[0]);
    long timestamp = Long.valueOf(args[1]);
    List<String> nodes = new ArrayList<>();

    for (int i = 2; i < args.length; ++i) {
        nodes.add(args[i]);
    }

    System.out.println(
            " Generate Group operation, groupID: "
                    + groupID
                    + " ,timestamp: "
                    + timestamp
                    + " ,nodes: "
                    + nodes);

    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.setGroupId(1);
    service.run();

    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);

    Web3j web3j = Web3j.build(channelEthereumService, 1);

    org.fisco.bcos.web3j.protocol.core.methods.response.GenerateGroup generateGroup =
            web3j.generateGroup(groupID, timestamp, false, nodes).send();
    logger.info("  generateGroup result: {}", generateGroup);

    System.out.println(" generateGroup result: " + generateGroup.getStatus());

    System.exit(0);
}
 
Example 20
Source Project: web3sdk   Source File: GroupManager.java    License: Apache License 2.0 5 votes vote down vote up
public Web3j init() throws Exception {
    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();

    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);

    Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());
    return web3j;
}
 
Example 21
Source Project: web3sdk   Source File: PerformanceDTTest.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
 
Example 22
Source Project: web3sdk   Source File: TableTestClient.java    License: Apache License 2.0 5 votes vote down vote up
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]));
        service.run(); // run the daemon service
        // init the client keys
        keyPair = Keys.createEcKeyPair();
        credentials = GenCredential.create(keyPair.getPrivateKey().toString(16));

        logger.info("-----> start test !");
        logger.info("init AOMP ChannelEthereumService");
        ChannelEthereumService channelEthereumService = new ChannelEthereumService();
        channelEthereumService.setChannelService(service);
        channelEthereumService.setTimeout(5 * 1000);
        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])) {
                deployTableTest();
            } else {
                String[] params = new String[args.length - 1];
                for (int i = 0; i < params.length; i++) params[i] = args[i + 1];
                testTableTest(params);
            }
        } else {
            System.out.println(
                    "\nPlease choose follow commands:\n deploy, create, insert, select, update or remove");
        }
        System.exit(0);
    }
 
Example 23
Source Project: web3sdk   Source File: OkClient.java    License: Apache License 2.0 5 votes vote down vote up
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]));
        service.run(); // run the daemon service
        // 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])) {
                deployOk();
            } else {
                String[] params = new String[args.length - 1];
                for (int i = 0; i < params.length; i++) params[i] = args[i + 1];
                testOk(params);
            }
        } else {
            System.out.println("\nPlease choose follow commands:\n deploy, trans or get");
        }
        System.exit(0);
    }
 
Example 24
Source Project: web3sdk   Source File: MixContractClient.java    License: Apache License 2.0 5 votes vote down vote up
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]));
        service.run(); // run the daemon service
        // 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);
    }
 
Example 25
Source Project: web3sdk   Source File: GMErc20Transaction.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    EncryptType encryptType = new EncryptType(1);
    System.out.println(encryptType.getEncryptType());
    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("300000000");

    Credentials credentials1 =
            GenCredential.create(
                    "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6");

    ContractGasProvider contractGasProvider = new StaticGasProvider(gasPrice, gasLimit);
    NewSolTest erc20 = NewSolTest.deploy(web3, credentials1, contractGasProvider).send();

    for (int i = 0; i < 1; i++) {
        System.out.println("####contract address is: " + erc20.getContractAddress());
        erc20.transfer("0x0f49a17d17f82da2a7d92ecf19268274150eaf5e", new BigInteger("100"))
                .send();

        BigInteger oldBalance =
                erc20.balanceOf("0x0f49a17d17f82da2a7d92ecf19268274150eaf5e").send();
        System.out.println(
                "0x0f49a17d17f82da2a7d92ecf19268274150eaf5e balance" + oldBalance.intValue());
    }
    System.exit(0);
}
 
Example 26
Source Project: web3sdk   Source File: GMTableTestClient.java    License: Apache License 2.0 5 votes vote down vote up
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]));
        service.run(); // run the daemon service
        // init the client keys
        keyPair = Keys.createEcKeyPair();
        credentials = GenCredential.create(keyPair.getPrivateKey().toString(16));

        logger.info("-----> start test !");
        logger.info("init AOMP ChannelEthereumService");
        ChannelEthereumService channelEthereumService = new ChannelEthereumService();
        channelEthereumService.setChannelService(service);
        channelEthereumService.setTimeout(5 * 1000);
        try {
            web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0]));
        } catch (Exception e) {
            System.out.println("\nPlease provide groupID in the first parameters");
            System.exit(0);
        }

        if (args.length > 1) {
            if ("deploy".equals(args[1])) {
                deployTableTest();
            } else {
                String[] params = new String[args.length - 1];
                for (int i = 0; i < params.length; i++) params[i] = args[i + 1];
                testTableTest(params);
            }
        } else {
            System.out.println(
                    "\nPlease choose follow commands:\n deploy, create, insert, select, update or remove");
        }
        System.exit(0);
    }
 
Example 27
Source Project: web3sdk   Source File: GMOkTransaction.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 28
Source Project: web3sdk   Source File: TestTxDecode.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 29
Source Project: evidenceSample   Source File: BcosApp.java    License: Apache License 2.0 5 votes vote down vote up
public boolean loadConfig() throws Exception{
	context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
	Service service = context.getBean(Service.class);
       service.run();
       ChannelEthereumService channelEthereumService = new ChannelEthereumService();
       channelEthereumService.setChannelService(service);
       web3j = Web3j.build(channelEthereumService,service.getGroupId());
       boolean flag=false;
       if(web3j!=null){
       	flag=true;
       }
       return flag;
}
 
Example 30
Source Project: WeEvent   Source File: FiscoBcos2.java    License: Apache License 2.0 4 votes vote down vote up
public Service getService() {
    return this.service;
}