class SnapshotManager {

    public boolean revertToSnapshot(int snapshotId) {
        if (snapshotId <= 0 || snapshotId > this.snapshots.size()) {
            return false;
        }

        long newBestBlockNumber = this.snapshots.get(snapshotId - 1);

        this.snapshots = this.snapshots.stream().limit(snapshotId).collect(Collectors.toList());

        long currentBestBlockNumber = blockchain.getBestBlock().getNumber();

        if (newBestBlockNumber >= currentBestBlockNumber) {
            return true;
        }

        BlockStore store = blockchain.getBlockStore();

        Block block = store.getChainBlockByNumber(newBestBlockNumber);
        BlockDifficulty difficulty = blockchain.getBlockStore().getTotalDifficultyForHash(block.getHash().getBytes());

        blockchain.setStatus(block, difficulty);

        // To clean pending state, first process the fork
        transactionPool.processBest(block);
        // then, clear any reverted transaction
        transactionPool.removeTransactions(transactionPool.getPendingTransactions());
        transactionPool.removeTransactions(transactionPool.getQueuedTransactions());

        // Remove removed blocks from store
        for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= currentBestBlockNumber; nb++) {
            blockchain.removeBlocksByNumber(nb);
        }

        return true;
    }

    public  SnapshotManager(Blockchain blockchain, TransactionPool transactionPool);

}