use of org.fisco.bcos.web3j.protocol.exceptions.TransactionException in project web3sdk by FISCO-BCOS.
the class Service method asyncSendEthereumMessage.
public void asyncSendEthereumMessage(BcosRequest request, BcosResponseCallback callback) {
BcosMessage bcosMessage = new BcosMessage();
bcosMessage.setSeq(request.getMessageID());
bcosMessage.setResult(0);
bcosMessage.setType((short) 0x12);
bcosMessage.setData(request.getContent().getBytes());
// select node
try {
ChannelConnections channelConnections = allChannelConnections.getAllChannelConnections().stream().filter(x -> x.getGroupId() == groupId).findFirst().get();
if (channelConnections == null) {
if (orgID != null) {
logger.error("not found:{}", orgID);
throw new TransactionException("not found orgID");
} else {
logger.error("not found:{}", agencyName);
throw new TransactionException("not found agencyName");
}
}
ChannelHandlerContext ctx = channelConnections.randomNetworkConnection(nodeToBlockNumberMap);
ByteBuf out = ctx.alloc().buffer();
bcosMessage.writeHeader(out);
bcosMessage.writeExtra(out);
seq2Callback.put(request.getMessageID(), callback);
if (request.getTimeout() > 0) {
final BcosResponseCallback callbackInner = callback;
callback.setTimeout(timeoutHandler.newTimeout(new TimerTask() {
BcosResponseCallback _callback = callbackInner;
@Override
public void run(Timeout timeout) throws Exception {
logger.error("process bcos message timeout, seq: {}, timeout: {}", bcosMessage.getSeq(), request.getTimeout());
// handle timer
_callback.onTimeout();
}
}, request.getTimeout(), TimeUnit.MILLISECONDS));
}
ctx.writeAndFlush(out);
SocketChannel socketChannel = (SocketChannel) ctx.channel();
InetSocketAddress socketAddress = socketChannel.remoteAddress();
logger.debug("selected node {}:{} bcos request, seq:{}", socketAddress.getAddress().getHostAddress(), socketAddress.getPort(), bcosMessage.getSeq());
} catch (Exception e) {
logger.error(" error message:{}, error: {} ", e.getMessage(), e);
BcosResponse response = new BcosResponse();
response.setErrorCode(-1);
response.setErrorMessage(e.getMessage() + " requset send failed! please check the log file content for reasons.");
response.setContent("");
response.setMessageID(request.getMessageID());
if (callback.getTimeout() != null) {
callback.getTimeout().cancel();
}
callback.onResponse(response);
}
}
use of org.fisco.bcos.web3j.protocol.exceptions.TransactionException in project web3sdk by FISCO-BCOS.
the class OkClient method deployOk.
/* deploy the contract,get address from blockchain */
@SuppressWarnings("deprecation")
public static void deployOk() {
RemoteCall<Ok> deploy = Ok.deploy(web3j, credentials, gasPrice, gasLimit);
Ok ok;
try {
ok = deploy.send();
contractAddress = ok.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("ok_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(e.getMessage());
}
} catch (Exception e) {
System.out.println("deploy failed! " + e.getMessage());
}
}
use of org.fisco.bcos.web3j.protocol.exceptions.TransactionException in project web3sdk by FISCO-BCOS.
the class TableTestClient 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 PrecompiledCommon method handleTransactionReceiptForCRUD.
public static int handleTransactionReceiptForCRUD(TransactionReceipt receipt) throws TransactionException {
String status = receipt.getStatus();
if (!"0x0".equals(status)) {
throw new TransactionException(StatusCode.getStatusMessage(status, receipt.getMessage()));
}
String output = receipt.getOutput();
if (!"0x".equals(output)) {
return new BigInteger(output.substring(2, output.length()), 16).intValue();
} else {
throw new TransactionException("Transaction is handled failure.");
}
}
use of org.fisco.bcos.web3j.protocol.exceptions.TransactionException in project web3sdk by FISCO-BCOS.
the class MixContractClient method deploymixContract.
/* deploy the contract,get address from blockchain */
@SuppressWarnings("deprecation")
public static void deploymixContract() {
RemoteCall<MixContract> deploy = MixContract.deploy(web3j, credentials, gasPrice, gasLimit);
MixContract mixContract;
try {
mixContract = deploy.send();
contractAddress = mixContract.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("mix_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(e.getMessage());
}
} catch (Exception e) {
System.out.println("deploy failed! " + e.getMessage());
}
}
Aggregations