4 using System.Collections.Generic;
11 public class CBlockHeader
14 /// Version of block schema.
16 public uint nVersion = 6;
19 /// Previous block hash.
21 public Hash256 prevHash = new Hash256();
26 public Hash256 merkleRoot = new Hash256();
31 public uint nTime = 0;
34 /// Compressed difficulty representation.
36 public uint nBits = 0;
41 public uint nNonce = 0;
44 /// Initialize an empty instance
46 public CBlockHeader ()
50 public CBlockHeader(CBlockHeader h)
52 nVersion = h.nVersion;
53 prevHash = new Hash256(h.prevHash);
54 merkleRoot = new Hash256(h.merkleRoot);
60 public CBlockHeader(byte[] bytes)
62 nVersion = BitConverter.ToUInt32(bytes, 0);
63 prevHash = new Hash256(bytes, 4);
64 merkleRoot = new Hash256(bytes, 36);
65 nTime = BitConverter.ToUInt32(bytes, 68);
66 nBits = BitConverter.ToUInt32(bytes, 72);
67 nNonce = BitConverter.ToUInt32(bytes, 76);
71 /// Convert current block header instance into sequence of bytes
73 /// <returns>Byte sequence</returns>
74 public IList<byte> Bytes
78 List<byte> r = new List<byte>();
80 r.AddRange(BitConverter.GetBytes(nVersion));
81 r.AddRange(prevHash.hashBytes);
82 r.AddRange(merkleRoot.hashBytes);
83 r.AddRange(BitConverter.GetBytes(nTime));
84 r.AddRange(BitConverter.GetBytes(nBits));
85 r.AddRange(BitConverter.GetBytes(nNonce));
91 public ScryptHash256 Hash
94 return ScryptHash256.Compute256(Bytes);
98 public override string ToString()
100 StringBuilder sb = new StringBuilder();
101 sb.AppendFormat("CBlockHeader(nVersion={0}, prevHash={1}, merkleRoot={2}, nTime={3}, nBits={4}, nNonce={5})", nVersion, prevHash.ToString(), merkleRoot.ToString(), nTime, nBits, nNonce);
102 return sb.ToString();