e8b257f0c2f6cd71d7336c5f188979a21bda3794
[NovacoinLibrary.git] / Novacoin / CBlockHeader.cs
1 \feffusing System;
2 using System.Text;
3 using System.Collections.Generic;
4
5 namespace Novacoin
6 {
7         /// <summary>
8         /// Block header
9         /// </summary>
10         public class CBlockHeader
11         {
12                 /// <summary>
13                 /// Version of block schema.
14                 /// </summary>
15                 public uint nVersion = 6;
16
17                 /// <summary>
18                 /// Previous block hash.
19                 /// </summary>
20                 public Hash256 prevHash = new Hash256();
21
22                 /// <summary>
23                 /// Merkle root hash.
24                 /// </summary>
25                 public Hash256 merkleRoot = new Hash256();
26
27                 /// <summary>
28                 /// Block timestamp.
29                 /// </summary>
30                 public uint nTime = 0;
31
32                 /// <summary>
33                 /// Compressed difficulty representation.
34                 /// </summary>
35                 public uint nBits = 0;
36
37                 /// <summary>
38                 /// Nonce counter.
39                 /// </summary>
40                 public uint nNonce = 0;
41
42         /// <summary>
43         /// Initialize an empty instance
44         /// </summary>
45                 public CBlockHeader ()
46                 {
47                 }
48
49         public CBlockHeader(CBlockHeader h)
50         {
51             nVersion = h.nVersion;
52             prevHash = new Hash256(h.prevHash);
53             merkleRoot = new Hash256(h.merkleRoot);
54             nTime = h.nTime;
55             nBits = h.nBits;
56             nNonce = h.nNonce;
57         }
58
59         /// <summary>
60         /// Convert current block header instance into sequence of bytes
61         /// </summary>
62         /// <returns>Byte sequence</returns>
63         public IList<byte> Bytes
64         {
65             get
66             {
67                 List<byte> r = new List<byte>();
68
69                 r.AddRange(BitConverter.GetBytes(nVersion));
70                 r.AddRange(prevHash.hashBytes);
71                 r.AddRange(merkleRoot.hashBytes);
72                 r.AddRange(BitConverter.GetBytes(nTime));
73                 r.AddRange(BitConverter.GetBytes(nBits));
74                 r.AddRange(BitConverter.GetBytes(nNonce));
75
76                 return r;
77             }
78         }
79
80         public override string ToString()
81         {
82             StringBuilder sb = new StringBuilder();
83             sb.AppendFormat("CBlockHeader(nVersion={0}, prevHash={1}, merkleRoot={2}, nTime={3}, nBits={4}, nNonce={5})", nVersion, prevHash.ToString(), merkleRoot.ToString(), nTime, nBits, nNonce);
84             return sb.ToString();
85         }
86         }
87 }