use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class PerformanceOkD 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...");
OkD ok = OkD.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;
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();
PerformanceOkCallback callback = new PerformanceOkCallback();
callback.setCollector(collector);
try {
ok.trans(String.valueOf(random.nextLong()), new BigInteger("1"), 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 GMTableTestClient 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<TableTest.UpdateResultEventResponse> updateResultEvents = tabletest.getUpdateResultEvents(transactionReceipt);
if (updateResultEvents.size() > 0) {
for (int i = 0; i < updateResultEvents.size(); i++) {
TableTest.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");
}
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class Web3jApITest method getTransactionReceipt.
@Test
public void getTransactionReceipt() throws IOException {
BcosTransactionReceipt bcosTransactionReceipt = web3j.getTransactionReceipt(txHash).send();
TransactionReceipt transactionReceipt = bcosTransactionReceipt.getTransactionReceipt().get();
assertNotNull(transactionReceipt);
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class TransactionResource method getTransactionReceiptWithProof.
public TransactionReceiptWithProof getTransactionReceiptWithProof(String transactionHash, String rootHash) throws IOException {
TransactionReceiptWithProof transactionReceiptWithProof = web3j.getTransactionReceiptByHashWithProof(transactionHash).send();
if (transactionReceiptWithProof.getTransactionReceiptWithProof() == null) {
return null;
}
TransactionReceipt transactionReceipt = transactionReceiptWithProof.getTransactionReceiptWithProof().getTransactionReceipt();
logger.debug("Receipt {}", transactionReceipt.toString());
// transaction index
String index = transactionReceipt.getTransactionIndexRaw();
BigInteger indexValue = Numeric.toBigInt(index);
byte[] byteIndex = RlpEncoder.encode(RlpString.create(indexValue));
String receiptRlp = ReceiptEncoder.encode(transactionReceipt);
logger.debug("ReceiptRlp:{}", receiptRlp);
String rlpHash = Hash.sha3(receiptRlp);
logger.debug("ReceiptRlpHash:{}", rlpHash);
String input = Numeric.toHexString(byteIndex) + rlpHash.substring(2);
logger.info("ReceiptWithIndex:{}", input);
String proof = Merkle.calculateMerkleRoot(transactionReceiptWithProof.getTransactionReceiptWithProof().getReceiptProof(), input);
// System.out.println("MerkleRoot: " + proof);
if (!proof.equals(rootHash)) {
logger.debug("MerkleRoot:{}", proof);
logger.debug("TransRoot :{}", rootHash);
return null;
}
return transactionReceiptWithProof;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class TransactionSucCallback method onTimeout.
public void onTimeout() {
TransactionReceipt receipt = new TransactionReceipt();
receipt.setStatus("Transaction receipt timeout");
// For console can get error message when timeout
receipt.setMessage("Transaction receipt timeout");
onResponse(receipt);
}
Aggregations