Java Code Examples for org.web3j.protocol.core.methods.response.EthLog#LogResult

The following examples show how to use org.web3j.protocol.core.methods.response.EthLog#LogResult . 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: 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 2
Source File: LogsFilter.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(List<LogResult> logResults) {
    List<Log> logs = new ArrayList<>(logResults.size());

    for (EthLog.LogResult logResult : logResults) {
        if (!(logResult instanceof EthLog.LogObject)) {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + " required LogObject");
        }

        logs.add(((EthLog.LogObject) logResult).get());
    }

    callback.onEvent(logs);
}
 
Example 3
Source File: BlockFilter.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(List<EthLog.LogResult> logResults) {
    for (EthLog.LogResult logResult : logResults) {
        if (logResult instanceof EthLog.Hash) {
            String blockHash = ((EthLog.Hash) logResult).get();
            callback.onEvent(blockHash);
        } else {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + ", required Hash");
        }
    }
}
 
Example 4
Source File: PendingTransactionFilter.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(List<EthLog.LogResult> logResults) {
    for (EthLog.LogResult logResult : logResults) {
        if (logResult instanceof EthLog.Hash) {
            String transactionHash = ((EthLog.Hash) logResult).get();
            callback.onEvent(transactionHash);
        } else {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + ", required Hash");
        }
    }
}
 
Example 5
Source File: CoreIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testEthGetLogs() throws Exception {
    org.web3j.protocol.core.methods.request.EthFilter ethFilter =
            new org.web3j.protocol.core.methods.request.EthFilter(
                    DefaultBlockParameterName.EARLIEST,
                    DefaultBlockParameterName.LATEST,
                    config.validContractAddress());

    ethFilter.addSingleTopic(config.encodedEvent());

    EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
    List<EthLog.LogResult> logs = ethLog.getLogs();
    assertFalse(logs.isEmpty());
}
 
Example 6
Source File: CoreIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testFiltersByFilterId() throws Exception {
    org.web3j.protocol.core.methods.request.EthFilter ethFilter =
            new org.web3j.protocol.core.methods.request.EthFilter(
                    DefaultBlockParameterName.EARLIEST,
                    DefaultBlockParameterName.LATEST,
                    config.validContractAddress());

    String eventSignature = config.encodedEvent();
    ethFilter.addSingleTopic(eventSignature);

    // eth_newFilter
    EthFilter ethNewFilter = web3j.ethNewFilter(ethFilter).send();
    BigInteger filterId = ethNewFilter.getFilterId();

    // eth_getFilterLogs
    EthLog ethFilterLogs = web3j.ethGetFilterLogs(filterId).send();
    List<EthLog.LogResult> filterLogs = ethFilterLogs.getLogs();
    assertFalse(filterLogs.isEmpty());

    // eth_getFilterChanges - nothing will have changed in this interval
    EthLog ethLog = web3j.ethGetFilterChanges(filterId).send();
    assertTrue(ethLog.getLogs().isEmpty());

    // eth_uninstallFilter
    EthUninstallFilter ethUninstallFilter = web3j.ethUninstallFilter(filterId).send();
    assertTrue(ethUninstallFilter.isUninstalled());
}
 
Example 7
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 8
Source File: BlocksFilter.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(List<LogResult> logResults) {
    List<String> blockHashes = new ArrayList<>(logResults.size());

    for (EthLog.LogResult logResult : logResults) {
        if (!(logResult instanceof EthLog.Hash)) {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + ", required Hash");
        }

        blockHashes.add(((EthLog.Hash) logResult).get());
    }

    callback.onEvent(blockHashes);
}
 
Example 9
Source File: LogFilter.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(List<EthLog.LogResult> logResults) {
    for (EthLog.LogResult logResult : logResults) {
        if (logResult instanceof EthLog.LogObject) {
            Log log = ((EthLog.LogObject) logResult).get();
            callback.onEvent(log);
        } else {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + " required LogObject");
        }
    }
}
 
Example 10
Source File: FilterTester.java    From web3j with Apache License 2.0 5 votes vote down vote up
List createExpected(EthLog ethLog) {
    List<EthLog.LogResult> logResults = ethLog.getLogs();
    if (logResults.isEmpty()) {
        fail("Results cannot be empty");
    }

    return ethLog.getLogs().stream().map(t -> t.get()).collect(Collectors.toList());
}
 
Example 11
Source File: FilterTester.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
List createExpected(EthLog ethLog) {
    List<EthLog.LogResult> logResults = ethLog.getLogs();
    if (logResults.isEmpty()) {
        fail("Results cannot be empty");
    }

    return ethLog.getLogs().stream()
            .map(t -> t.get()).collect(Collectors.toList());
}
 
Example 12
Source File: LogFilter.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
void process(List<EthLog.LogResult> logResults) {
    for (EthLog.LogResult logResult : logResults) {
        if (logResult instanceof EthLog.LogObject) {
            Log log = ((EthLog.LogObject) logResult).get();
            callback.onEvent(log);
        } else {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + " required LogObject");
        }
    }
}
 
Example 13
Source File: BlockFilter.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
void process(List<EthLog.LogResult> logResults) {
    for (EthLog.LogResult logResult : logResults) {
        if (logResult instanceof EthLog.Hash) {
            String blockHash = ((EthLog.Hash) logResult).get();
            callback.onEvent(blockHash);
        } else {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + ", required Hash");
        }
    }
}
 
Example 14
Source File: PendingTransactionsFilter.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(List<EthLog.LogResult> logResults) {
    List<String> logs = new ArrayList<>(logResults.size());

    for (EthLog.LogResult logResult : logResults) {
        if (!(logResult instanceof EthLog.Hash)) {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + ", required Hash");
        }

        logs.add(((EthLog.Hash) logResult).get());
    }

    callback.onEvent(logs);
}
 
Example 15
Source File: CoreIT.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEthGetLogs() throws Exception {
    org.web3j.protocol.core.methods.request.EthFilter ethFilter =
            new org.web3j.protocol.core.methods.request.EthFilter(
            DefaultBlockParameterName.EARLIEST,
            DefaultBlockParameterName.LATEST,
            config.validContractAddress()
    );

    ethFilter.addSingleTopic(config.encodedEvent());

    EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
    List<EthLog.LogResult> logs = ethLog.getLogs();
    assertFalse(logs.isEmpty());
}
 
Example 16
Source File: CoreIT.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testFiltersByFilterId() throws Exception {
    org.web3j.protocol.core.methods.request.EthFilter ethFilter =
            new org.web3j.protocol.core.methods.request.EthFilter(
            DefaultBlockParameterName.EARLIEST,
            DefaultBlockParameterName.LATEST,
            config.validContractAddress());

    String eventSignature = config.encodedEvent();
    ethFilter.addSingleTopic(eventSignature);

    // eth_newFilter
    EthFilter ethNewFilter = web3j.ethNewFilter(ethFilter).send();
    BigInteger filterId = ethNewFilter.getFilterId();

    // eth_getFilterLogs
    EthLog ethFilterLogs = web3j.ethGetFilterLogs(filterId).send();
    List<EthLog.LogResult> filterLogs = ethFilterLogs.getLogs();
    assertFalse(filterLogs.isEmpty());

    // eth_getFilterChanges - nothing will have changed in this interval
    EthLog ethLog = web3j.ethGetFilterChanges(filterId).send();
    assertTrue(ethLog.getLogs().isEmpty());

    // eth_uninstallFilter
    EthUninstallFilter ethUninstallFilter = web3j.ethUninstallFilter(filterId).send();
    assertTrue(ethUninstallFilter.isUninstalled());
}
 
Example 17
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 18
Source File: EventFilterIT.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testEventFilter() throws Exception {
    unlockAccount();

    Function function = createFibonacciFunction();
    String encodedFunction = FunctionEncoder.encode(function);

    BigInteger gas = estimateGas(encodedFunction);
    String transactionHash = sendTransaction(ALICE, CONTRACT_ADDRESS, gas, encodedFunction);

    TransactionReceipt transactionReceipt = waitForTransactionReceipt(transactionHash);

    assertFalse(gas.equals(transactionReceipt.getGasUsed()));

    List<Log> logs = transactionReceipt.getLogs();
    assertFalse(logs.isEmpty());

    Log log = logs.get(0);

    List<String> topics = log.getTopics();
    assertEquals(topics.size(), (1));

    Event event =
            new Event(
                    "Notify",
                    Arrays.asList(
                            new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}));

    // check function signature - we only have a single topic our event signature,
    // there are no indexed parameters in this example
    String encodedEventSignature = EventEncoder.encode(event);
    assertEquals(topics.get(0), (encodedEventSignature));

    // verify our two event parameters
    List<Type> results =
            FunctionReturnDecoder.decode(log.getData(), event.getNonIndexedParameters());
    assertEquals(
            results,
            (Arrays.asList(
                    new Uint256(BigInteger.valueOf(7)), new Uint256(BigInteger.valueOf(13)))));

    // finally check it shows up in the event filter
    List<EthLog.LogResult> filterLogs =
            createFilterForEvent(encodedEventSignature, CONTRACT_ADDRESS);
    assertFalse(filterLogs.isEmpty());
}
 
Example 19
Source File: Filter.java    From etherscan-explorer with GNU General Public License v3.0 votes vote down vote up
abstract void process(List<EthLog.LogResult> logResults); 
Example 20
Source File: Filter.java    From web3j with Apache License 2.0 votes vote down vote up
protected abstract void process(List<EthLog.LogResult> logResults);