Copy constructors for block, block header and hash classes
[NovacoinLibrary.git] / Novacoin / CBlock.cs
index 17ffe6a..5e47b08 100644 (file)
@@ -24,6 +24,18 @@ namespace Novacoin
                /// </summary>
                public byte[] signature;
 
+        public CBlock(CBlock b)
+        {
+            header = new CBlockHeader(b.header);
+
+            for (int i = 0; i < b.vtx.Length; i++)
+            {
+                vtx[i] = new CTransaction(b.vtx[i]);
+            }
+
+            b.signature.CopyTo(signature, 0);
+        }
+
         /// <summary>
         /// Parse byte sequence and initialize new block instance
         /// </summary>
@@ -49,6 +61,14 @@ namespace Novacoin
             signature = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
                }
 
+        public CBlock()
+        {
+            // Initialize empty array of transactions. Please note that such 
+            // configuration is not valid real block since it has to provide 
+            // at least one transaction.
+            vtx = new CTransaction[0];
+        }
+
         /// <summary>
         /// Convert current instance into sequence of bytes
         /// </summary>