Coverage Summary for Class: SiblingPaymentCalculator (co.rsk.remasc)

Class Class, % Method, % Line, %
SiblingPaymentCalculator 0% (0/1) 0% (0/6) 0% (0/18)


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.remasc; 20  21 import co.rsk.config.RemascConfig; 22 import co.rsk.core.Coin; 23  24 import javax.annotation.Nullable; 25 import java.math.BigInteger; 26  27 /** 28  * Created by mario on 09/01/17. 29  */ 30 public class SiblingPaymentCalculator { 31  32  private final Coin individualPublisherReward; 33  private final Coin publishersSurplus; 34  private final Coin individualMinerReward; 35  private final Coin minersSurplus; 36  private final Coin punishment; 37  38  public SiblingPaymentCalculator(Coin fullBlockReward, boolean brokenSelectionRule, long siblingsNumber, RemascConfig remascConstants) { 39  Coin publishersReward = fullBlockReward.divide(BigInteger.valueOf(remascConstants.getPublishersDivisor())); 40  Coin minersReward = fullBlockReward.subtract(publishersReward); 41  Coin[] integerDivisionResult = publishersReward.divideAndRemainder(BigInteger.valueOf(siblingsNumber)); 42  this.individualPublisherReward = integerDivisionResult[0]; 43  this.publishersSurplus = integerDivisionResult[1]; 44  45  Coin[] individualRewardDivisionResult = minersReward.divideAndRemainder(BigInteger.valueOf(siblingsNumber + 1L)); 46  this.minersSurplus = individualRewardDivisionResult[1]; 47  if (brokenSelectionRule) { 48  this.punishment = individualRewardDivisionResult[0].divide(BigInteger.valueOf(remascConstants.getPunishmentDivisor())); 49  this.individualMinerReward = individualRewardDivisionResult[0].subtract(punishment); 50  } else { 51  this.punishment = null; 52  this.individualMinerReward = individualRewardDivisionResult[0]; 53  } 54  } 55  56  public Coin getIndividualPublisherReward() { 57  return individualPublisherReward; 58  } 59  60  public Coin getPublishersSurplus() { 61  return publishersSurplus; 62  } 63  64  public Coin getIndividualMinerReward() { 65  return individualMinerReward; 66  } 67  68  public Coin getMinersSurplus() { 69  return minersSurplus; 70  } 71  72  @Nullable 73  public Coin getPunishment() { 74  return punishment; 75  } 76 }