Copy constructors for block, block header and hash classes
authorCryptoManiac <balthazar.ad@gmail.com>
Fri, 21 Aug 2015 07:48:25 +0000 (10:48 +0300)
committerCryptoManiac <balthazar.ad@gmail.com>
Fri, 21 Aug 2015 07:48:25 +0000 (10:48 +0300)
Novacoin/CBlock.cs
Novacoin/CBlockHeader.cs
Novacoin/CTransaction.cs
Novacoin/Hash.cs
Novacoin/Hash160.cs
Novacoin/Hash256.cs
Novacoin/ScryptHash256.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>
index d85f34f..e8b257f 100644 (file)
@@ -46,6 +46,16 @@ namespace Novacoin
                {
                }
 
+        public CBlockHeader(CBlockHeader h)
+        {
+            nVersion = h.nVersion;
+            prevHash = new Hash256(h.prevHash);
+            merkleRoot = new Hash256(h.merkleRoot);
+            nTime = h.nTime;
+            nBits = h.nBits;
+            nNonce = h.nNonce;
+        }
+
         /// <summary>
         /// Convert current block header instance into sequence of bytes
         /// </summary>
index 88ea4a2..8fba084 100644 (file)
@@ -39,11 +39,11 @@ namespace Novacoin
         /// </summary>
         public CTransaction()
         {
-            vin = new CTxIn[1]; /// Any transaction must provide at least one input ...
-            vin[0] = new CTxIn();
-
-            vout = new CTxOut[1]; // ... and output.
-            vout[0] = new CTxOut();
+            // Initialize empty input and output arrays. Please note that such 
+            // configuration is not valid for real transaction, you have to supply 
+            // at least one input and one output.
+            vin = new CTxIn[0];
+            vout = new CTxOut[0];
         }
 
         /// <summary>
index 14c19d9..8cf0b55 100644 (file)
@@ -51,6 +51,11 @@ namespace Novacoin
             _hashBytes = bytes;
         }
 
+        public Hash(Hash h)
+        {
+            h._hashBytes.CopyTo(_hashBytes, 0);
+        }
+
         public bool IsZero
         {
             get { return !_hashBytes.Any(b => b != 0); }
index 7d59f5c..5b23d60 100644 (file)
@@ -25,6 +25,7 @@ namespace Novacoin
         public Hash160() : base() { }
         public Hash160(byte[] bytes) : base(bytes) { }
         public Hash160(IEnumerable<byte> bytes) : base(bytes) { }
+        public Hash160(Hash160 h) : base(h) { }
 
         public static Hash160 Compute160(IEnumerable<byte> inputBytes)
         {
index a862cd5..f571f3d 100644 (file)
@@ -23,6 +23,8 @@ namespace Novacoin
         public Hash256() : base() { }
         public Hash256(byte[] bytes) : base(bytes) { }
         public Hash256(IEnumerable<byte> bytes) : base(bytes) { }
+        public Hash256(Hash256 h) : base(h) { }
+
 
         public static Hash256 Compute256(IEnumerable<byte> inputBytes)
         {
index c479b0d..ca804fd 100644 (file)
@@ -18,6 +18,7 @@ namespace Novacoin
         public ScryptHash256() : base() { }
         public ScryptHash256(byte[] bytes) : base(bytes) { }
         public ScryptHash256(IEnumerable<byte> bytes) : base(bytes) { }
+        public ScryptHash256(ScryptHash256 h) : base(h) { }
 
         /// <summary>
         /// Calculate scrypt hash and return new instance of ScryptHash256 class