use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class PerformanceEvidenceVerify 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 Evidence 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 = GenCredential.create();
BigInteger gasPrice = new BigInteger("30000000");
BigInteger gasLimit = new BigInteger("30000000");
String command = args[0];
Integer count = 0;
Integer qps = 0;
switch(command) {
case "insert":
count = Integer.parseInt(args[1]);
qps = Integer.parseInt(args[2]);
break;
default:
System.out.println("Args: <insert> <Total> <QPS>");
}
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
threadPool.setCorePoolSize(200);
threadPool.setMaxPoolSize(500);
threadPool.setQueueCapacity(count);
threadPool.initialize();
System.out.println("Deploying Evidence contract...");
EvidenceVerify evidence = EvidenceVerify.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;
ECDSASign signHandler = new ECDSASign();
ECKeyPair keyPair = Keys.createEcKeyPair();
System.out.println("Start test,total:" + count);
System.out.println("address:" + credentials.getAddress());
String signAddr = Keys.getAddress(keyPair);
System.out.println("standardCredential address:" + signAddr);
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 {
String evi = "test";
String evInfo = "test_info";
int random = new SecureRandom().nextInt(50000);
String eviId = String.valueOf(random);
// sign to evi
byte[] message = Hash.sha3(evi.getBytes());
Sign.SignatureData sign = signHandler.signMessage(evi.getBytes(), keyPair);
int v = sign.getV();
evidence.insertEvidence(evi, evInfo, eviId, signAddr, message, BigInteger.valueOf(v), sign.getR(), sign.getS(), 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);
}
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class StartGroup method main.
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);
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class BlockTxReceipts method init.
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;
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class GroupManager method init.
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;
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class GenerateGroup method main.
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);
}
Aggregations