Graphql - allow matching any topic (#3662)

* added test file to match any topic

* add singleton list containing null if empty topic passed in

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3803/head
Sally MacFarlane 3 years ago committed by GitHub
parent baed1ef02c
commit e8407ae344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      CHANGELOG.md
  2. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetchers.java
  3. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java
  4. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/EthGraphQLHttpBySpecTest.java
  5. 26
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getLogs_emptyListParam.json
  6. 22
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getLogs_matchAnyTopic.json
  7. 29
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getLogs_matchAnyTopic.json

@ -1,5 +1,10 @@
# Changelog
## 22.4.1
### Additions and Improvements
- GraphQL - allow null log topics in queries which match any topic [#3662](https://github.com/hyperledger/besu/pull/3662)
## 22.4.0
### Breaking Changes

@ -50,6 +50,7 @@ import org.hyperledger.besu.evm.worldstate.WorldState;
import org.hyperledger.besu.plugin.data.SyncStatus;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -256,7 +257,11 @@ public class GraphQLDataFetchers {
final List<List<LogTopic>> transformedTopics = new ArrayList<>();
for (final List<Bytes32> topic : topics) {
transformedTopics.add(topic.stream().map(LogTopic::of).collect(Collectors.toList()));
if (topic.isEmpty()) {
transformedTopics.add(Collections.singletonList(null));
} else {
transformedTopics.add(topic.stream().map(LogTopic::of).collect(Collectors.toList()));
}
}
final LogsQuery query =

@ -35,6 +35,7 @@ import org.hyperledger.besu.evm.tracing.OperationTracer;
import org.hyperledger.besu.evm.worldstate.WorldState;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -160,7 +161,11 @@ public class BlockAdapterBase extends AdapterBase {
final List<List<LogTopic>> transformedTopics = new ArrayList<>();
for (final List<Bytes32> topic : topics) {
transformedTopics.add(topic.stream().map(LogTopic::of).collect(Collectors.toList()));
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();

@ -78,7 +78,9 @@ public class EthGraphQLHttpBySpecTest extends AbstractEthGraphQLHttpServiceTest
specs.add("eth_getCode");
specs.add("eth_getCode_noCode");
specs.add("eth_getLogs_emptyListParam");
specs.add("eth_getLogs_matchTopic");
specs.add("eth_getLogs_matchAnyTopic");
specs.add("eth_getLogs_range");
specs.add("eth_getStorageAt");

@ -0,0 +1,26 @@
{
"request": "{ block(number: \"0x20\") { logs( filter: { topics : [[], [\"0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b\"]]}) { index topics data account{address} transaction{hash} } } }",
"response": {
"data" : {
"block" : {
"logs" : [ {
"index" : 0,
"topics": [
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
],
"data" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe9000000000000000000000000000000000000000000000000000000000000002a",
"account" : {
"address" : "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"
},
"transaction" : {
"hash" : "0xcef53f2311d7c80e9086d661e69ac11a5f3d081e28e02a9ba9b66749407ac310"
}
} ]
}
}
},
"statusCode": 200
}

@ -0,0 +1,22 @@
{
"request": "{ block(number: \"0x17\") { logs( filter: { topics : []}) { index topics data account{address} transaction{hash} } } }",
"response": {
"data" : {
"block" : {
"logs" : [ {
"index" : 0,
"topics" : [ "0x65c9ac8011e286e89d02a269890f41d67ca2cc597b2c76c7c69321ff492be580" ],
"data" : "0x000000000000000000000000000000000000000000000000000000000000002a",
"account" : {
"address" : "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"
},
"transaction" : {
"hash" : "0x97a385bf570ced7821c6495b3877ddd2afd5c452f350f0d4876e98d9161389c6"
}
} ]
}
}
},
"statusCode": 200
}

@ -0,0 +1,29 @@
{
"request": {
"id": 406,
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{
"fromBlock": "0x17",
"toBlock": "0x17",
"address": [],
"topics": []
}]
},
"response": {
"jsonrpc": "2.0",
"id": 406,
"result" : [{
"logIndex" : "0x0",
"removed": false,
"blockNumber" : "0x17",
"blockHash" : "0x3c419f39b340a4c35cc27b8f7880b779dc1abb9814ad13a2a5a55b885cc8ec2d",
"transactionHash" : "0x97a385bf570ced7821c6495b3877ddd2afd5c452f350f0d4876e98d9161389c6",
"transactionIndex" : "0x0",
"address" : "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"data" : "0x000000000000000000000000000000000000000000000000000000000000002a",
"topics" : ["0x65c9ac8011e286e89d02a269890f41d67ca2cc597b2c76c7c69321ff492be580"]
}]
},
"statusCode": 200
}
Loading…
Cancel
Save