Java Code Examples for org.web3j.protocol.core.DefaultBlockParameterName#EARLIEST

The following examples show how to use org.web3j.protocol.core.DefaultBlockParameterName#EARLIEST . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
public static void observeContractEvent(Web3j web3j,
                                        String contractEventName,
                                        String contractAddress,
                                        List<TypeReference<?>> indexedParameters,
                                        List<TypeReference<?>> nonIndexedParameters,
                                        String eventReturnType,
                                        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);
}
 
Example 2
Source File: EventFilterIT.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private List<EthLog.LogResult> createFilterForEvent(
        String encodedEventSignature, String contractAddress) throws Exception {
    EthFilter ethFilter = new EthFilter(
            DefaultBlockParameterName.EARLIEST,
            DefaultBlockParameterName.LATEST,
            contractAddress
    );

    ethFilter.addSingleTopic(encodedEventSignature);

    EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
    return ethLog.getLogs();
}
 
Example 3
Source File: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
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);
                }
            }
    );
}
 
Example 4
Source File: EventFilterIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
private List<EthLog.LogResult> createFilterForEvent(
        String encodedEventSignature, String contractAddress) throws Exception {
    EthFilter ethFilter =
            new EthFilter(
                    DefaultBlockParameterName.EARLIEST,
                    DefaultBlockParameterName.LATEST,
                    contractAddress);

    ethFilter.addSingleTopic(encodedEventSignature);

    EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
    return ethLog.getLogs();
}
 
Example 5
Source File: EventUtils.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
public EthFilter generateLogFilter(EventDefinition ev, Token originToken, AttributeInterface attrIf) throws Exception
{
    int chainId = ev.contract.addresses.keySet().iterator().next();
    String eventContractAddr = ev.contract.addresses.get(chainId).get(0);

    final Event resolverEvent = generateEventFunction(ev);
    //work out which topics to filter on
    String filterTopic = ev.getFilterTopicIndex();
    String filterTopicValue = ev.getFilterTopicValue();

    //find the topic index - at this stage we only handle single topics
    int topicIndex = ev.getTopicIndex(filterTopic);

    //isolate which indexed param it is
    List<String> indexedParams = ev.eventModule.getArgNames(true);

    DefaultBlockParameter startBlock = DefaultBlockParameterName.EARLIEST;

    if (ev.readBlock != null && ev.readBlock.compareTo(BigInteger.ZERO) > 0)
    {
        startBlock = DefaultBlockParameter.valueOf(ev.readBlock);
    }

    final org.web3j.protocol.core.methods.request.EthFilter filter =
            new org.web3j.protocol.core.methods.request.EthFilter(
                    startBlock,
                    DefaultBlockParameterName.LATEST,
                    eventContractAddr)                            // contract address
                    .addSingleTopic(EventEncoder.encode(resolverEvent)); // event name

    for (int i = 0; i < indexedParams.size(); i++)
    {
        if (i == topicIndex)
        {
            addTopicFilter(ev, filter, filterTopicValue, originToken, eventContractAddr, attrIf); //add the required log filter - allowing for multiple tokenIds
            break;
        }
        else
        {
            filter.addSingleTopic(null);
        }
    }

    return filter;
}