Replace ref with out in the stake modifier calculation method.
[NovacoinLibrary.git] / Novacoin / COutPoint.cs
index 09d0690..07c6552 100644 (file)
@@ -25,7 +25,7 @@ using System.Text;
 
 namespace Novacoin
 {
-    public class COutPoint : IComparable<COutPoint>, IEquatable<COutPoint>
+    public class COutPoint : IComparable<COutPoint>, IEquatable<COutPoint>, IEqualityComparer<COutPoint>
     {
         /// <summary>
         /// Hash of parent transaction.
@@ -88,6 +88,11 @@ namespace Novacoin
             return outBytes;
         }
 
+        public static implicit operator COutPoint(byte[] b)
+        {
+            return new COutPoint(b);
+        }
+
         public override string ToString()
         {
             var sb = new StringBuilder();
@@ -123,8 +128,34 @@ namespace Novacoin
         /// <returns>Result of comparison.</returns>
         public bool Equals(COutPoint o)
         {
+            if (object.ReferenceEquals(o, null))
+            {
+                return false;
+            }
+
             return (o.n == n) && (o.hash == hash);
         }
+
+        /// <summary>
+        /// Equality comparer for outpoints.
+        /// </summary>
+        /// <param name="x">First outpoint.</param>
+        /// <param name="y">Second outpoint.</param>
+        /// <returns>Result of comparison.</returns>
+        public bool Equals(COutPoint x, COutPoint y)
+        {
+            return (x.n == y.n) && (x.hash == y.hash);
+        }
+
+        public override int GetHashCode()
+        {
+            return n.GetHashCode() ^ hash.GetHashCode();
+        }
+
+        public int GetHashCode(COutPoint obj)
+        {
+            return obj.GetHashCode();
+        }
     }
 
 }