Search in sources :

Example 6 with TransactionException

use of org.fisco.bcos.web3j.protocol.exceptions.TransactionException in project web3sdk by FISCO-BCOS.

the class GMTableTestClient method deployTableTest.

/* deploy the contract,get address from blockchain */
@SuppressWarnings("deprecation")
public static void deployTableTest() {
    RemoteCall<TableTest> deploy = TableTest.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit));
    TableTest tabletest;
    try {
        tabletest = deploy.send();
        contractAddress = tabletest.getContractAddress();
        System.out.println("deploy contract address: " + contractAddress);
        logger.info("deploy contract address: " + contractAddress);
        final Resource contractResource = new ClassPathResource("contract.properties");
        PropertiesConfiguration prop = new PropertiesConfiguration(contractResource.getFile());
        prop.setProperty("crud_address", contractAddress);
        prop.save();
        System.out.println("deploy contract successful!");
    } catch (TransactionException e) {
        if ("0x19".equals(e.getStatus())) {
            System.out.println("non-authorized to deploy contracts!");
        } else {
            System.out.println("deploy transaction is abnormal, please check the environment msg:" + e.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("deploy transaction is abnormal, please check the environment");
    }
}
Also used : StaticGasProvider(org.fisco.bcos.web3j.tx.gas.StaticGasProvider) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException)

Example 7 with TransactionException

use of org.fisco.bcos.web3j.protocol.exceptions.TransactionException in project web3sdk by FISCO-BCOS.

the class Contract method executeTransaction.

/**
 * Given the duration required to execute a transaction.
 *
 * @param data to send in transaction
 * @param weiValue in Wei to send in transaction
 * @return {@link Optional} containing our transaction receipt
 * @throws IOException if the call to the node fails
 * @throws TransactionException if the transaction was not mined while waiting
 */
protected TransactionReceipt executeTransaction(String data, BigInteger weiValue, String funcName) throws TransactionException, IOException {
    Callback callback = new Callback();
    asyncExecuteTransaction(data, funcName, callback);
    try {
        callback.semaphore.acquire(1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    TransactionReceipt receipt = callback.receipt;
    if (!receipt.isStatusOK()) {
        String status = receipt.getStatus();
        BigInteger gasUsed = receipt.getGasUsed();
        String message = StatusCode.getStatusMessage(receipt.getStatus(), receipt.getMessage());
        logger.trace(" execute transaction not successfully, hash: {}, status: {}, message: {}, gasUsed: {}", receipt.getTransactionHash(), receipt.getStatus(), receipt.getMessage(), receipt.getGasUsed());
        TransactionException transactionException = new TransactionException(message, status, gasUsed, receipt.getTransactionHash());
        transactionException.setReceipt(receipt);
        throw transactionException;
    }
    return receipt;
}
Also used : EventLogPushWithDecodeCallback(org.fisco.bcos.channel.event.filter.EventLogPushWithDecodeCallback) TransactionSucCallback(org.fisco.bcos.channel.client.TransactionSucCallback) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) BigInteger(java.math.BigInteger)

Aggregations

TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)7 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 Resource (org.springframework.core.io.Resource)4 BigInteger (java.math.BigInteger)2 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 Timeout (io.netty.util.Timeout)1 TimerTask (io.netty.util.TimerTask)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetSocketAddress (java.net.InetSocketAddress)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 CertificateException (java.security.cert.CertificateException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1