Search in sources :

Example 6 with HttpService

use of org.web3j.protocol.http.HttpService in project jbpm-work-items by kiegroup.

the class QueryExistingContractWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        String serviceURL = (String) workItem.getParameter("ServiceURL");
        String contractAddress = (String) workItem.getParameter("ContractAddress");
        String contractMethodName = (String) workItem.getParameter("ContractMethodName");
        String contractMethodOutputType = (String) workItem.getParameter("MethodOutputType");
        if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(contractAddress) && StringUtils.isNotEmpty(contractMethodName)) {
            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();
            List<TypeReference<?>> outputTypeList = null;
            if (contractMethodOutputType != null) {
                Class typeClazz = Class.forName(contractMethodOutputType);
                outputTypeList = Collections.singletonList(TypeReference.create(typeClazz));
            }
            Object queryReturnObj = EthereumUtils.queryExistingContract(credentials, web3j, contractAddress, contractMethodName, null, outputTypeList);
            results.put(RESULTS, queryReturnObj);
            workItemManager.completeWorkItem(workItem.getId(), results);
        } else {
            logger.error("Missing service url, valid address or method name to execute.");
            throw new IllegalArgumentException("Missing service url, valid address or method name to execute.");
        }
    } catch (Exception e) {
        logger.error("Error executing workitem: " + e.getMessage());
        handleException(e);
    }
}
Also used : HashMap(java.util.HashMap) HttpService(org.web3j.protocol.http.HttpService) TypeReference(org.web3j.abi.TypeReference) Credentials(org.web3j.crypto.Credentials)

Example 7 with HttpService

use of org.web3j.protocol.http.HttpService in project jbpm-work-items by kiegroup.

the class DeployContractWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        String serviceURL = (String) workItem.getParameter("ServiceURL");
        String contractPath = (String) workItem.getParameter("ContractPath");
        String depositAmount = (String) workItem.getParameter("DepositAmount");
        String waitForReceiptStr = (String) workItem.getParameter("WaitForReceipt");
        if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(contractPath)) {
            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();
            int depositEtherAmountToSend = 0;
            if (depositAmount != null) {
                depositEtherAmountToSend = Integer.parseInt(depositAmount);
            }
            boolean waitForReceipt = false;
            if (waitForReceiptStr != null) {
                waitForReceipt = Boolean.parseBoolean(waitForReceiptStr);
            }
            String createdContractAddress = EthereumUtils.deployContract(credentials, web3j, EthereumUtils.convertStreamToStr(classLoader.getResourceAsStream(contractPath)), depositEtherAmountToSend, waitForReceipt, EthereumUtils.DEFAULT_SLEEP_DURATION, org.jbpm.process.workitem.ethereum.EthereumUtils.DEFAULT_ATTEMPTS);
            results.put(RESULTS, createdContractAddress);
            workItemManager.completeWorkItem(workItem.getId(), results);
        } else {
            logger.error("Missing service url, or contract path.");
            throw new IllegalArgumentException("Missing service url, or contract path.");
        }
    } catch (Exception e) {
        logger.error("Error executing workitem: " + e.getMessage());
        handleException(e);
    }
}
Also used : HashMap(java.util.HashMap) HttpService(org.web3j.protocol.http.HttpService) Credentials(org.web3j.crypto.Credentials)

Aggregations

HttpService (org.web3j.protocol.http.HttpService)7 HashMap (java.util.HashMap)5 Credentials (org.web3j.crypto.Credentials)5 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)2 PaymentService (com.asf.appcoins.sdk.iab.payment.PaymentService)1 ArrayList (java.util.ArrayList)1 IocBean (org.nutz.ioc.loader.annotation.IocBean)1 TypeReference (org.web3j.abi.TypeReference)1 Type (org.web3j.abi.datatypes.Type)1 Web3j (org.web3j.protocol.Web3j)1 RawTransactionManager (org.web3j.tx.RawTransactionManager)1 TransactionManager (org.web3j.tx.TransactionManager)1 Transfer (org.web3j.tx.Transfer)1