예제 #1
0
  @Override
  public Block getChainBlockByNumber(long number) {
    if (number >= index.size()) {
      return null;
    }

    List<BlockInfo> blockInfos = index.get((int) number);

    for (BlockInfo blockInfo : blockInfos) {

      if (blockInfo.isMainChain()) {

        byte[] hash = blockInfo.getHash();
        return blocks.get(hash);
      }
    }

    return null;
  }
예제 #2
0
  public List<Block> getBlocksByNumber(long number) {

    List<Block> result = new ArrayList<>();

    if (number >= index.size()) {
      return result;
    }

    List<BlockInfo> blockInfos = index.get((int) number);

    for (BlockInfo blockInfo : blockInfos) {

      byte[] hash = blockInfo.getHash();
      Block block = blocks.get(hash);

      result.add(block);
    }
    return result;
  }
예제 #3
0
 @Override
 public boolean isBlockExist(byte[] hash) {
   return blocks.get(hash) != null;
 }
예제 #4
0
 @Override
 public Block getBlockByHash(byte[] hash) {
   return blocks.get(hash);
 }