Search in sources :

Example 26 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class LogsQueryTest method multivariateAddressQueryMatchReturnsTrue.

@Test
public void multivariateAddressQueryMatchReturnsTrue() {
    final Address address1 = Address.fromHexString("0x1111111111111111111111111111111111111111");
    final Address address2 = Address.fromHexString("0x2222222222222222222222222222222222222222");
    final LogsQuery query = new LogsQuery.Builder().addresses(address1, address2).build();
    final List<LogTopic> topics = new ArrayList<>();
    final Log log = new Log(address1, data, topics);
    assertThat(query.couldMatch(LogsBloomFilter.builder().insertLog(log).build())).isTrue();
    assertThat(query.matches(log)).isTrue();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) Log(org.hyperledger.besu.evm.log.Log) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) ArrayList(java.util.ArrayList) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.Test)

Example 27 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class LogsQueryTest method multivariateSurplusTopicMatchMultivariateQueryReturnTrue_02.

/**
 * [A, B] "A in first position AND B in second position (and anything after)"
 */
@Test
public void multivariateSurplusTopicMatchMultivariateQueryReturnTrue_02() {
    final Address address = Address.fromHexString("0x1111111111111111111111111111111111111111");
    final LogTopic topic1 = LogTopic.fromHexString("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    final LogTopic topic2 = LogTopic.fromHexString("0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
    final LogTopic topic3 = LogTopic.fromHexString("0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc");
    final List<LogTopic> logTopics = new ArrayList<>();
    logTopics.add(topic1);
    logTopics.add(topic2);
    logTopics.add(topic3);
    final List<LogTopic> queryTopics = new ArrayList<>();
    queryTopics.add(topic1);
    queryTopics.add(topic2);
    final List<List<LogTopic>> queryParameter = new ArrayList<>();
    queryParameter.add(queryTopics);
    final LogsQuery query = new LogsQuery.Builder().address(address).topics(queryParameter).build();
    final Log log = new Log(address, data, logTopics);
    assertThat(query.couldMatch(LogsBloomFilter.builder().insertLog(log).build())).isTrue();
    assertThat(query.matches(log)).isTrue();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) Log(org.hyperledger.besu.evm.log.Log) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.Test)

Example 28 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class BlockAdapterBase method getLogs.

public List<LogAdapter> getLogs(final DataFetchingEnvironment environment) {
    final Map<String, Object> filter = environment.getArgument("filter");
    @SuppressWarnings("unchecked") final List<Address> addrs = (List<Address>) filter.get("addresses");
    @SuppressWarnings("unchecked") final List<List<Bytes32>> topics = (List<List<Bytes32>>) filter.get("topics");
    final List<List<LogTopic>> transformedTopics = new ArrayList<>();
    for (final List<Bytes32> topic : topics) {
        if (topic.isEmpty()) {
            transformedTopics.add(Collections.singletonList(null));
        } else {
            transformedTopics.add(topic.stream().map(LogTopic::of).collect(Collectors.toList()));
        }
    }
    final LogsQuery query = new LogsQuery.Builder().addresses(addrs).topics(transformedTopics).build();
    final BlockchainQueries blockchain = getBlockchainQueries(environment);
    final Hash hash = header.getHash();
    final List<LogWithMetadata> logs = blockchain.matchingLogs(hash, query, () -> true);
    final List<LogAdapter> results = new ArrayList<>();
    for (final LogWithMetadata log : logs) {
        results.add(new LogAdapter(log));
    }
    return results;
}
Also used : Address(org.hyperledger.besu.datatypes.Address) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) ArrayList(java.util.ArrayList) Hash(org.hyperledger.besu.datatypes.Hash) Bytes32(org.apache.tuweni.bytes.Bytes32) LogTopic(org.hyperledger.besu.evm.log.LogTopic) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

LogsQuery (org.hyperledger.besu.ethereum.api.query.LogsQuery)28 Test (org.junit.Test)24 Address (org.hyperledger.besu.datatypes.Address)22 ArrayList (java.util.ArrayList)19 LogTopic (org.hyperledger.besu.evm.log.LogTopic)19 List (java.util.List)18 Log (org.hyperledger.besu.evm.log.Log)18 Collections.emptyList (java.util.Collections.emptyList)14 Collections.singletonList (java.util.Collections.singletonList)13 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)6 FilterParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter)6 Hash (org.hyperledger.besu.datatypes.Hash)4 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)4 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)4 LogWithMetadata (org.hyperledger.besu.ethereum.core.LogWithMetadata)4 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 TransactionPool (org.hyperledger.besu.ethereum.eth.transactions.TransactionPool)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1