Search in sources :

Example 16 with TransactionReceipt

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);
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) RlpString(org.fisco.bcos.web3j.rlp.RlpString)

Example 17 with 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(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;
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 18 with 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;
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 19 with 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);
    }
}
Also used : StaticGasProvider(org.fisco.bcos.web3j.tx.gas.StaticGasProvider) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 20 with TransactionReceipt

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);
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) Test(org.junit.Test)

Aggregations

TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)41 BigInteger (java.math.BigInteger)18 Service (org.fisco.bcos.channel.client.Service)10 Credentials (org.fisco.bcos.web3j.crypto.Credentials)10 Web3j (org.fisco.bcos.web3j.protocol.Web3j)10 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)10 ApplicationContext (org.springframework.context.ApplicationContext)10 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)10 RateLimiter (com.google.common.util.concurrent.RateLimiter)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)9 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)9 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 Random (java.util.Random)6 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)5 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)5 List (java.util.List)4 PrecompileMessageException (org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException)3 Test (org.junit.Test)3 IOException (java.io.IOException)2