Coverage Summary for Class: EthUnsubscribeRequest (co.rsk.rpc.modules.eth.subscribe)
Class |
Class, %
|
Method, %
|
Line, %
|
EthUnsubscribeRequest |
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 public class EthUnsubscribeRequest extends RskJsonRpcRequest {
31
32 private final EthUnsubscribeParams params;
33
34 @JsonCreator
35 public EthUnsubscribeRequest(
36 @JsonProperty("jsonrpc") JsonRpcVersion version,
37 @JsonProperty("method") RskJsonRpcMethod method,
38 @JsonProperty("id") int id,
39 @JsonProperty("params") EthUnsubscribeParams params) {
40 super(version, verifyMethod(method), id);
41 this.params = params;
42 }
43
44 @JsonInclude(JsonInclude.Include.NON_NULL)
45 public EthUnsubscribeParams getParams() {
46 return params;
47 }
48
49 @Override
50 public JsonRpcResultOrError accept(RskJsonRpcRequestVisitor visitor, ChannelHandlerContext ctx) {
51 return visitor.visit(this, ctx);
52 }
53
54 private static RskJsonRpcMethod verifyMethod(RskJsonRpcMethod method) {
55 if (method != RskJsonRpcMethod.ETH_UNSUBSCRIBE) {
56 throw new IllegalArgumentException(
57 "Wrong method mapped to eth_unsubscribe. Check JSON mapping configuration in JsonRpcRequest."
58 );
59 }
60
61 return method;
62 }
63 }