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);
}
}
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);
}
}
Aggregations