예제 #1
0
 @Override
 public void flush() {
   blocks.flush();
   index.flush();
   if (blocksDS instanceof Flushable) {
     ((Flushable) blocksDS).flush();
   }
   if (indexDS instanceof Flushable) {
     ((Flushable) indexDS).flush();
   }
 }
예제 #2
0
  private void addInternalBlock(Block block, BigInteger cummDifficulty, boolean mainChain) {

    List<BlockInfo> blockInfos =
        block.getNumber() >= index.size()
            ? new ArrayList<BlockInfo>()
            : index.get((int) block.getNumber());

    BlockInfo blockInfo = new BlockInfo();
    blockInfo.setCummDifficulty(cummDifficulty);
    blockInfo.setHash(block.getHash());
    blockInfo.setMainChain(
        mainChain); // FIXME:maybe here I should force reset main chain for all uncles on that level

    blockInfos.add(blockInfo);
    index.set((int) block.getNumber(), blockInfos);

    blocks.put(block.getHash(), block);
  }
예제 #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<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;
  }
예제 #5
0
 @Override
 public boolean isBlockExist(byte[] hash) {
   return blocks.get(hash) != null;
 }
예제 #6
0
 @Override
 public Block getBlockByHash(byte[] hash) {
   return blocks.get(hash);
 }