Use implicit type casting operator for serialization.
[NovacoinLibrary.git] / Novacoin / CBlockHeader.cs
index cc753c4..d7c1dc6 100644 (file)
  */
 
 using System;
-using System.Linq;
 using System.Text;
 using System.Collections.Generic;
 
 namespace Novacoin
 {
-       /// <summary>
-       /// Block header
-       /// </summary>
-       public class CBlockHeader
+    /// <summary>
+    /// Block header
+    /// </summary>
+    public class CBlockHeader
        {
                /// <summary>
                /// Version of block schema.
@@ -89,27 +88,24 @@ namespace Novacoin
         /// Convert current block header instance into sequence of bytes
         /// </summary>
         /// <returns>Byte sequence</returns>
-        public IList<byte> Bytes
+        public static implicit operator byte[] (CBlockHeader h)
         {
-            get
-            {
-                var r = new List<byte>();
-
-                r.AddRange(BitConverter.GetBytes(nVersion));
-                r.AddRange(prevHash.hashBytes);
-                r.AddRange(merkleRoot.hashBytes);
-                r.AddRange(BitConverter.GetBytes(nTime));
-                r.AddRange(BitConverter.GetBytes(nBits));
-                r.AddRange(BitConverter.GetBytes(nNonce));
-
-                return r;
-            }
+            var r = new List<byte>();
+
+            r.AddRange(BitConverter.GetBytes(h.nVersion));
+            r.AddRange((byte[])h.prevHash);
+            r.AddRange((byte[])h.merkleRoot);
+            r.AddRange(BitConverter.GetBytes(h.nTime));
+            r.AddRange(BitConverter.GetBytes(h.nBits));
+            r.AddRange(BitConverter.GetBytes(h.nNonce));
+
+            return r.ToArray();
         }
 
         public ScryptHash256 Hash
         {
             get {
-                return ScryptHash256.Compute256(Bytes);
+                return ScryptHash256.Compute256(this);
             }
         }