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();
}
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();
}
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;
}
Aggregations