示例#1
0
        /// <summary>
        /// Check PoW and that the blocks connect correctly
        /// </summary>
        /// <param name="network">The network being used</param>
        /// <returns>True if PoW is correct</returns>
        public bool Validate(Network network)
        {
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }
            if (Block.BlockSignature)
            {
                return(BlockStake.Validate(network, this));
            }

            var genesisCorrect = Height != 0 || HashBlock == network.GetGenesis().GetHash();

            return(genesisCorrect && Validate(network.Consensus));
        }
示例#2
0
        /// <summary>
        /// Check that the header is a valid block header including the work done for PoW blocks.
        /// </summary>
        /// <param name="network">The network to verify against.</param>
        /// <returns><c>true</c> if the header is a valid block header, <c>false</c> otherwise.</returns>
        public bool Validate(Network network)
        {
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }

            if (network.Consensus.IsProofOfStake)
            {
                return(BlockStake.Validate(network, this));
            }

            bool genesisCorrect = (this.Height != 0) || this.HashBlock == network.GetGenesis().GetHash();

            return(genesisCorrect && this.Validate(network.Consensus));
        }
示例#3
0
        /// <summary>
        /// Check PoW and that the blocks connect correctly
        /// </summary>
        /// <param name="network">The network being used</param>
        /// <returns>True if PoW is correct</returns>
        public bool Validate(Network network)
        {
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }
            if (Height != 0 && Previous == null)
            {
                return(false);
            }

            if (Block.BlockSignature)
            {
                return(BlockStake.Validate(network, this));
            }

            var heightCorrect   = Height == 0 || Height == Previous.Height + 1;
            var genesisCorrect  = Height != 0 || HashBlock == network.GetGenesis().GetHash();
            var hashPrevCorrect = Height == 0 || Header.HashPrevBlock == Previous.HashBlock;
            var hashCorrect     = HashBlock == Header.GetHash();
            var workCorrect     = CheckProofOfWorkAndTarget(network);

            return(heightCorrect && genesisCorrect && hashPrevCorrect && hashCorrect && workCorrect);
        }