Use getters instead of Satoshi-style access methods
authorCryptoManiac <balthazar@yandex.ru>
Thu, 20 Aug 2015 19:16:25 +0000 (22:16 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Thu, 20 Aug 2015 19:16:25 +0000 (22:16 +0300)
Novacoin/CScript.cs
Novacoin/ScriptCode.cs

index 565b6a2..c4f7f91 100644 (file)
@@ -175,65 +175,71 @@ namespace Novacoin
         /// Is it true that script doesn't contain anything except push value operations?
         /// </summary>
         /// <returns>Checking result</returns>
-        public bool IsPushonly()
+        public bool IsPushonly
         {
-            WrappedList<byte> wCodeBytes = new WrappedList<byte>(codeBytes);
-
-            opcodetype opcode; // Current opcode
-            IEnumerable<byte> pushArgs; // OP_PUSHDATAn argument
-            
-            // Scan opcodes sequence
-            while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
+            get
             {
-                if (opcode > opcodetype.OP_16)
+                WrappedList<byte> wCodeBytes = new WrappedList<byte>(codeBytes);
+
+                opcodetype opcode; // Current opcode
+                IEnumerable<byte> pushArgs; // OP_PUSHDATAn argument
+
+                // Scan opcodes sequence
+                while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
                 {
-                    // We don't allow control opcodes here
-                    return false;
+                    if (opcode > opcodetype.OP_16)
+                    {
+                        // We don't allow control opcodes here
+                        return false;
+                    }
                 }
-            }
 
-            return true;
+                return true;
+            }
         }
 
         /// <summary>
         /// Is it true that script doesn't contain non-canonical push operations?
         /// </summary>
         /// <returns>Checking result</returns>
-        public bool HashOnlyCanonicalPushes()
+        public bool HasOnlyCanonicalPushes
         {
-            WrappedList<byte> wCodeBytes = new WrappedList<byte>(codeBytes);
-
-            opcodetype opcode; // Current opcode
-            IEnumerable<byte> pushArgs; // OP_PUSHDATAn argument
-
-            // Scan opcodes sequence
-            while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
+            get
             {
-                byte[] data = pushArgs.ToArray();
+                WrappedList<byte> wCodeBytes = new WrappedList<byte>(codeBytes);
 
-                if (opcode < opcodetype.OP_PUSHDATA1 && opcode > opcodetype.OP_0 && (data.Length == 1 && data[0] <= 16))
-                {
-                    // Could have used an OP_n code, rather than a 1-byte push.
-                    return false;
-                }
-                if (opcode == opcodetype.OP_PUSHDATA1 && data.Length < (int)opcodetype.OP_PUSHDATA1)
-                {
-                    // Could have used a normal n-byte push, rather than OP_PUSHDATA1.
-                    return false;
-                }
-                if (opcode == opcodetype.OP_PUSHDATA2 && data.Length <= 0xFF)
-                {
-                    // Could have used an OP_PUSHDATA1.
-                    return false;
-                }
-                if (opcode == opcodetype.OP_PUSHDATA4 && data.LongLength <= 0xFFFF)
+                opcodetype opcode; // Current opcode
+                IEnumerable<byte> pushArgs; // OP_PUSHDATAn argument
+
+                // Scan opcodes sequence
+                while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
                 {
-                    // Could have used an OP_PUSHDATA2.
-                    return false;
+                    byte[] data = pushArgs.ToArray();
+
+                    if (opcode < opcodetype.OP_PUSHDATA1 && opcode > opcodetype.OP_0 && (data.Length == 1 && data[0] <= 16))
+                    {
+                        // Could have used an OP_n code, rather than a 1-byte push.
+                        return false;
+                    }
+                    if (opcode == opcodetype.OP_PUSHDATA1 && data.Length < (int)opcodetype.OP_PUSHDATA1)
+                    {
+                        // Could have used a normal n-byte push, rather than OP_PUSHDATA1.
+                        return false;
+                    }
+                    if (opcode == opcodetype.OP_PUSHDATA2 && data.Length <= 0xFF)
+                    {
+                        // Could have used an OP_PUSHDATA1.
+                        return false;
+                    }
+                    if (opcode == opcodetype.OP_PUSHDATA4 && data.LongLength <= 0xFFFF)
+                    {
+                        // Could have used an OP_PUSHDATA2.
+                        return false;
+                    }
                 }
-            }
 
-            return true;
+                return true;
+            }
         }
 
         /// <summary>
@@ -263,7 +269,6 @@ namespace Novacoin
             {
                 // Sender provides hash of pubkey, receiver provides signature and pubkey
                 // OP_DUP OP_HASH160 20 [20 byte hash] OP_EQUALVERIFY OP_CHECKSIG
-
                 return (codeBytes.Count == 25 &&
                         codeBytes[0] == (byte)opcodetype.OP_DUP &&
                         codeBytes[1] == (byte)opcodetype.OP_HASH160 &&
@@ -384,7 +389,7 @@ namespace Novacoin
         /// <summary>
         /// Access to script code.
         /// </summary>
-        public IEnumerable<byte> Enumerable
+        public IEnumerable<byte> Bytes
         {
             get { return codeBytes; }
         }
index 6d69349..2326c01 100644 (file)
@@ -661,7 +661,7 @@ namespace Novacoin
                 typeRet = txnouttype.TX_SCRIPTHASH;
 
                 // Take 20 bytes with offset of 2 bytes
-                IEnumerable<byte> hashBytes = scriptPubKey.Enumerable.Skip(2).Take(20);
+                IEnumerable<byte> hashBytes = scriptPubKey.Bytes.Skip(2).Take(20);
                 solutions.Add(hashBytes);
 
                 return true;
@@ -673,7 +673,7 @@ namespace Novacoin
                 typeRet = txnouttype.TX_PUBKEYHASH;
 
                 // Take 20 bytes with offset of 3 bytes
-                IEnumerable<byte> hashBytes = scriptPubKey.Enumerable.Skip(3).Take(20);
+                IEnumerable<byte> hashBytes = scriptPubKey.Bytes.Skip(3).Take(20);
                 solutions.Add(hashBytes);
 
                 return true;
@@ -722,8 +722,8 @@ namespace Novacoin
 
                 IEnumerable<byte> args1, args2;
 
-                byte last1 = script1.Enumerable.Last();
-                byte last2 = script2.Enumerable.Last();
+                byte last1 = script1.Bytes.Last();
+                byte last2 = script2.Bytes.Last();
 
                 while (true)
                 {