org.web3j.abi.datatypes.Event Java Examples

The following examples show how to use org.web3j.abi.datatypes.Event. 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: Contract.java    From client-sdk-java with Apache License 2.0 7 votes vote down vote up
public static EventValues staticExtractEventParameters(
        Event event, Log log) {

    List<String> topics = log.getTopics();
    String encodedEventSignature = EventEncoder.encode(event);
    if (topics == null || topics.size() == 0 || !topics.get(0).equals(encodedEventSignature)) {
        return null;
    }

    List<Type> indexedValues = new ArrayList<>();
    List<Type> nonIndexedValues = FunctionReturnDecoder.decode(
            log.getData(), event.getNonIndexedParameters());

    List<TypeReference<Type>> indexedParameters = event.getIndexedParameters();
    for (int i = 0; i < indexedParameters.size(); i++) {
        Type value = FunctionReturnDecoder.decodeIndexedValue(
                topics.get(i + 1), indexedParameters.get(i));
        indexedValues.add(value);
    }
    return new EventValues(indexedValues, nonIndexedValues);
}
 
Example #2
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<TransferEventResponse> transferEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("Transfer", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, TransferEventResponse>() {
        @Override
        public TransferEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            TransferEventResponse typedResponse = new TransferEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.owner = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #3
Source File: Contract.java    From web3j with Apache License 2.0 6 votes vote down vote up
public static EventValues staticExtractEventParameters(Event event, Log log) {
    final List<String> topics = log.getTopics();
    String encodedEventSignature = EventEncoder.encode(event);
    if (topics == null || topics.size() == 0 || !topics.get(0).equals(encodedEventSignature)) {
        return null;
    }

    List<Type> indexedValues = new ArrayList<>();
    List<Type> nonIndexedValues =
            FunctionReturnDecoder.decode(log.getData(), event.getNonIndexedParameters());

    List<TypeReference<Type>> indexedParameters = event.getIndexedParameters();
    for (int i = 0; i < indexedParameters.size(); i++) {
        Type value =
                FunctionReturnDecoder.decodeIndexedValue(
                        topics.get(i + 1), indexedParameters.get(i));
        indexedValues.add(value);
    }
    return new EventValues(indexedValues, nonIndexedValues);
}
 
Example #4
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 #5
Source File: TokenERC20.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 6 votes vote down vote up
public Observable<TransferEventResponse> transferEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("Transfer", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, TransferEventResponse>() {
        @Override
        public TransferEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            TransferEventResponse typedResponse = new TransferEventResponse();
            typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #6
Source File: TokenERC20.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 6 votes vote down vote up
public Observable<BurnEventResponse> burnEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("Burn", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, BurnEventResponse>() {
        @Override
        public BurnEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            BurnEventResponse typedResponse = new BurnEventResponse();
            typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #7
Source File: EventUtils.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
public String getSelectVal(EventDefinition ev, EthLog.LogResult ethLog)
{
    String selectVal = "";
    final Event resolverEvent = generateEventFunction(ev);
    final EventValues eventValues = staticExtractEventParameters(resolverEvent, (Log)ethLog.get());
    int selectIndexInNonIndexed = ev.getSelectIndex(false);
    int selectIndexInIndexed = ev.getSelectIndex(true);

    if (selectIndexInNonIndexed >= 0)
    {
        selectVal = getValueFromParams(eventValues.getNonIndexedValues(), selectIndexInNonIndexed);
    }
    else if (selectIndexInIndexed >= 0)
    {
        selectVal = getValueFromParams(eventValues.getIndexedValues(), selectIndexInIndexed);
    }

    Log log = (Log)ethLog;
    ev.readBlock = log.getBlockNumber().add(BigInteger.ONE);

    return selectVal;
}
 
Example #8
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<AddrChangedEventResponse> addrChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("AddrChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, AddrChangedEventResponse>() {
        @Override
        public AddrChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            AddrChangedEventResponse typedResponse = new AddrChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.a = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #9
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<ContentChangedEventResponse> contentChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("ContentChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, ContentChangedEventResponse>() {
        @Override
        public ContentChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            ContentChangedEventResponse typedResponse = new ContentChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.hash = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #10
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<NameChangedEventResponse> nameChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("NameChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NameChangedEventResponse>() {
        @Override
        public NameChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NameChangedEventResponse typedResponse = new NameChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.name = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #11
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<ABIChangedEventResponse> aBIChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("ABIChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Uint256>() {}),
            Arrays.<TypeReference<?>>asList());
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, ABIChangedEventResponse>() {
        @Override
        public ABIChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            ABIChangedEventResponse typedResponse = new ABIChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.contentType = (BigInteger) eventValues.getIndexedValues().get(1).getValue();
            return typedResponse;
        }
    });
}
 
Example #12
Source File: Contract.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public static EventValues staticExtractEventParameters(
        Event event, Log log) {

    List<String> topics = log.getTopics();
    String encodedEventSignature = EventEncoder.encode(event);
    if (!topics.get(0).equals(encodedEventSignature)) {
        return null;
    }

    List<Type> indexedValues = new ArrayList<>();
    List<Type> nonIndexedValues = FunctionReturnDecoder.decode(
            log.getData(), event.getNonIndexedParameters());

    List<TypeReference<Type>> indexedParameters = event.getIndexedParameters();
    for (int i = 0; i < indexedParameters.size(); i++) {
        Type value = FunctionReturnDecoder.decodeIndexedValue(
                topics.get(i + 1), indexedParameters.get(i));
        indexedValues.add(value);
    }
    return new EventValues(indexedValues, nonIndexedValues);
}
 
Example #13
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<PubkeyChangedEventResponse> pubkeyChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("PubkeyChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Bytes32>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, PubkeyChangedEventResponse>() {
        @Override
        public PubkeyChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            PubkeyChangedEventResponse typedResponse = new PubkeyChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.x = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.y = (byte[]) eventValues.getNonIndexedValues().get(1).getValue();
            return typedResponse;
        }
    });
}
 
Example #14
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<NewTTLEventResponse> newTTLEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("NewTTL", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint64>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NewTTLEventResponse>() {
        @Override
        public NewTTLEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NewTTLEventResponse typedResponse = new NewTTLEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.ttl = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #15
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<TextChangedEventResponse> textChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("TextChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Utf8String>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, TextChangedEventResponse>() {
        @Override
        public TextChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            TextChangedEventResponse typedResponse = new TextChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.indexedKey = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.key = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #16
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<NewOwnerEventResponse> newOwnerEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("NewOwner", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NewOwnerEventResponse>() {
        @Override
        public NewOwnerEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NewOwnerEventResponse typedResponse = new NewOwnerEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.label = (byte[]) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.owner = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #17
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<NewResolverEventResponse> newResolverEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("NewResolver", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NewResolverEventResponse>() {
        @Override
        public NewResolverEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NewResolverEventResponse typedResponse = new NewResolverEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.resolver = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #18
Source File: EventUtils.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
public String getTopicVal(EventDefinition ev, EthLog.LogResult ethLog)
{
    String topicVal = "";
    final Event resolverEvent = generateEventFunction(ev);
    final EventValues eventValues = staticExtractEventParameters(resolverEvent, (Log)ethLog.get());
    String filterTopic = ev.getFilterTopicIndex();
    int topicIndex = ev.getTopicIndex(filterTopic);

    topicVal = getValueFromParams(eventValues.getIndexedValues(), topicIndex);

    return topicVal;
}
 
Example #19
Source File: ContractTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
public List<EventValues> processEvent(TransactionReceipt transactionReceipt) {
    Event event =
            new Event(
                    "Event",
                    Arrays.asList(
                            new TypeReference<Address>(true) {},
                            new TypeReference<Uint256>() {}));
    return extractEventParameters(event, transactionReceipt);
}
 
Example #20
Source File: TokenERC20.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 5 votes vote down vote up
public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("Transfer", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        TransferEventResponse typedResponse = new TransferEventResponse();
        typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
        typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example #21
Source File: Contract.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
protected List<EventValues> extractEventParameters(
        Event event, TransactionReceipt transactionReceipt) {
    return transactionReceipt.getLogs().stream()
            .map(log -> extractEventParameters(event, log))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #22
Source File: HumanStandardTokenIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
private Event approvalEvent() {
    return new Event(
            "Approval",
            Arrays.asList(
                    new TypeReference<Address>(true) {},
                    new TypeReference<Address>(true) {},
                    new TypeReference<Uint256>() {}));
}
 
Example #23
Source File: TestnetConfig.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public String encodedEvent() {
    Event event =
            new Event(
                    "Notify",
                    Arrays.asList(
                            new TypeReference<Uint>(true) {}, new TypeReference<Uint>() {}));

    return EventEncoder.encode(event);
}
 
Example #24
Source File: EventEncoderTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncode() {
    Event event =
            new Event(
                    "Notify",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}));

    assertEquals(
            EventEncoder.encode(event),
            "0x71e71a8458267085d5ab16980fd5f114d2d37f232479c245d523ce8d23ca40ed");
}
 
Example #25
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 5 votes vote down vote up
private FieldSpec createEventDefinition(String name, List<NamedTypeName> parameters) {

        CodeBlock initializer = buildVariableLengthEventInitializer(name, parameters);

        return FieldSpec.builder(Event.class, buildEventDefinitionName(name))
                .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
                .initializer(initializer)
                .build();
    }
 
Example #26
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 5 votes vote down vote up
private static CodeBlock buildVariableLengthEventInitializer(
        String eventName, List<NamedTypeName> parameterTypes) {

    List<Object> objects = new ArrayList<>();
    objects.add(Event.class);
    objects.add(eventName);

    objects.add(Arrays.class);
    objects.add(TypeReference.class);
    for (NamedTypeName parameterType : parameterTypes) {
        objects.add(TypeReference.class);
        objects.add(parameterType.getTypeName());
    }

    String asListParams =
            parameterTypes.stream()
                    .map(
                            type -> {
                                if (type.isIndexed()) {
                                    return "new $T<$T>(true) {}";
                                } else {
                                    return "new $T<$T>() {}";
                                }
                            })
                    .collect(Collectors.joining(", "));

    return CodeBlock.builder()
            .addStatement(
                    "new $T($S, \n" + "$T.<$T<?>>asList(" + asListParams + "))",
                    objects.toArray())
            .build();
}
 
Example #27
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public List<NewTTLEventResponse> getNewTTLEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("NewTTL", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint64>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<NewTTLEventResponse> responses = new ArrayList<NewTTLEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        NewTTLEventResponse typedResponse = new NewTTLEventResponse();
        typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.ttl = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example #28
Source File: Contract.java    From web3j with Apache License 2.0 5 votes vote down vote up
protected List<EventValues> extractEventParameters(
        Event event, TransactionReceipt transactionReceipt) {
    return transactionReceipt.getLogs().stream()
            .map(log -> extractEventParameters(event, log))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #29
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 #30
Source File: Contract.java    From web3j with Apache License 2.0 5 votes vote down vote up
protected List<EventValuesWithLog> extractEventParametersWithLog(
        Event event, TransactionReceipt transactionReceipt) {
    return transactionReceipt.getLogs().stream()
            .map(log -> extractEventParametersWithLog(event, log))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}