Use type-safe enum for opcodes.
authorCryptoManiac <balthazar@yandex.ru>
Mon, 11 Apr 2016 21:02:17 +0000 (00:02 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Mon, 11 Apr 2016 21:02:17 +0000 (00:02 +0300)
src/script.cpp
src/script.h

index 89b3e98..379923f 100644 (file)
@@ -459,7 +459,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                 opcode == OP_RSHIFT)
                 return false; // Disabled opcodes.
 
-            if (fExec && 0 <= opcode && opcode <= OP_PUSHDATA4)
+            if (fExec && opcode <= OP_PUSHDATA4)
                 stack.push_back(vchPushValue);
             else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF))
             switch (opcode)
@@ -486,7 +486,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                 case OP_16:
                 {
                     // ( -- value)
-                    CBigNum bn((int)opcode - (int)(OP_1 - 1));
+                    CBigNum bn(opcode - (OP_1 - 1));
                     stack.push_back(bn.getvch());
                 }
                 break;
index 5a3cf06..7355f67 100644 (file)
@@ -109,7 +109,7 @@ enum txnouttype
 const char* GetTxnOutputType(txnouttype t);
 
 // Script opcodes
-enum opcodetype
+enum opcodetype : uint8_t
 {
     // push value
     OP_0 = 0x00,
@@ -356,9 +356,7 @@ public:
 
     CScript& operator<<(opcodetype opcode)
     {
-        if (opcode < 0 || opcode > 0xff)
-            throw std::runtime_error("CScript::operator<<() : invalid opcode");
-        insert(end(), (uint8_t)opcode);
+        insert(end(), opcode);
         return *this;
     }
 
@@ -607,7 +605,7 @@ public:
                 str += "[error]";
                 return str;
             }
-            if (0 <= opcode && opcode <= OP_PUSHDATA4)
+            if (opcode <= OP_PUSHDATA4)
                 str += fShort? ValueString(vch).substr(0, 10) : ValueString(vch);
             else
                 str += GetOpName(opcode);