diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/LogsSubscriptionParam.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/LogsSubscriptionParam.java index 0cf1da2814..c7da1043a5 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/LogsSubscriptionParam.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/LogsSubscriptionParam.java @@ -15,22 +15,24 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.request; import java.util.List; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; class LogsSubscriptionParam { - private final String address; + private final List address; private final List topics; @JsonCreator LogsSubscriptionParam( - @JsonProperty("address") final String address, + @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) @JsonProperty("address") + final List address, @JsonProperty("topics") final List topics) { this.address = address; this.topics = topics; } - String address() { + List address() { return address; } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java index 31fb602629..4fddb0ded0 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java @@ -86,7 +86,7 @@ public class SubscriptionRequestMapper { private List hasAddresses(final LogsSubscriptionParam logFilterParams) { return logFilterParams.address() != null && !logFilterParams.address().isEmpty() - ? Arrays.asList(logFilterParams.address()) + ? logFilterParams.address() : Collections.emptyList(); } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapperTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapperTest.java index 9c13f220c1..a205890b71 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapperTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/request/SubscriptionRequestMapperTest.java @@ -150,16 +150,40 @@ public class SubscriptionRequestMapperTest { } @Test - public void mapRequestToLogs() { + public void mapRequestWithSingleAddress() { final JsonRpcRequest jsonRpcRequest = parseWebSocketRpcRequest( - "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"logs\", {\"address\": \"0x8320fe7702b96808f7bbc0d4a888ed1468216cfd\", \"topics\": [\"0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902\"]}]}"); + "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"logs\", {\"address\": \"0x8320fe7702b96808f7bbc0d4a888ed1468216cfd\"}]}"); final FilterParameter expectedFilterParam = new FilterParameter( null, null, Arrays.asList("0x8320fe7702b96808f7bbc0d4a888ed1468216cfd"), + Collections.emptyList(), + null); + final SubscribeRequest expectedSubscribeRequest = + new SubscribeRequest(SubscriptionType.LOGS, expectedFilterParam, null, null); + + final SubscribeRequest subscribeRequest = mapper.mapSubscribeRequest(jsonRpcRequest); + + assertThat(subscribeRequest) + .isEqualToComparingFieldByFieldRecursively(expectedSubscribeRequest); + } + + @Test + public void mapRequestWithMultipleAddresses() { + final JsonRpcRequest jsonRpcRequest = + parseWebSocketRpcRequest( + "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"logs\", {\"address\": [\"0x8320fe7702b96808f7bbc0d4a888ed1468216cfd\", \"0xf17f52151EbEF6C7334FAD080c5704D77216b732\"], \"topics\": [\"0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902\"]}]}"); + + final FilterParameter expectedFilterParam = + new FilterParameter( + null, + null, + Arrays.asList( + "0x8320fe7702b96808f7bbc0d4a888ed1468216cfd", + "0xf17f52151EbEF6C7334FAD080c5704D77216b732"), Arrays.asList( Arrays.asList( "0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902")), @@ -173,6 +197,31 @@ public class SubscriptionRequestMapperTest { .isEqualToComparingFieldByFieldRecursively(expectedSubscribeRequest); } + @Test + public void mapRequestWithMultipleTopics() { + final JsonRpcRequest jsonRpcRequest = + parseWebSocketRpcRequest( + "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"logs\", {\"address\": \"0x8320fe7702b96808f7bbc0d4a888ed1468216cfd\", \"topics\": [\"0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902\", \"0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab901\"]}]}"); + + final FilterParameter expectedFilterParam = + new FilterParameter( + null, + null, + Arrays.asList("0x8320fe7702b96808f7bbc0d4a888ed1468216cfd"), + Arrays.asList( + Arrays.asList( + "0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902", + "0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab901")), + null); + final SubscribeRequest expectedSubscribeRequest = + new SubscribeRequest(SubscriptionType.LOGS, expectedFilterParam, null, null); + + final SubscribeRequest subscribeRequest = mapper.mapSubscribeRequest(jsonRpcRequest); + + assertThat(subscribeRequest) + .isEqualToComparingFieldByFieldRecursively(expectedSubscribeRequest); + } + @Test public void mapRequestToLogsWithoutTopics() { final JsonRpcRequest jsonRpcRequest =