Esempio n. 1
0
 @Override
 public void flush() {
   blocks.flush();
   index.flush();
   if (blocksDS instanceof Flushable) {
     ((Flushable) blocksDS).flush();
   }
   if (indexDS instanceof Flushable) {
     ((Flushable) indexDS).flush();
   }
 }
Esempio n. 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);
  }
Esempio n. 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;
  }
Esempio n. 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;
  }
Esempio n. 5
0
 @Override
 public boolean isBlockExist(byte[] hash) {
   return blocks.get(hash) != null;
 }
Esempio n. 6
0
 @Override
 public Block getBlockByHash(byte[] hash) {
   return blocks.get(hash);
 }