Search in sources :

Example 1 with HttpService

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

the class GetBalanceWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        String serviceURL = (String) workItem.getParameter("ServiceURL");
        if (StringUtils.isNotEmpty(serviceURL)) {
            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();
            results.put(RESULTS_VALUE, EthereumUtils.getBalanceInEther(credentials, web3j));
            workItemManager.completeWorkItem(workItem.getId(), results);
        } else {
            logger.error("Missing service url.");
            throw new IllegalArgumentException("Missing service url.");
        }
    } 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)

Example 2 with HttpService

use of org.web3j.protocol.http.HttpService 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)

Example 3 with HttpService

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

the class TransactExistingContractWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        String serviceURL = (String) workItem.getParameter("ServiceURL");
        String contractAddress = (String) workItem.getParameter("ContractAddress");
        String waitForReceiptStr = (String) workItem.getParameter("WaitForReceipt");
        String methodName = (String) workItem.getParameter("MethodName");
        Type methodInputType = (Type) workItem.getParameter("MethodInputType");
        String depositAmount = (String) workItem.getParameter("DepositAmount");
        if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(contractAddress) && StringUtils.isNotEmpty(methodName)) {
            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);
            }
            List<Type> methodInputTypeList = new ArrayList<>();
            if (methodInputType != null) {
                methodInputTypeList = Collections.singletonList(methodInputType);
            }
            TransactionReceipt transactionReceipt = EthereumUtils.transactExistingContract(credentials, web3j, depositEtherAmountToSend, EthereumUtils.DEFAULT_GAS_PRICE, EthereumUtils.DEFAULT_GAS_LIMIT, contractAddress, methodName, methodInputTypeList, null, waitForReceipt, EthereumUtils.DEFAULT_SLEEP_DURATION, EthereumUtils.DEFAULT_ATTEMPTS);
            results.put(RESULTS, transactionReceipt);
            workItemManager.completeWorkItem(workItem.getId(), results);
        } else {
            logger.error("Missing service url, valid toAddress or method name to execute.");
            throw new IllegalArgumentException("Missing service url, valid toAddress or method name to execute.");
        }
    } catch (Exception e) {
        logger.error("Error executing workitem: " + e.getMessage());
        handleException(e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Type(org.web3j.abi.datatypes.Type) HttpService(org.web3j.protocol.http.HttpService) Credentials(org.web3j.crypto.Credentials)

Example 4 with HttpService

use of org.web3j.protocol.http.HttpService in project AppCoins-ethereumj by AppStoreFoundation.

the class AppCoinsSdkBuilder method createAppCoinsSdk.

public AppCoinsSdk createAppCoinsSdk() {
    Web3j web3;
    if (debug) {
        networkId = 3;
        web3 = Web3jFactory.build(new HttpService("https://ropsten.infura.io/1YsvKO0VH5aBopMYJzcy"));
    } else {
        networkId = 1;
        web3 = Web3jFactory.build(new HttpService("https://mainnet.infura.io/1YsvKO0VH5aBopMYJzcy"));
    }
    if (this.scheduler == null) {
        this.scheduler = Schedulers.io();
    }
    if (this.skuManager == null) {
        this.skuManager = new SkuManager(skus);
    }
    if (this.asfWeb3j == null) {
        this.asfWeb3j = new AsfWeb3jImpl(web3);
    }
    if (this.paymentService == null) {
        this.paymentService = new PaymentService(networkId, skuManager, developerAddress, asfWeb3j);
    }
    return new AppCoinsSdkImpl(period, scheduler, skuManager, paymentService, debug);
}
Also used : Web3j(org.web3j.protocol.Web3j) HttpService(org.web3j.protocol.http.HttpService) PaymentService(com.asf.appcoins.sdk.iab.payment.PaymentService)

Example 5 with HttpService

use of org.web3j.protocol.http.HttpService in project nutzboot by nutzam.

the class Web3jStarter method createWeb3jService.

@IocBean(name = "web3jService")
public Web3jService createWeb3jService() {
    String url = conf.get(PROP_HTTP_URL, HttpService.DEFAULT_URL);
    boolean debug = conf.getBoolean(PROP_HTTP_DEBUG, true);
    boolean includeRawResponses = conf.getBoolean(PROP_HTTP_INCLUDE_RAW_RESPONSES, false);
    if (debug)
        return new HttpService(url, includeRawResponses);
    return new HttpService(url, new OkHttpClient.Builder().build(), includeRawResponses);
}
Also used : HttpService(org.web3j.protocol.http.HttpService) IocBean(org.nutz.ioc.loader.annotation.IocBean)

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