Remove RIPEMD160, SHA1 and SHA256 classes.
[NovacoinLibrary.git] / Novacoin / CBlock.cs
index 101d20e..a620d26 100644 (file)
@@ -47,6 +47,16 @@ namespace Novacoin
     /// </summary>
     public class CBlock
        {
+        /// <summary>
+        /// Maximum block size is 1Mb.
+        /// </summary>
+        public const uint nMaxBlockSize = 1000000;
+
+        /// <summary>
+        /// Sanity threshold for amount of sigops.
+        /// </summary>
+        public const uint nMaxSigOps = 20000;
+
                /// <summary>
                /// Block header.
                /// </summary>
@@ -92,13 +102,7 @@ namespace Novacoin
                 var reader = new BinaryReader(stream);
 
                 // Fill the block header fields
-                header = new CBlockHeader();
-                header.nVersion = reader.ReadUInt32();
-                header.prevHash = new ScryptHash256(reader.ReadBytes(32));
-                header.merkleRoot = new Hash256(reader.ReadBytes(32));
-                header.nTime = reader.ReadUInt32();
-                header.nBits = reader.ReadUInt32();
-                header.nNonce = reader.ReadUInt32();                
+                header = new CBlockHeader(ref reader);               
 
                 // Parse transactions list
                 vtx = CTransaction.ReadTransactionsList(ref reader);
@@ -128,7 +132,7 @@ namespace Novacoin
             uint nSigOps = 0; // total sigops
 
             // Basic sanity checkings
-            if (vtx.Length == 0 || Size > 1000000)
+            if (vtx.Length == 0 || Size > nMaxBlockSize)
             {
                 return false;
             }
@@ -251,7 +255,7 @@ namespace Novacoin
             }
 
             // Reject block if validation would consume too much resources.
-            if (nSigOps > 50000)
+            if (nSigOps > nMaxSigOps)
             {
                 return false;
             }
@@ -422,7 +426,7 @@ namespace Novacoin
                         var left = merkleTree.GetRange((levelOffset + nLeft) * 32, 32).ToArray();
                         var right = merkleTree.GetRange((levelOffset + nRight) * 32, 32).ToArray();
 
-                        merkleTree.AddRange(Hash256.ComputeRaw256(ref left, ref right));
+                        merkleTree.AddRange(CryptoUtils.ComputeHash256(ref left, ref right));
                     }
                     levelOffset += nLevelSize;
                 }