Esempio n. 1
0
        private bool CheckProofOfWork(XRCBlockHeader header)
        {
            BigInteger bits = header.Bits.ToBigInteger();

            if ((bits.CompareTo(BigInteger.Zero) <= 0) || (bits.CompareTo(pow256) >= 0))
            {
                return(false);
            }

            return(header.GetPoWHash() <= header.Bits.ToUInt256());
        }
Esempio n. 2
0
        public override void Run(RuleContext context)
        {
            if (!CheckProofOfWork((XRCBlockHeader)context.ValidationContext.ChainedHeaderToValidate.Header))
            {
                ConsensusErrors.HighHash.Throw();
            }

            Target nextWorkRequired = GetWorkRequired(
                context.ValidationContext.ChainedHeaderToValidate,
                (XRCConsensus)this.Parent.Network.Consensus);

            XRCBlockHeader header = (XRCBlockHeader)context.ValidationContext.ChainedHeaderToValidate.Header;

            // Check proof of work.
            if (header.Bits != nextWorkRequired)
            {
                this.Logger.LogTrace("(-)[BAD_DIFF_BITS]");
                ConsensusErrors.BadDiffBits.Throw();
            }
        }