Example #1
0
        void LoadImageHeaderchain(string pathImage)
        {
            string pathFile = Path.Combine(
                pathImage, "ImageHeaderchain");

            var blockParser = new UTXOTable.BlockParser();

            int indexBytesHeaderImage = 0;

            byte[] bytesHeaderImage = File.ReadAllBytes(pathFile);

            Header headerPrevious = HeaderGenesis;

            while (indexBytesHeaderImage < bytesHeaderImage.Length)
            {
                Header header = blockParser.ParseHeader(
                    bytesHeaderImage,
                    ref indexBytesHeaderImage);

                if (!header.HashPrevious.IsEqual(
                        headerPrevious.Hash))
                {
                    throw new ProtocolException(
                              "Header image does not link to genesis header.");
                }

                header.HeaderPrevious = headerPrevious;

                ValidateHeader(
                    header,
                    Height + 1);

                InsertHeader(header);

                headerPrevious = header;
            }
        }