BitSharper.Sha256Hash.ToBigInteger C# (CSharp) Method

ToBigInteger() public method

Returns the bytes interpreted as a positive integer.
public ToBigInteger ( ) : BigInteger
return Org.BouncyCastle.Math.BigInteger
        public BigInteger ToBigInteger()
        {
            return new BigInteger(1, _bytes);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Returns true if the hash of the block is OK (lower than difficulty target).
        /// </summary>
        /// <exception cref="VerificationException"/>
        private bool CheckProofOfWork(bool throwException)
        {
            // This part is key - it is what proves the block was as difficult to make as it claims
            // to be. Note however that in the context of this function, the block can claim to be
            // as difficult as it wants to be .... if somebody was able to take control of our network
            // connection and fork us onto a different chain, they could send us valid blocks with
            // ridiculously easy difficulty and this function would accept them.
            //
            // To prevent this attack from being possible, elsewhere we check that the difficultyTarget
            // field is of the right value. This requires us to have the preceding blocks.
            var target = GetDifficultyTargetAsInteger();

            var h = Hash.ToBigInteger();

            if (h.CompareTo(target) > 0)
            {
                // Proof of work check failed!
                if (throwException)
                {
                    throw new VerificationException("Hash is higher than target: " + HashAsString + " vs " +
                                                    target.ToString(16));
                }
                return(false);
            }
            return(true);
        }