Coverage Summary for Class: EthSubscribeRequest (co.rsk.rpc.modules.eth.subscribe)
Class |
Class, %
|
Method, %
|
Line, %
|
EthSubscribeRequest |
0%
(0/1)
|
0%
(0/4)
|
0%
(0/7)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2018 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 package co.rsk.rpc.modules.eth.subscribe;
19
20 import co.rsk.jsonrpc.JsonRpcResultOrError;
21 import co.rsk.jsonrpc.JsonRpcVersion;
22 import co.rsk.rpc.modules.RskJsonRpcMethod;
23 import co.rsk.rpc.modules.RskJsonRpcRequest;
24 import co.rsk.rpc.modules.RskJsonRpcRequestVisitor;
25 import com.fasterxml.jackson.annotation.JsonCreator;
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import io.netty.channel.ChannelHandlerContext;
29
30 import java.util.Objects;
31
32 public class EthSubscribeRequest extends RskJsonRpcRequest {
33
34 private final EthSubscribeParams params;
35
36 @JsonCreator
37 public EthSubscribeRequest(
38 @JsonProperty("jsonrpc") JsonRpcVersion version,
39 @JsonProperty("method") RskJsonRpcMethod method,
40 @JsonProperty("id") Integer id,
41 @JsonProperty("params") EthSubscribeParams params) {
42 super(version, verifyMethod(method), Objects.requireNonNull(id));
43 this.params = Objects.requireNonNull(params);
44 }
45
46 @JsonInclude(JsonInclude.Include.NON_NULL)
47 public EthSubscribeParams getParams() {
48 return params;
49 }
50
51 @Override
52 public JsonRpcResultOrError accept(RskJsonRpcRequestVisitor visitor, ChannelHandlerContext ctx) {
53 return visitor.visit(this, ctx);
54 }
55
56 private static RskJsonRpcMethod verifyMethod(RskJsonRpcMethod method) {
57 if (method != RskJsonRpcMethod.ETH_SUBSCRIBE) {
58 throw new IllegalArgumentException(
59 "Wrong method mapped to eth_subscribe. Check JSON mapping configuration in JsonRpcRequest."
60 );
61 }
62
63 return method;
64 }
65 }