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");
}
}
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;
}
Aggregations