예제 #1
0
 public override string ToString()
 {
     return($"Hash     :{BitConverter.ToString(Hash.ToArray()).Replace("-", "")}\n" +
            $"Pre Hash :{BitConverter.ToString(PreviousHash.ToArray()).Replace("-", "")}\n" +
            $"Nonce    :{Nonce}\n" +
            $"Timestamp:{Timestamp:yyyy/MM/dd HH:mm:ss.fff}\n\r");
 }
예제 #2
0
        /// <summary>
        /// Gets <see cref="Bencodex.Types.Dictionary"/> representation of
        /// <see cref="BlockHeader"/>.
        /// </summary>
        /// <returns><see cref="Bencodex.Types.Dictionary"/> representation of
        /// <see cref="BlockHeader"/>.</returns>
        public Bencodex.Types.Dictionary ToBencodex()
        {
            var dict = Bencodex.Types.Dictionary.Empty
                       .Add(IndexKey, Index)
                       .Add(TimestampKey, Timestamp)
                       .Add(DifficultyKey, Difficulty)
                       .Add(TotalDifficultyKey, (IValue)(Bencodex.Types.Integer)TotalDifficulty)
                       .Add(NonceKey, Nonce.ToArray())
                       .Add(HashKey, Hash.ToArray());

            if (Miner.Any())
            {
                dict = dict.Add(MinerKey, Miner.ToArray());
            }

            if (PreviousHash.Any())
            {
                dict = dict.Add(PreviousHashKey, PreviousHash.ToArray());
            }

            if (TxHash.Any())
            {
                dict = dict.Add(TxHashKey, TxHash.ToArray());
            }

            return(dict);
        }
예제 #3
0
        public List <byte> GenerateHash()
        {
            var sha256 = new SHA256Managed();

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream))
                {
                    writer.Write(Data.ToBytesArray());
                    writer.Write(Nonce);
                    writer.Write(Timestamp.ToBinary());
                    writer.Write(PreviousHash.ToArray());
                    var streamArray = stream.ToArray();
                    return(sha256.ComputeHash(streamArray).ToList());
                }
            }
        }