Coverage Summary for Class: BlockGasPriceRange (co.rsk.mine)
Class |
Class, %
|
Method, %
|
Line, %
|
BlockGasPriceRange |
0%
(0/1)
|
0%
(0/5)
|
0%
(0/10)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 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.mine;
20
21 import co.rsk.core.Coin;
22
23 import java.math.BigInteger;
24
25 /**
26 * Created by mario on 26/12/16.
27 */
28 public class BlockGasPriceRange {
29
30 private static final BigInteger VARIATION_PERCENTAGE_RANGE = BigInteger.ONE;
31
32 private final Coin upperLimit;
33 private final Coin lowerLimit;
34
35 public BlockGasPriceRange(Coin center) {
36 Coin mgpDelta = center.multiply(VARIATION_PERCENTAGE_RANGE).divide(BigInteger.valueOf(100));
37 mgpDelta = mgpDelta.equals(Coin.ZERO) ? Coin.valueOf(1L) : mgpDelta;
38 Coin candidateLower = center.subtract(mgpDelta);
39 this.upperLimit = center.add(mgpDelta);
40 this.lowerLimit = candidateLower.compareTo(Coin.ZERO) < 0 ? Coin.ZERO : candidateLower;
41 }
42
43 public boolean inRange(Coin mgp) {
44 return mgp.compareTo(upperLimit) <= 0 && mgp.compareTo(lowerLimit) >= 0;
45 }
46
47 public Coin getUpperLimit() {
48 return upperLimit;
49 }
50
51 public Coin getLowerLimit() {
52 return lowerLimit;
53 }
54 }