use of org.web3j.protocol.core.methods.request.EthFilter 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.protocol.core.methods.request.EthFilter 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);
}