use of org.web3j.tx.RawTransactionManager in project jbpm-work-items by kiegroup.
the class SendEtherWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
try {
String serviceURL = (String) workItem.getParameter("ServiceURL");
String amount = (String) workItem.getParameter("Amount");
String toAddress = (String) workItem.getParameter("ToAddress");
if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(toAddress) && StringUtils.isNotEmpty(amount) && NumberUtils.isDigits(amount)) {
Map<String, Object> results = new HashMap<String, Object>();
if (web3j == null) {
web3j = Web3j.build(new HttpService(serviceURL));
}
auth = new EthereumAuth(walletPassword, walletPath, classLoader);
Credentials credentials = auth.getCredentials();
TransactionManager transactionManager = new RawTransactionManager(web3j, credentials);
if (transfer == null) {
transfer = new Transfer(web3j, transactionManager);
}
int amountToSend = 0;
if (amount != null) {
amountToSend = Integer.parseInt(amount);
}
TransactionReceipt transactionReceipt = EthereumUtils.sendFundsToContract(credentials, web3j, amountToSend, toAddress, transfer);
results.put(RESULTS, transactionReceipt);
workItemManager.completeWorkItem(workItem.getId(), results);
} else {
logger.error("Missing service url or valid ether amount or toAddress.");
throw new IllegalArgumentException("Missing service url or valid ether amount or toAddress.");
}
} catch (Exception e) {
logger.error("Error executing workitem: " + e.getMessage());
handleException(e);
}
}
Aggregations