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

Class Class, % Method, % Line, %
RemascState 0% (0/1) 0% (0/7) 0% (0/23)


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  22 import co.rsk.core.Coin; 23 import org.ethereum.util.RLP; 24 import org.ethereum.util.RLPList; 25  26 /** 27  * DTO to send the contract state. 28  * Not production code, just used for debugging. 29  * @author Oscar Guindzberg 30  */ 31 public class RemascState { 32  private final Coin rewardBalance; 33  private final Coin burnedBalance; 34  35  private final Boolean brokenSelectionRule; 36  37  public RemascState(Coin rewardBalance, Coin burnedBalance, Boolean brokenSelectionRule) { 38  this.rewardBalance = rewardBalance; 39  this.burnedBalance = burnedBalance; 40  this.brokenSelectionRule = brokenSelectionRule; 41  } 42  43  public Coin getRewardBalance() { 44  return rewardBalance; 45  } 46  47  public Coin getBurnedBalance() { 48  return burnedBalance; 49  } 50  51  public Boolean getBrokenSelectionRule() { 52  return brokenSelectionRule; 53  } 54  55  public byte[] getEncoded() { 56  byte[] rlpRewardBalance = RLP.encodeCoin(this.rewardBalance); 57  byte[] rlpBurnedBalance = RLP.encodeCoin(this.burnedBalance); 58  byte[] rlpBrokenSelectionRule = new byte[1]; 59  60  if (brokenSelectionRule) { 61  rlpBrokenSelectionRule[0] = 1; 62  } else { 63  rlpBrokenSelectionRule[0] = 0; 64  } 65  66  // we add an empty list because Remasc state expects to have an empty siblings list after 0.5.0 activation 67  return RLP.encodeList(rlpRewardBalance, rlpBurnedBalance, RLP.encodedEmptyList(), rlpBrokenSelectionRule); 68  } 69  70  public static RemascState create(byte[] data) { 71  RLPList rlpList = (RLPList)RLP.decode2(data).get(0); 72  73  Coin rlpRewardBalance = RLP.parseCoin(rlpList.get(0).getRLPData()); 74  Coin rlpBurnedBalance = RLP.parseCoin(rlpList.get(1).getRLPData()); 75  // index 2 is ignored because it's a leftover from when we stored the Remasc siblings 76  byte[] rlpBrokenSelectionRuleBytes = rlpList.get(3).getRLPData(); 77  78  Boolean rlpBrokenSelectionRule; 79  80  if (rlpBrokenSelectionRuleBytes != null && rlpBrokenSelectionRuleBytes.length != 0 && rlpBrokenSelectionRuleBytes[0] != 0) { 81  rlpBrokenSelectionRule = Boolean.TRUE; 82  } else { 83  rlpBrokenSelectionRule = Boolean.FALSE; 84  } 85  86  return new RemascState(rlpRewardBalance, rlpBurnedBalance, rlpBrokenSelectionRule); 87  } 88  89  @Override 90  public String toString() { 91  return "RemascState{" + 92  "rewardBalance=" + rewardBalance + 93  ", burnedBalance=" + burnedBalance + 94  ", brokenSelectionRule=" + brokenSelectionRule + 95  '}'; 96  } 97 }