Coverage Summary for Class: EthSubscribeLogsParams (co.rsk.rpc.modules.eth.subscribe)
Class |
Class, %
|
Method, %
|
Line, %
|
EthSubscribeLogsParams |
0%
(0/1)
|
0%
(0/7)
|
0%
(0/11)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2019 RSK Labs Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package co.rsk.rpc.modules.eth.subscribe;
20
21 import co.rsk.core.RskAddress;
22 import com.fasterxml.jackson.annotation.JsonCreator;
23 import com.fasterxml.jackson.annotation.JsonFormat;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
26 import io.netty.channel.Channel;
27 import org.ethereum.rpc.Topic;
28
29 import java.util.Arrays;
30
31 @JsonDeserialize
32 public class EthSubscribeLogsParams implements EthSubscribeParams {
33
34 private final RskAddress[] addresses;
35 private final String[] fromBlock;
36 private final Topic[][] topics;
37 private final String[] toBlock;
38
39 public EthSubscribeLogsParams() {
40 this(new RskAddress[0], new String[0], new String[0], new Topic[0][]);
41 }
42
43 @JsonCreator
44 public EthSubscribeLogsParams(
45 @JsonProperty("address") @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) RskAddress[] addresses,
46 @JsonProperty("fromBlock") @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) String[] fromBlock,
47 @JsonProperty("toBlock") @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) String[] toBlock,
48 @JsonProperty("topics") @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) Topic[][] topics
49 ) {
50 this.addresses = addresses == null? new RskAddress[0]: addresses;
51 this.fromBlock = fromBlock == null? new String[0]: fromBlock;
52 this.toBlock = fromBlock == null? new String[0]: toBlock;
53 this.topics = topics == null? new Topic[0][]: topics;
54 }
55
56 public RskAddress[] getAddresses() {
57 return Arrays.copyOf(addresses, addresses.length);
58 }
59
60 public String[] getFromBlock(){
61 return Arrays.copyOf(fromBlock, fromBlock.length);
62 }
63
64 public String[] getToBlock(){
65 return Arrays.copyOf(toBlock, toBlock.length);
66 }
67
68 public Topic[][] getTopics() {
69 // TODO(mc) deep copy
70 return Arrays.copyOf(topics, topics.length);
71 }
72
73 @Override
74 public SubscriptionId accept(EthSubscribeParamsVisitor visitor, Channel channel) {
75 return visitor.visit(this, channel);
76 }
77 }