ToInt64 -> ToUInt64
[NovacoinLibrary.git] / Novacoin / COutPoint.cs
index be3017f..9d1dbb5 100644 (file)
@@ -18,6 +18,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.Contracts;
 using System.Text;
 
 namespace Novacoin
@@ -34,6 +35,11 @@ namespace Novacoin
         /// </summary>
         public uint n;
 
+        /// <summary>
+        /// Out reference is always 36 bytes long.
+        /// </summary>
+        public const int Size = 36;
+
         public COutPoint()
         {
             hash = new Hash256();
@@ -54,6 +60,8 @@ namespace Novacoin
 
         public COutPoint(byte[] bytes)
         {
+            Contract.Requires<ArgumentException>(bytes.Length == 36, "Any valid outpoint reference data item is exactly 36 bytes long.");
+
             hash = new Hash256(bytes);
             n = BitConverter.ToUInt32(bytes, 32);
         }
@@ -63,16 +71,13 @@ namespace Novacoin
             get { return hash.IsZero && n == uint.MaxValue; }
         }
 
-        public IList<byte> Bytes
+        public static implicit operator byte[] (COutPoint o)
         {
-            get
-            {
-                var r = new List<byte>();
-                r.AddRange(hash.hashBytes);
-                r.AddRange(BitConverter.GetBytes(n));
-
-                return r;
-            }
+            var r = new List<byte>();
+            r.AddRange((byte[])o.hash);
+            r.AddRange(BitConverter.GetBytes(o.n));
+
+            return r.ToArray();
         }
 
         public override string ToString()