mirror of https://github.com/hyperledger/besu
Rework how filter and log query parameters are created/used (#146)
* Rework how filter and log query parameters are created/used We used a `FilterParameter` that held strings in places where we could create strongly typed objects. We also used it in places where we only wanted a subset of its descriptiveness, namely, the `LogsQuery` part of it. * deserialize directly into `LogsQuery`, which is useful for log pub/sub * narrow uses of `FilterParameter` to `LogsQuery` where possible * make `FilterParameter` hold strongly typed `Address`s and `LogTopic`s Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>pull/133/head
parent
a07b450663
commit
a48a2de7f5
@ -1,44 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright ConsenSys AG. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
|
||||||
* the License. You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
|
||||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
|
||||||
* specific language governing permissions and limitations under the License. |
|
||||||
* |
|
||||||
* SPDX-License-Identifier: Apache-2.0 |
|
||||||
*/ |
|
||||||
package org.hyperledger.besu.ethereum.api.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 List<String> address; |
|
||||||
private final List<String> topics; |
|
||||||
|
|
||||||
@JsonCreator |
|
||||||
LogsSubscriptionParam( |
|
||||||
@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; |
|
||||||
} |
|
||||||
|
|
||||||
List<String> address() { |
|
||||||
return address; |
|
||||||
} |
|
||||||
|
|
||||||
List<String> topics() { |
|
||||||
return topics; |
|
||||||
} |
|
||||||
} |
|
@ -1,53 +0,0 @@ |
|||||||
/* |
|
||||||
* |
|
||||||
* Copyright ConsenSys AG. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
|
||||||
* the License. You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
|
||||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
|
||||||
* specific language governing permissions and limitations under the License. |
|
||||||
* |
|
||||||
* SPDX-License-Identifier: Apache-2.0 |
|
||||||
* |
|
||||||
*/ |
|
||||||
package org.hyperledger.besu.ethereum.api.query; |
|
||||||
|
|
||||||
import org.hyperledger.besu.ethereum.core.LogTopic; |
|
||||||
import org.hyperledger.besu.util.bytes.BytesValue; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
public class TopicsParameter { |
|
||||||
|
|
||||||
private final List<List<LogTopic>> queryTopics = new ArrayList<>(); |
|
||||||
|
|
||||||
public TopicsParameter(final List<List<String>> topics) { |
|
||||||
if (topics != null) { |
|
||||||
for (final List<String> list : topics) { |
|
||||||
final List<LogTopic> inputTopics = new ArrayList<>(); |
|
||||||
if (list != null) { |
|
||||||
for (final String input : list) { |
|
||||||
final LogTopic topic = |
|
||||||
input != null ? LogTopic.create(BytesValue.fromHexString(input)) : null; |
|
||||||
inputTopics.add(topic); |
|
||||||
} |
|
||||||
} |
|
||||||
queryTopics.add(inputTopics); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public List<List<LogTopic>> getTopics() { |
|
||||||
return queryTopics; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return "TopicsParameter{" + "queryTopics=" + queryTopics + '}'; |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue