Class BlockFileLoader

  • All Implemented Interfaces:
    java.lang.Iterable<Block>, java.util.Iterator<Block>

    public class BlockFileLoader
    extends java.lang.Object
    implements java.lang.Iterable<Block>, java.util.Iterator<Block>

    This class reads block files stored in the Bitcoin Core format. This is simply a way to concatenate blocks together. Importing block data with this tool can be a lot faster than syncing over the network, if you have the files available.

    In order to comply with Iterator, this class swallows a lot of IOExceptions, which may result in a few blocks being missed followed by a huge set of orphan blocks.

    To blindly import all files which can be found in Bitcoin Core (version 0.8 or higher) datadir automatically, try this code fragment: BlockFileLoader loader = new BlockFileLoader(BlockFileLoader.getReferenceClientBlockFileList()); for (Block block : loader) { try { chain.add(block); } catch (Exception e) { } }

    • Constructor Detail

      • BlockFileLoader

        public BlockFileLoader​(NetworkParameters params,
      • BlockFileLoader

        public BlockFileLoader​(NetworkParameters params,
                               java.util.List<> files)
    • Method Detail

      • getReferenceClientBlockFileList

        public static java.util.List<> getReferenceClientBlockFileList​( blocksDir)
        Gets the list of files which contain blocks from Bitcoin Core.
      • getReferenceClientBlockFileList

        public static java.util.List<> getReferenceClientBlockFileList()
      • defaultBlocksDir

        public static defaultBlocksDir()
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<Block>
      • next

        public Block next()
                   throws java.util.NoSuchElementException
        Specified by:
        next in interface java.util.Iterator<Block>
      • remove

        public void remove()
                    throws java.lang.UnsupportedOperationException
        Specified by:
        remove in interface java.util.Iterator<Block>
      • iterator

        public java.util.Iterator<Block> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Block>