Coverage Summary for Class: JsonRpcMessage (co.rsk.jsonrpc)
Class |
Class, %
|
Method, %
|
Line, %
|
JsonRpcMessage |
0%
(0/1)
|
0%
(0/3)
|
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.jsonrpc;
19
20 import com.fasterxml.jackson.annotation.JsonInclude;
21 import com.fasterxml.jackson.annotation.JsonProperty;
22 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
23
24 /**
25 * The basic JSON-RPC 2.0 message.
26 *
27 * It defines the version property, which should always be '2.0'.
28 */
29 @JsonPropertyOrder({"jsonrpc", "id", "method", "result", "params", "error"})
30 public abstract class JsonRpcMessage {
31 private final JsonRpcVersion version;
32
33 public JsonRpcMessage(JsonRpcVersion version) {
34 this.version = verifyVersion(version);
35 }
36
37 @JsonProperty("jsonrpc")
38 @JsonInclude(JsonInclude.Include.ALWAYS)
39 public JsonRpcVersion getVersion() {
40 return version;
41 }
42
43 private static JsonRpcVersion verifyVersion(JsonRpcVersion version) {
44 if (version != JsonRpcVersion.V2_0) {
45 throw new IllegalArgumentException(
46 String.format("JSON-RPC version should always be %s, but was %s.", JsonRpcVersion.V2_0, version)
47 );
48 }
49
50 return version;
51 }
52 }