Exemplo n.º 1
0
        public Block_Disk getNext()
        {
            while (fs.Position < fs.Length)
            {
                Block_Disk b;
                b = Block_Disk.FromStream(fs);

                if (b.blockSize == 0)
                {
                    blockFileNum++;
                    try
                    {
                        fs.Close();
                        fs = new FileStream(@"C:\Users\Administrator\AppData\Roaming\Bitcoin\blocks\blk" + blockFileNum.ToString("D5") + ".dat", FileMode.Open);
                    }
                    catch (FileNotFoundException)
                    {
                        return(null);
                    }
                    continue;
                }

                return(b);
            }

            return(null);
        }
        /// <summary>
        /// Reads a block disk into the <seealso cref="Block_Disk">Block_Disk</seealso> structure from the active filestream and opens the next blockfile.
        /// </summary>
        /// <param name="file">Name of the blockchain datafile.</param>
        /// <param name="path">Location of the blockchain datafile(s).</param>
        /// <returns>A <seealso cref="Block_Disk"/>Block_Disk</seealso> structure containing the contents of the blockfile.</returns>
        /// <remarks>
        /// Pass an empty String or null value to initialize the file or path value with the defaults.
        /// </remarks>
        public Block_Disk getNext(String file, String path)
        {
            if (String.IsNullOrWhiteSpace(file))
            {
                file = this._blockFileName;
            }
            if (String.IsNullOrWhiteSpace(path))
            {
                path = this._blockFilePath;
            }

            while (this._fileStream.Position < this._fileStream.Length)
            {
                Block_Disk _block;
                _block = Block_Disk.FromStream(this._fileStream);

                if (_block.blockSize == 0)
                {
                    this.blockFileNum++;
                    try
                    {
                        this._fileStream.Close();
                        String _fullPath = System.IO.Path.Combine(path, file);
                        this._fileStream = new FileStream(_fullPath, FileMode.Open);
                    }
                    catch (FileNotFoundException)
                    {
                        return(null);
                    }
                    continue;
                }

                return(_block);
            }

            return(null);
        }