Coverage Summary for Class: EthVersion (org.ethereum.net.eth)
Class |
Class, %
|
Method, %
|
Line, %
|
EthVersion |
0%
(0/1)
|
0%
(0/7)
|
0%
(0/20)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package org.ethereum.net.eth;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 /**
26 * Represents supported Eth versions
27 *
28 * @author Mikhail Kalinin
29 * @since 14.08.2015
30 */
31 public enum EthVersion {
32
33 V62((byte) 62);
34
35 public static final byte LOWER = V62.getCode();
36 public static final byte UPPER = V62.getCode();
37
38 private byte code;
39
40 EthVersion(byte code) {
41 this.code = code;
42 }
43
44 public byte getCode() {
45 return code;
46 }
47
48 public static EthVersion fromCode(int code) {
49 for (EthVersion v : values()) {
50 if (v.code == code) {
51 return v;
52 }
53 }
54
55 return null;
56 }
57
58 public static boolean isSupported(byte code) {
59 return code >= LOWER && code <= UPPER;
60 }
61
62 public static List<EthVersion> supported() {
63 List<EthVersion> supported = new ArrayList<>();
64 for (EthVersion v : values()) {
65 if (isSupported(v.code)) {
66 supported.add(v);
67 }
68 }
69
70 return supported;
71 }
72
73 public boolean isCompatible(EthVersion version) {
74
75 if (version.getCode() >= V62.getCode()) {
76 return this.getCode() >= V62.getCode();
77 } else {
78 return this.getCode() < V62.getCode();
79 }
80 }
81 }