Solver bug fixes
authorCryptoManiac <balthazar@yandex.ru>
Thu, 20 Aug 2015 17:28:03 +0000 (20:28 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Thu, 20 Aug 2015 17:28:03 +0000 (20:28 +0300)
Novacoin/Hash.cs
Novacoin/Hash160.cs
Novacoin/Hash256.cs
Novacoin/ScriptCode.cs
Novacoin/ScryptHash256.cs
NovacoinTest/Program.cs

index 954e5f4..4944b30 100644 (file)
@@ -41,14 +41,14 @@ namespace Novacoin
         /// Initializes a new instance of Hash class with first 20 bytes from supplied list
         /// </summary>
         /// <param name="bytesList">List of bytes</param>
-        public Hash(IList<byte> bytesList)
+        public Hash(IEnumerable<byte> bytes)
         {
-            _hashBytes = bytesList.Take<byte>(hashSize).ToArray<byte>();
+            _hashBytes = bytes.Take<byte>(hashSize).ToArray<byte>();
         }
 
-        public Hash(byte[] bytesArray)
+        public Hash(byte[] bytes)
         {
-            _hashBytes = bytesArray;
+            _hashBytes = bytes;
         }
 
         public bool IsZero()
index c11c7b0..7d59f5c 100644 (file)
@@ -23,8 +23,8 @@ namespace Novacoin
         }
 
         public Hash160() : base() { }
-        public Hash160(byte[] bytesArray) : base(bytesArray) { }
-        public Hash160(IList<byte> bytesList) : base(bytesList) { }
+        public Hash160(byte[] bytes) : base(bytes) { }
+        public Hash160(IEnumerable<byte> bytes) : base(bytes) { }
 
         public static Hash160 Compute160(IEnumerable<byte> inputBytes)
         {
index c2e4645..a862cd5 100644 (file)
@@ -21,8 +21,8 @@ namespace Novacoin
         }
 
         public Hash256() : base() { }
-        public Hash256(byte[] bytesArray) : base(bytesArray) { }
-        public Hash256(IList<byte> bytesList) : base(bytesList) { }
+        public Hash256(byte[] bytes) : base(bytes) { }
+        public Hash256(IEnumerable<byte> bytes) : base(bytes) { }
 
         public static Hash256 Compute256(IEnumerable<byte> inputBytes)
         {
index 4aad33e..c6da9c5 100644 (file)
@@ -711,8 +711,8 @@ namespace Novacoin
 
             foreach (Tuple<txnouttype, IEnumerable<byte>> templateTuple in templateTuples)
             {
-                CScript script2 = new CScript(templateTuple.Item2);
                 CScript script1 = scriptPubKey;
+                CScript script2 = new CScript(templateTuple.Item2);
 
                 opcodetype opcode1, opcode2;
 
@@ -727,7 +727,7 @@ namespace Novacoin
 
                 while (true)
                 {
-                    if (wl1.GetItem() == last1 && wl2.GetItem() == last2)
+                    if (wl1.GetCurrentItem() == last1 && wl2.GetCurrentItem() == last2)
                     {
                         // Found a match
                         typeRet = templateTuple.Item1;
@@ -807,7 +807,7 @@ namespace Novacoin
                             break;
                         }
                     }
-                    else if (opcode1 != opcode2 || args1.SequenceEqual(args2))
+                    else if (opcode1 != opcode2 || !args1.SequenceEqual(args2))
                     {
                         // Others must match exactly
                         break;
index 90c2f8f..c479b0d 100644 (file)
@@ -16,8 +16,8 @@ namespace Novacoin
         }
 
         public ScryptHash256() : base() { }
-        public ScryptHash256(byte[] bytesArray) : base(bytesArray) { }
-        public ScryptHash256(IList<byte> bytesList) : base(bytesList) { }
+        public ScryptHash256(byte[] bytes) : base(bytes) { }
+        public ScryptHash256(IEnumerable<byte> bytes) : base(bytes) { }
 
         /// <summary>
         /// Calculate scrypt hash and return new instance of ScryptHash256 class
index b74e14a..d48bc74 100644 (file)
@@ -103,7 +103,20 @@ namespace NovacoinTest
             IEnumerable<byte> dataBytesForScrypt = b1.header.ToBytes();
             ScryptHash256 scryptHash = ScryptHash256.Compute256(dataBytesForScrypt);
 
-            Console.WriteLine("block1 header hash: {0}", scryptHash.ToString());
+            Console.WriteLine("\nblock1 header hash: {0}", scryptHash.ToString());
+
+            /// Solver tests
+            CScript scriptPubKey = new CScript(Interop.ParseHex("21021ad6ae76a602310e86957d4ca752c81a8725f142fd2fc40f6a7fc2310bb2c749ac"));
+            CScript scriptPubKeyHash = new CScript(Interop.ParseHex("76a914edbf189bece45d4afa9848276e949183936bf6a488ac"));
+
+            txnouttype typeRet;
+            IList<IEnumerable<byte>> solutions;
+
+            Console.WriteLine("scriptPubKey solved: {0}", ScriptCode.Solver(scriptPubKey, out typeRet, out solutions));
+            Console.WriteLine("scriptPubKey address: {0}", new CPubKey(solutions.First()).GetKeyID().ToString());
+
+            Console.WriteLine("scriptPubKeyHash solved: {0}", ScriptCode.Solver(scriptPubKeyHash, out typeRet, out solutions));
+            Console.WriteLine("scriptPubKeyHash address: {0}", new CKeyID(new Hash160(solutions.First())).ToString());
 
             Console.ReadLine();
         }