Search in sources :

Example 1 with EthFilter

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);
        }
    });
}
Also used : EthFilter(org.web3j.protocol.core.methods.request.EthFilter) Type(org.web3j.abi.datatypes.Type) Event(org.web3j.abi.datatypes.Event)

Example 2 with EthFilter

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);
}
Also used : EthFilter(org.web3j.protocol.core.methods.request.EthFilter) Type(org.web3j.abi.datatypes.Type) Event(org.web3j.abi.datatypes.Event)

Aggregations

Event (org.web3j.abi.datatypes.Event)2 Type (org.web3j.abi.datatypes.Type)2 EthFilter (org.web3j.protocol.core.methods.request.EthFilter)2