org.web3j.abi.EventValues Java Examples

The following examples show how to use org.web3j.abi.EventValues. 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<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 #3
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 #4
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 #5
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 #6
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 #7
Source File: ContractTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testProcessEvent() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    Log log = new Log();
    log.setTopics(Arrays.asList(
            // encoded function
            "0xfceb437c298f40d64702ac26411b2316e79f3c28ffa60edfc891ad4fc8ab82ca",
            // indexed value
            "0000000000000000000000003d6cb163f7c72d20b0fcd6baae5889329d138a4a"));
    // non-indexed value
    log.setData("0000000000000000000000000000000000000000000000000000000000000001");

    transactionReceipt.setLogs(Arrays.asList(log));

    EventValues eventValues = contract.processEvent(transactionReceipt).get(0);

    assertThat(eventValues.getIndexedValues(),
            equalTo(singletonList(
                    new Address("0x3d6cb163f7c72d20b0fcd6baae5889329d138a4a"))));
    assertThat(eventValues.getNonIndexedValues(),
            equalTo(singletonList(new Uint256(BigInteger.ONE))));
}
 
Example #8
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 #9
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 #10
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 #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: 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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: ContractTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore
public void testProcessEvent() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    Log log = new Log();
    log.setTopics(Arrays.asList(
            // encoded function
            "0xfceb437c298f40d64702ac26411b2316e79f3c28ffa60edfc891ad4fc8ab82ca",
            // indexed value
            "0000000000000000000000003d6cb163f7c72d20b0fcd6baae5889329d138a4a"));
    // non-indexed value
    log.setData("0000000000000000000000000000000000000000000000000000000000000001");

    transactionReceipt.setLogs(Arrays.asList(log));

    EventValues eventValues = contract.processEvent(transactionReceipt).get(0);

    assertThat(eventValues.getIndexedValues(),
            equalTo(singletonList(
                    new Address("0x3d6cb163f7c72d20b0fcd6baae5889329d138a4a"))));
    assertThat(eventValues.getNonIndexedValues(),
            equalTo(singletonList(new Uint256(BigInteger.ONE))));
}
 
Example #19
Source File: ContractTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessEvent() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    Log log = new Log();
    log.setTopics(
            Arrays.asList(
                    // encoded function
                    "0xfceb437c298f40d64702ac26411b2316e79f3c28ffa60edfc891ad4fc8ab82ca",
                    // indexed value
                    "0000000000000000000000003d6cb163f7c72d20b0fcd6baae5889329d138a4a"));
    // non-indexed value
    log.setData("0000000000000000000000000000000000000000000000000000000000000001");

    transactionReceipt.setLogs(singletonList(log));

    EventValues eventValues = contract.processEvent(transactionReceipt).get(0);

    assertEquals(
            singletonList(new Address("0x3d6cb163f7c72d20b0fcd6baae5889329d138a4a")),
            eventValues.getIndexedValues());
    assertEquals(singletonList(new Uint256(BigInteger.ONE)), eventValues.getNonIndexedValues());
}
 
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: 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 #22
Source File: TokenERC20.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 5 votes vote down vote up
public List<BurnEventResponse> getBurnEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("Burn", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<BurnEventResponse> responses = new ArrayList<BurnEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        BurnEventResponse typedResponse = new BurnEventResponse();
        typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example #23
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 #24
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 #25
Source File: ContractTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessEventForLogWithoutTopics() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    final Log log = new Log();
    log.setTopics(Collections.emptyList());
    // non-indexed value
    log.setData("0000000000000000000000000000000000000000000000000000000000000001");
    transactionReceipt.setLogs(singletonList(log));

    final List<EventValues> eventValues = contract.processEvent(transactionReceipt);
    assertTrue(eventValues.isEmpty(), "No events expected");
}
 
Example #26
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 #27
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public List<NewResolverEventResponse> getNewResolverEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("NewResolver", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<NewResolverEventResponse> responses = new ArrayList<NewResolverEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        NewResolverEventResponse typedResponse = new NewResolverEventResponse();
        typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.resolver = (String) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example #28
Source File: Contract.java    From client-sdk-java 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: ContractTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public List<EventValues> processEvent(TransactionReceipt transactionReceipt) {
    Event event = new Event("Event",
            Arrays.<TypeReference<?>>asList(
                    new TypeReference<Address>(true) { },
                    new TypeReference<Uint256>() { }));
    return extractEventParameters(event, transactionReceipt);
}
 
Example #30
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public List<AddrChangedEventResponse> getAddrChangedEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("AddrChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<AddrChangedEventResponse> responses = new ArrayList<AddrChangedEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        AddrChangedEventResponse typedResponse = new AddrChangedEventResponse();
        typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.a = (String) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}