Example #1
0
        private string EncodeTarget(double difficulty)
        {
            var diff     = BigInteger.ValueOf((long)(difficulty * 255d));
            var quotient = ZCashConstants.Diff1.Divide(diff).Multiply(BigInteger.ValueOf(255));
            var bytes    = quotient.ToByteArray();
            var padded   = ArrayPool <byte> .Shared.Rent(ZCashConstants.TargetPaddingLength);

            try
            {
                Array.Clear(padded, 0, ZCashConstants.TargetPaddingLength);
                var padLength = ZCashConstants.TargetPaddingLength - bytes.Length;

                if (padLength > 0)
                {
                    Array.Copy(bytes, 0, padded, padLength, bytes.Length);
                    bytes = padded;
                }

                var result = bytes.ToHexString(0, ZCashConstants.TargetPaddingLength);
                return(result);
            }

            finally
            {
                ArrayPool <byte> .Shared.Return(padded);
            }
        }
Example #2
0
        private string EncodeTarget(double difficulty)
        {
            var diff     = BigInteger.ValueOf((long)(difficulty * 255d));
            var quotient = ZCashConstants.Diff1.Divide(diff).Multiply(BigInteger.ValueOf(255));
            var bytes    = quotient.ToByteArray();
            var padded   = Enumerable.Repeat((byte)0, 32).ToArray();

            if (padded.Length - bytes.Length > 0)
            {
                Buffer.BlockCopy(bytes, 0, padded, padded.Length - bytes.Length, bytes.Length);
                bytes = padded;
            }

            var result = bytes.ToHexString();

            return(result);
        }