Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Supporting list of addresses in logs subscription #336

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@
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<String> address;
private final List<String> topics;

@JsonCreator
LogsSubscriptionParam(
@JsonProperty("address") final String address,
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) @JsonProperty("address")
final List<String> address,
@JsonProperty("topics") final List<String> topics) {
this.address = address;
this.topics = topics;
}

String address() {
List<String> address() {
return address;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private FilterParameter createFilterParameter(final LogsSubscriptionParam logFil

private List<String> hasAddresses(final LogsSubscriptionParam logFilterParams) {
return logFilterParams.address() != null && !logFilterParams.address().isEmpty()
? Arrays.asList(logFilterParams.address())
? logFilterParams.address()
: Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,40 @@ public void mapRequestToNewHeadsIgnoresThirdParam() {
}

@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")),
Expand All @@ -173,6 +197,31 @@ public void mapRequestToLogs() {
.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 =
Expand Down