Search in sources :

Example 1 with Transfer

use of org.web3j.tx.Transfer 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);
    }
}
Also used : HashMap(java.util.HashMap) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) RawTransactionManager(org.web3j.tx.RawTransactionManager) HttpService(org.web3j.protocol.http.HttpService) RawTransactionManager(org.web3j.tx.RawTransactionManager) TransactionManager(org.web3j.tx.TransactionManager) Transfer(org.web3j.tx.Transfer) Credentials(org.web3j.crypto.Credentials)

Aggregations

HashMap (java.util.HashMap)1 Credentials (org.web3j.crypto.Credentials)1 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)1 HttpService (org.web3j.protocol.http.HttpService)1 RawTransactionManager (org.web3j.tx.RawTransactionManager)1 TransactionManager (org.web3j.tx.TransactionManager)1 Transfer (org.web3j.tx.Transfer)1