Get rid of HexToList and HexToEnumerable functions
[NovacoinLibrary.git] / Novacoin / CScript.cs
index 9149d34..3127ec6 100644 (file)
@@ -59,7 +59,7 @@ namespace Novacoin
         /// Initializes new instance of CScript and fills it with supplied bytes
         /// </summary>
         /// <param name="bytes">Enumerator interface for byte sequence</param>
-        public CScript(IEnumerable<byte> bytes)
+        public CScript(byte[] bytes)
         {
             codeBytes = new List<byte>(bytes);
         }
@@ -74,21 +74,21 @@ namespace Novacoin
         }
 
         /// <summary>
-        /// Adds specified operation to opcode bytes list
+        /// Adds specified operation to instruction list
         /// </summary>
         /// <param name="opcode"></param>
-        public void AddOp(instruction opcode)
+        public void AddInstruction(instruction opcode)
         {
             if (opcode < instruction.OP_0 || opcode > instruction.OP_INVALIDOPCODE)
             {
-                throw new CScriptException("CScript::AddOp() : invalid opcode");
+                throw new CScriptException("CScript::AddInstruction() : invalid instruction");
             }
 
             codeBytes.Add((byte)opcode);
         }
 
         /// <summary>
-        /// Adds hash to opcode bytes list.
+        /// Adds hash to instruction list.
         ///    New items are added in this format:
         ///    hash_length_byte hash_bytes
         /// </summary>
@@ -100,7 +100,7 @@ namespace Novacoin
         }
 
         /// <summary>
-        /// Adds hash to opcode bytes list.
+        /// Adds hash to instruction list.
         ///    New items are added in this format:
         ///    hash_length_byte hash_bytes
         /// </summary>
@@ -112,7 +112,7 @@ namespace Novacoin
         }
 
         /// <summary>
-        /// Create new OP_PUSHDATAn operator and add it to opcode bytes list
+        /// Create new OP_PUSHDATAn operator and add it to instruction list
         /// </summary>
         /// <param name="dataBytes">Set of data bytes</param>
         public void PushData(byte[] dataBytes)
@@ -135,7 +135,7 @@ namespace Novacoin
                 // OP_PUSHDATA1 0x00 0x01 [0x5a]
                 codeBytes.Add((byte)instruction.OP_PUSHDATA2);
 
-                byte[] szBytes = Interop.BEBytes((ushort)nCount);
+                var szBytes = Interop.BEBytes((ushort)nCount);
                 codeBytes.AddRange(szBytes);
             }
             else if (nCount < 0xffffffff)
@@ -143,7 +143,7 @@ namespace Novacoin
                 // OP_PUSHDATA1 0x00 0x00 0x00 0x01 [0x5a]
                 codeBytes.Add((byte)instruction.OP_PUSHDATA4);
 
-                byte[] szBytes = Interop.BEBytes((uint)nCount);
+                var szBytes = Interop.BEBytes((uint)nCount);
                 codeBytes.AddRange(szBytes);
             }
 
@@ -197,15 +197,15 @@ namespace Novacoin
             {
                 var wCodeBytes = new ByteQueue(codeBytes);
 
-                instruction opcode; // Current opcode
+                instruction opcode; // Current instruction
                 byte[] pushArgs; // OP_PUSHDATAn argument
 
-                // Scan opcodes sequence
+                // Scan instructions sequence
                 while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
                 {
                     if (opcode > instruction.OP_16)
                     {
-                        // We don't allow control opcodes here
+                        // We don't allow control instructions here
                         return false;
                     }
                 }
@@ -224,9 +224,9 @@ namespace Novacoin
                 var wCodeBytes = new ByteQueue(codeBytes);
 
                 byte[] pushArgs; // OP_PUSHDATAn argument
-                instruction opcode; // Current opcode
+                instruction opcode; // Current instruction
 
-                // Scan opcodes sequence
+                // Scan instructions sequence
                 while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
                 {
                     var data = pushArgs;
@@ -312,13 +312,13 @@ namespace Novacoin
         {
             var wCodeBytes = new ByteQueue(codeBytes);
 
-            instruction opcode; // Current opcode
+            instruction opcode; // Current instruction
             byte[] pushArgs; // OP_PUSHDATAn argument
 
             int nCount = 0;
             var lastOpcode = instruction.OP_INVALIDOPCODE;
 
-            // Scan opcodes sequence
+            // Scan instructions sequence
             while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
             {
                 if (opcode == instruction.OP_CHECKSIG || opcode == instruction.OP_CHECKSIGVERIFY)
@@ -359,7 +359,7 @@ namespace Novacoin
             // pushes onto the stack:
             ByteQueue wScriptSig = scriptSig.GetByteQUeue();
 
-            instruction opcode; // Current opcode
+            instruction opcode; // Current instruction
             byte[] pushArgs; // OP_PUSHDATAn argument
 
             while (ScriptCode.GetOp(ref wScriptSig, out opcode, out pushArgs))
@@ -385,7 +385,7 @@ namespace Novacoin
         {
             codeBytes.Clear();
             PushData(pubKey.PublicBytes);
-            AddOp(instruction.OP_CHECKSIG);
+            AddInstruction(instruction.OP_CHECKSIG);
         }
 
         /// <summary>
@@ -395,11 +395,11 @@ namespace Novacoin
         public void SetDestination(CKeyID ID)
         {
             codeBytes.Clear();
-            AddOp(instruction.OP_DUP);
-            AddOp(instruction.OP_HASH160);
+            AddInstruction(instruction.OP_DUP);
+            AddInstruction(instruction.OP_HASH160);
             AddHash(ID);
-            AddOp(instruction.OP_EQUALVERIFY);
-            AddOp(instruction.OP_CHECKSIG);
+            AddInstruction(instruction.OP_EQUALVERIFY);
+            AddInstruction(instruction.OP_CHECKSIG);
         }
 
         /// <summary>
@@ -409,9 +409,9 @@ namespace Novacoin
         public void SetDestination(CScriptID ID)
         {
             codeBytes.Clear();
-            AddOp(instruction.OP_HASH160);
+            AddInstruction(instruction.OP_HASH160);
             AddHash(ID);
-            AddOp(instruction.OP_EQUAL);
+            AddInstruction(instruction.OP_EQUAL);
         }
 
         /// <summary>
@@ -430,15 +430,15 @@ namespace Novacoin
         public void SetMultiSig(int nRequired, CPubKey[] keys)
         {
             codeBytes.Clear();
-            AddOp(ScriptCode.EncodeOP_N(nRequired));
+            AddInstruction(ScriptCode.EncodeOP_N(nRequired));
 
             foreach (var key in keys)
             {
                 PushData(key.PublicBytes);
             }
 
-            AddOp(ScriptCode.EncodeOP_N(keys.Length));
-            AddOp(instruction.OP_CHECKMULTISIG);
+            AddInstruction(ScriptCode.EncodeOP_N(keys.Length));
+            AddInstruction(instruction.OP_CHECKMULTISIG);
         }
 
         /// <summary>
@@ -463,7 +463,7 @@ namespace Novacoin
                        var sb = new StringBuilder();
             var wCodeBytes = new ByteQueue(codeBytes);
 
-            instruction opcode; // Current opcode
+            instruction opcode; // Current instruction
             byte[] pushArgs; // OP_PUSHDATAn argument
             while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs))
             {