示例#1
0
  @Override
  public BigInteger getTotalDifficulty() {
    long maxNumber = getMaxNumber();

    List<BlockInfo> blockInfos = index.get((int) maxNumber);
    for (BlockInfo blockInfo : blockInfos) {
      if (blockInfo.isMainChain()) {
        return blockInfo.getCummDifficulty();
      }
    }

    while (true) {
      --maxNumber;
      List<BlockInfo> infos = getBlockInfoForLevel(maxNumber);

      for (BlockInfo blockInfo : infos) {
        if (blockInfo.isMainChain()) {
          return blockInfo.getCummDifficulty();
        }
      }
    }
  }
示例#2
0
  public void printChain() {

    Long number = getMaxNumber();

    for (int i = 0; i < number; ++i) {
      List<BlockInfo> levelInfos = index.get(i);

      if (levelInfos != null) {
        System.out.print(i);
        for (BlockInfo blockInfo : levelInfos) {
          if (blockInfo.isMainChain())
            System.out.print(" [" + shortHash(blockInfo.getHash()) + "] ");
          else System.out.print(" " + shortHash(blockInfo.getHash()) + " ");
        }
        System.out.println();
      }
    }
  }
示例#3
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;
  }
示例#4
0
  public List<byte[]> getListHashesStartWith(long number, long maxBlocks) {

    List<byte[]> result = new ArrayList<>();

    int i;
    for (i = 0; i < maxBlocks; ++i) {
      List<BlockInfo> blockInfos = index.get((int) number);
      if (blockInfos == null) break;

      for (BlockInfo blockInfo : blockInfos)
        if (blockInfo.isMainChain()) {
          result.add(blockInfo.getHash());
          break;
        }

      ++number;
    }
    maxBlocks -= i;

    return result;
  }