use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class MerkleProofUtility method verifyTransactionReceipt.
/**
* Verify transaction receipt merkle proof
*
* @param receiptRoot
* @param receiptAndProof
* @return
*/
public static boolean verifyTransactionReceipt(String receiptRoot, TransactionReceiptWithProof.ReceiptAndProof receiptAndProof) {
TransactionReceipt transactionReceipt = receiptAndProof.getTransactionReceipt();
// transaction index
byte[] byteIndex = RlpEncoder.encode(RlpString.create(transactionReceipt.getTransactionIndex()));
if (!transactionReceipt.getGasUsedRaw().startsWith("0x")) {
transactionReceipt.setGasUsed("0x" + transactionReceipt.getGasUsed().toString(16));
}
String receiptRlp = ReceiptEncoder.encode(transactionReceipt);
String rlpHash = Hash.sha3(receiptRlp);
String input = Numeric.toHexString(byteIndex) + rlpHash.substring(2);
String proof = Merkle.calculateMerkleRoot(receiptAndProof.getReceiptProof(), input);
logger.debug(" transaction hash: {}, receipt index: {}, root: {}, proof: {}, receipt: {}", transactionReceipt.getTransactionHash(), transactionReceipt.getTransactionIndex(), receiptRoot, proof, receiptAndProof.getTransactionReceipt());
return proof.equals(receiptRoot);
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class CallContract method sendTransaction.
public TransactionReceipt sendTransaction(BigInteger gasPrice, BigInteger gasLimit, String contractAddress, String funcName, Type... args) {
final Function function = new Function(funcName, Arrays.<Type>asList(args), Collections.<TypeReference<?>>emptyList());
TransactionReceipt transactionReceipt = new TransactionReceipt();
try {
ExecuteTransaction executeTransaction = new ExecuteTransaction(contractAddress, web3j, credentials, gasPrice, gasLimit);
transactionReceipt = executeTransaction.send(function);
String status = transactionReceipt.getStatus();
transactionReceipt.setMessage(StatusCode.getStatusMessage(status));
} catch (Exception e) {
transactionReceipt.setStatus(StatusCode.ExceptionCatched);
transactionReceipt.setMessage(e.getMessage());
transactionReceipt.setOutput("0x");
}
return transactionReceipt;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class CallContract method sendTransaction.
public TransactionReceipt sendTransaction(String contractAddress, String funcName, Type... args) {
final Function function = new Function(funcName, Arrays.<Type>asList(args), Collections.<TypeReference<?>>emptyList());
TransactionReceipt transactionReceipt = new TransactionReceipt();
try {
ExecuteTransaction executeTransaction = new ExecuteTransaction(contractAddress, web3j, credentials, gasPrice, gasLimit);
transactionReceipt = executeTransaction.send(function);
String status = transactionReceipt.getStatus();
transactionReceipt.setMessage(StatusCode.getStatusMessage(status));
} catch (Exception e) {
transactionReceipt.setStatus(StatusCode.ExceptionCatched);
transactionReceipt.setMessage(e.getMessage());
transactionReceipt.setOutput("0x");
}
return transactionReceipt;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class OkTest method testOkContract.
@Test
public void testOkContract() throws Exception {
Ok ok = Ok.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit)).send();
if (ok != null) {
TransactionReceipt receipt = ok.trans(new BigInteger("4")).send();
assertTrue(receipt.getBlockNumber().intValue() > 0);
assertTrue(receipt.getTransactionIndex().intValue() >= 0);
assertTrue(receipt.getGasUsed().intValue() > 0);
BigInteger oldBalance = ok.get().sendAsync().get(60000, TimeUnit.MILLISECONDS);
ok.trans(new BigInteger("4")).sendAsync().get(60000, TimeUnit.MILLISECONDS);
BigInteger newBalance = ok.get().sendAsync().get(60000, TimeUnit.MILLISECONDS);
assertTrue(newBalance.intValue() == oldBalance.intValue() + 4);
}
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt in project web3sdk by FISCO-BCOS.
the class PermissionServiceTest method userTableManager.
@Test
public void userTableManager() throws Exception {
TransactionReceipt transactionReceipt = permissionService.grantAndRetReceipt("tt", Common.TX_ORIGIN);
Assert.assertTrue(transactionReceipt.isStatusOK());
int i = PrecompiledCommon.handleTransactionReceiptForCRUD(transactionReceipt);
assertEquals(i, 1);
}
Aggregations