Coverage Summary for Class: BlockFork (co.rsk.core.bc)

Class Class, % Method, % Line, %
BlockFork 100% (1/1) 75% (3/4) 87.5% (7/8)


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.core.bc; 20  21 import org.ethereum.core.Block; 22  23 import java.util.Collections; 24 import java.util.List; 25  26 /** 27  * Created by ajlopez on 09/08/2016. 28  */ 29 public class BlockFork { 30  private final Block commonAncestor; 31  private final List<Block> oldBlocks; 32  private final List<Block> newBlocks; 33  34  public BlockFork(Block commonAncestor, List<Block> oldBlocks, List<Block> newBlocks) { 35  this.commonAncestor = commonAncestor; 36  this.oldBlocks = Collections.unmodifiableList(oldBlocks); 37  this.newBlocks = Collections.unmodifiableList(newBlocks); 38  } 39  40  /** 41  * getCommonAncestor gets the common ancestor of the two chains. 42  * @return highest block such that is an ancestor of all the blocks in oldBlocks and in newBlocks. 43  */ 44  public Block getCommonAncestor() { 45  return commonAncestor; 46  } 47  48  /** 49  * getOldBlocks returns the blocks from the old chain, not including the common ancestor. 50  * if oldBlock is the common ancestor, it won't be included in oldBlocks. 51  * @return If oldBlock is the commonAncestor: the empty list. Otherwise, it will return a list containing all chain 52  * from commonAncestor (not included) to oldBlock (included), in ascending number order. 53  */ 54  public List<Block> getOldBlocks() { 55  return oldBlocks; 56  } 57  58  /** 59  * getNewBlocks returns the blocks from the new chain, not including the common ancestor. 60  * if newBlock is the common ancestor, it won't be included in newBlocks. 61  * @return If newBlock is the commonAncestor: the empty list. Otherwise, it will return a list containing all chain 62  * from commonAncestor (not included) to newBlock (included), in ascending number order. 63  */ 64  public List<Block> getNewBlocks() { 65  return newBlocks; 66  } 67 }