use of org.web3j.abi.datatypes.Type in project jbpm-work-items by kiegroup.
the class EthereumUtils method observeContractEvent.
public static void observeContractEvent(Web3j web3j, String contractEventName, String contractAddress, List<TypeReference<?>> indexedParameters, List<TypeReference<?>> nonIndexedParameters, String eventReturnType, KieSession kieSession, String signalName, boolean doAbortOnUpdate, WorkItemManager workItemManager, WorkItem workItem) {
Event event = new Event(contractEventName, indexedParameters, nonIndexedParameters);
EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contractAddress);
filter.addSingleTopic(EventEncoder.encode(event));
Class<Type> type = (Class<Type>) AbiTypes.getType(eventReturnType);
TypeReference<Type> typeRef = TypeReference.create(type);
web3j.ethLogObservable(filter).subscribe(eventTrigger -> {
kieSession.signalEvent(signalName, FunctionReturnDecoder.decode(eventTrigger.getData(), Arrays.asList(typeRef)).get(0).getValue());
if (doAbortOnUpdate) {
workItemManager.completeWorkItem(workItem.getId(), null);
}
});
}
use of org.web3j.abi.datatypes.Type in project jbpm-work-items by kiegroup.
the class EthereumUtils method queryExistingContract.
public static Object queryExistingContract(Credentials credentials, Web3j web3j, String contractAddress, String contractMethodName, List<Type> contractMethodInputTypes, List<TypeReference<?>> contractMethodOutputTypes) throws Exception {
Function function = getFunction(contractMethodName, contractMethodInputTypes, contractMethodOutputTypes);
Transaction transaction = Transaction.createEthCallTransaction(credentials.getAddress(), contractAddress, getEncodedFunction(function));
EthCall response = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).sendAsync().get();
List<Type> responseTypeList = FunctionReturnDecoder.decode(response.getValue(), function.getOutputParameters());
if (responseTypeList != null && responseTypeList.size() > 0) {
return responseTypeList.get(0).getValue();
} else {
return null;
}
}
use of org.web3j.abi.datatypes.Type 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);
}
}
use of org.web3j.abi.datatypes.Type in project jbpm-work-items by kiegroup.
the class EthereumUtils method observeContractEvent.
public static void observeContractEvent(Web3j web3j, String contractEventName, String contractAddress, List<TypeReference<?>> indexedParameters, List<TypeReference<?>> nonIndexedParameters, String eventReturnType, KieSession kieSession, String signalName, boolean doAbortOnUpdate, WorkItemManager workItemManager, WorkItem workItem, rx.functions.Action1 action1) {
Event event = new Event(contractEventName, indexedParameters, nonIndexedParameters);
EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contractAddress);
filter.addSingleTopic(EventEncoder.encode(event));
Class<Type> type = (Class<Type>) AbiTypes.getType(eventReturnType);
TypeReference<Type> typeRef = TypeReference.create(type);
web3j.ethLogObservable(filter).subscribe(action1);
}
use of org.web3j.abi.datatypes.Type in project jbpm-work-items by kiegroup.
the class EthereumUtils method getFunction.
public static Function getFunction(String queryName, List<Type> queryInputTypes, List<TypeReference<?>> queryOutputTypes) {
List<Type> inputParameters;
if (queryInputTypes != null) {
inputParameters = queryInputTypes;
} else {
inputParameters = new ArrayList<>();
}
List<TypeReference<?>> outputTypes;
if (queryOutputTypes != null) {
outputTypes = queryOutputTypes;
} else {
outputTypes = new ArrayList<>();
}
Function function = new Function(queryName, inputParameters, outputTypes);
return function;
}
Aggregations