@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; }
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; }
@Override public boolean isBlockExist(byte[] hash) { return blocks.get(hash) != null; }
@Override public Block getBlockByHash(byte[] hash) { return blocks.get(hash); }