use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildEventTransactionReceiptFunction.
MethodSpec buildEventTransactionReceiptFunction(String responseClassName, String functionName, List<NamedTypeName> indexedParameters, List<NamedTypeName> nonIndexedParameters) {
ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName.get(ClassName.get(List.class), ClassName.get("", responseClassName));
String generatedFunctionName = "get" + Strings.capitaliseFirstLetter(functionName) + "Events";
MethodSpec.Builder transactionMethodBuilder = MethodSpec.methodBuilder(generatedFunctionName).addModifiers(Modifier.PUBLIC).addParameter(TransactionReceipt.class, "transactionReceipt").returns(parameterizedTypeName);
transactionMethodBuilder.addStatement("$T valueList = extractEventParametersWithLog(" + buildEventDefinitionName(functionName) + ", " + "transactionReceipt)", ParameterizedTypeName.get(List.class, Contract.EventValuesWithLog.class)).addStatement("$1T responses = new $1T(valueList.size())", ParameterizedTypeName.get(ClassName.get(ArrayList.class), ClassName.get("", responseClassName))).beginControlFlow("for ($T eventValues : valueList)", Contract.EventValuesWithLog.class).addStatement("$1T typedResponse = new $1T()", ClassName.get("", responseClassName)).addCode(buildTypedResponse("typedResponse", indexedParameters, nonIndexedParameters, false)).addStatement("responses.add(typedResponse)").endControlFlow();
transactionMethodBuilder.addStatement("return responses");
return transactionMethodBuilder.build();
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt 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);
}
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class PerfomanceTableQuery 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 time_before = System.currentTimeMillis();
long _id = getNextID();
Random r = new Random();
long l1 = r.nextLong();
Tuple3<List<byte[]>, List<BigInteger>, List<byte[]>> lists = tabletest.select("fruit" + l1 % TableTestClient.modevalue).send();
Long time_after = System.currentTimeMillis();
TransactionReceipt receipt = new TransactionReceipt();
receipt.setStatus("0");
collector.onSelectMessage(receipt, time_after - time_before);
/*
List<byte[]> value1 = lists.getValue1();
List<BigInteger> value2 = lists.getValue2();
List<byte[]> value3 = lists.getValue3();
logger.info("record numbers = " + value1.size());
System.out.println("record numbers = " + value1.size());
for (int i = 0; i < value1.size(); i++) {
String name = new String(value1.get(i));
logger.info("name = " + name);
System.out.println("name = " + name);
int item_id = value2.get(i).intValue();
logger.info("item_id = " + item_id);
System.out.println("item_id = " + item_id);
String item_name = new String(value3.get(i));
logger.info("item_name = " + item_name);
System.out.println("item_name = " + item_name);
}
*/
} 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);
}
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt 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.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class TableTestClient method update.
private static void update(String[] args, TableTest tabletest) {
if (args.length == 4) {
try {
String name = args[1];
int item_id = Integer.parseInt(args[2]);
String item_name = args[3];
RemoteCall<TransactionReceipt> update = tabletest.update(name, BigInteger.valueOf(item_id), item_name);
TransactionReceipt transactionReceipt = update.send();
List<UpdateResultEventResponse> updateResultEvents = tabletest.getUpdateResultEvents(transactionReceipt);
if (updateResultEvents.size() > 0) {
for (int i = 0; i < updateResultEvents.size(); i++) {
UpdateResultEventResponse updateResultEventResponse = updateResultEvents.get(i);
System.out.println("updateCount = " + updateResultEventResponse.count.intValue());
logger.info("updateCount = " + updateResultEventResponse.count.intValue());
}
} else {
System.out.println("t_test table does not exist.");
}
} catch (Exception e) {
System.out.println("update transaction is abnormal, please check the environment");
}
} else {
System.out.println("\nPlease enter as follow example:\n 1 1 update fruit 1 orange");
}
}
Aggregations