b006f0dd1437cbcbd7b89ede8b69237932b6160d
[NovacoinLibrary.git] / Novacoin / CBlock.cs
1 \feffusing System;
2 using System.Collections.Generic;
3
4 namespace Novacoin
5 {
6         /// <summary>
7         /// Represents the block. Block consists of header, transaction array and header signature.
8         /// </summary>
9         public class CBlock
10         {
11                 /// <summary>
12                 /// Block header.
13                 /// </summary>
14                 public CBlockHeader header;
15
16                 /// <summary>
17                 /// Transactions array.
18                 /// </summary>
19                 public CTransaction[] tx;
20
21                 /// <summary>
22                 /// Block header signature.
23                 /// </summary>
24                 public byte[] signature;
25
26         /// <summary>
27         /// Parse byte sequence and initialize new block instance
28         /// </summary>
29         /// <param name="blockBytes"></param>
30                 public CBlock (List<byte> blockBytes)
31                 {
32             header = new CBlockHeader();
33
34             WrappedList<byte> wBytes = new WrappedList<byte>(blockBytes);
35
36             // Fill the block header fields
37             header.nVersion = Interop.LEBytesToUInt32(wBytes.GetItems(4));
38             header.prevHash = new Hash256(wBytes.GetItems(32));
39             header.merkleRoot = new Hash256(wBytes.GetItems(32));
40             header.nTime = Interop.LEBytesToUInt32(wBytes.GetItems(4));
41             header.nBits = Interop.LEBytesToUInt32(wBytes.GetItems(4));
42             header.nNonce = Interop.LEBytesToUInt32(wBytes.GetItems(4));
43
44             // Parse transactions list
45             tx = CTransaction.ReadTransactionsList(ref wBytes);
46
47             // Read block signature
48             signature = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
49                 }
50
51         public override string ToString()
52         {
53             // TODO
54             return base.ToString();
55         }
56         }
57 }
58