Implementation of operator* for uint160 and uint256.
[NovacoinLibrary.git] / Novacoin / COutPoint.cs
index a9a347c..09d0690 100644 (file)
@@ -19,6 +19,8 @@
 using System;
 using System.Collections.Generic;
 using System.Diagnostics.Contracts;
+using System.IO;
+using System.Linq;
 using System.Text;
 
 namespace Novacoin
@@ -28,7 +30,7 @@ namespace Novacoin
         /// <summary>
         /// Hash of parent transaction.
         /// </summary>
-        public Hash256 hash;
+        public uint256 hash;
 
         /// <summary>
         /// Parent input number.
@@ -42,11 +44,11 @@ namespace Novacoin
 
         public COutPoint()
         {
-            hash = new Hash256();
+            hash = new uint256();
             n = uint.MaxValue;
         }
 
-        public COutPoint(Hash256 hashIn, uint nIn)
+        public COutPoint(uint256 hashIn, uint nIn)
         {
             hash = hashIn;
             n = nIn;
@@ -54,7 +56,7 @@ namespace Novacoin
 
         public COutPoint(COutPoint o)
         {
-            hash = new Hash256(o.hash);
+            hash = o.hash;
             n = o.n;
         }
 
@@ -62,28 +64,34 @@ namespace Novacoin
         {
             Contract.Requires<ArgumentException>(bytes.Length == 36, "Any valid outpoint reference data item is exactly 36 bytes long.");
 
-            hash = new Hash256(bytes);
+            hash = bytes.Take(32).ToArray();
             n = BitConverter.ToUInt32(bytes, 32);
         }
 
         public bool IsNull
         {
-            get { return hash.IsZero && n == uint.MaxValue; }
+            get { return !hash && n == uint.MaxValue; }
         }
 
         public static implicit operator byte[] (COutPoint o)
         {
-            var r = new List<byte>();
-            r.AddRange((byte[])o.hash);
-            r.AddRange(BitConverter.GetBytes(o.n));
+            var stream = new MemoryStream();
+            var writer = new BinaryWriter(stream);
 
-            return r.ToArray();
+            writer.Write(o.hash);
+            writer.Write(o.n);
+
+            var outBytes = stream.ToArray();
+
+            writer.Close();
+
+            return outBytes;
         }
 
         public override string ToString()
         {
             var sb = new StringBuilder();
-            sb.AppendFormat("COutPoint({0}, {1})", hash.ToString(), n);
+            sb.AppendFormat("COutPoint({0}, {1})", hash, n);
 
             return sb.ToString();
         }