Replace GetOpName with shorter version
authorCryptoManiac <balthazar@yandex.ru>
Sun, 23 Aug 2015 01:03:26 +0000 (04:03 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Sun, 23 Aug 2015 01:03:26 +0000 (04:03 +0300)
Novacoin/ScriptCode.cs
NovacoinTest/Program.cs

index ff8bb40..f5f1352 100644 (file)
@@ -216,263 +216,12 @@ namespace Novacoin
         /// <returns>Opcode name</returns>
         public static string GetOpName(instruction opcode)
         {
-            switch (opcode)
-            {
-                // push value
-                case instruction.OP_0:
-                    return "OP_0";
-                case instruction.OP_PUSHDATA1:
-                    return "OP_PUSHDATA1";
-                case instruction.OP_PUSHDATA2:
-                    return "OP_PUSHDATA2";
-                case instruction.OP_PUSHDATA4:
-                    return "OP_PUSHDATA4";
-                case instruction.OP_1NEGATE:
-                    return "OP_1NEGATE";
-                case instruction.OP_RESERVED:
-                    return "OP_RESERVED";
-                case instruction.OP_1:
-                    return "OP_1";
-                case instruction.OP_2:
-                    return "OP_2";
-                case instruction.OP_3:
-                    return "OP_3";
-                case instruction.OP_4:
-                    return "OP_4";
-                case instruction.OP_5:
-                    return "OP_5";
-                case instruction.OP_6:
-                    return "OP_6";
-                case instruction.OP_7:
-                    return "OP_7";
-                case instruction.OP_8:
-                    return "OP_8";
-                case instruction.OP_9:
-                    return "OP_9";
-                case instruction.OP_10:
-                    return "OP_10";
-                case instruction.OP_11:
-                    return "OP_11";
-                case instruction.OP_12:
-                    return "OP_12";
-                case instruction.OP_13:
-                    return "OP_13";
-                case instruction.OP_14:
-                    return "OP_14";
-                case instruction.OP_15:
-                    return "OP_15";
-                case instruction.OP_16:
-                    return "OP_16";
-
-                // control
-                case instruction.OP_NOP:
-                    return "OP_NOP";
-                case instruction.OP_VER:
-                    return "OP_VER";
-                case instruction.OP_IF:
-                    return "OP_IF";
-                case instruction.OP_NOTIF:
-                    return "OP_NOTIF";
-                case instruction.OP_VERIF:
-                    return "OP_VERIF";
-                case instruction.OP_VERNOTIF:
-                    return "OP_VERNOTIF";
-                case instruction.OP_ELSE:
-                    return "OP_ELSE";
-                case instruction.OP_ENDIF:
-                    return "OP_ENDIF";
-                case instruction.OP_VERIFY:
-                    return "OP_VERIFY";
-                case instruction.OP_RETURN:
-                    return "OP_RETURN";
-
-                // stack ops
-                case instruction.OP_TOALTSTACK:
-                    return "OP_TOALTSTACK";
-                case instruction.OP_FROMALTSTACK:
-                    return "OP_FROMALTSTACK";
-                case instruction.OP_2DROP:
-                    return "OP_2DROP";
-                case instruction.OP_2DUP:
-                    return "OP_2DUP";
-                case instruction.OP_3DUP:
-                    return "OP_3DUP";
-                case instruction.OP_2OVER:
-                    return "OP_2OVER";
-                case instruction.OP_2ROT:
-                    return "OP_2ROT";
-                case instruction.OP_2SWAP:
-                    return "OP_2SWAP";
-                case instruction.OP_IFDUP:
-                    return "OP_IFDUP";
-                case instruction.OP_DEPTH:
-                    return "OP_DEPTH";
-                case instruction.OP_DROP:
-                    return "OP_DROP";
-                case instruction.OP_DUP:
-                    return "OP_DUP";
-                case instruction.OP_NIP:
-                    return "OP_NIP";
-                case instruction.OP_OVER:
-                    return "OP_OVER";
-                case instruction.OP_PICK:
-                    return "OP_PICK";
-                case instruction.OP_ROLL:
-                    return "OP_ROLL";
-                case instruction.OP_ROT:
-                    return "OP_ROT";
-                case instruction.OP_SWAP:
-                    return "OP_SWAP";
-                case instruction.OP_TUCK:
-                    return "OP_TUCK";
-
-                // splice ops
-                case instruction.OP_CAT:
-                    return "OP_CAT";
-                case instruction.OP_SUBSTR:
-                    return "OP_SUBSTR";
-                case instruction.OP_LEFT:
-                    return "OP_LEFT";
-                case instruction.OP_RIGHT:
-                    return "OP_RIGHT";
-                case instruction.OP_SIZE:
-                    return "OP_SIZE";
-
-                // bit logic
-                case instruction.OP_INVERT:
-                    return "OP_INVERT";
-                case instruction.OP_AND:
-                    return "OP_AND";
-                case instruction.OP_OR:
-                    return "OP_OR";
-                case instruction.OP_XOR:
-                    return "OP_XOR";
-                case instruction.OP_EQUAL:
-                    return "OP_EQUAL";
-                case instruction.OP_EQUALVERIFY:
-                    return "OP_EQUALVERIFY";
-                case instruction.OP_RESERVED1:
-                    return "OP_RESERVED1";
-                case instruction.OP_RESERVED2:
-                    return "OP_RESERVED2";
-
-                // numeric
-                case instruction.OP_1ADD:
-                    return "OP_1ADD";
-                case instruction.OP_1SUB:
-                    return "OP_1SUB";
-                case instruction.OP_2MUL:
-                    return "OP_2MUL";
-                case instruction.OP_2DIV:
-                    return "OP_2DIV";
-                case instruction.OP_NEGATE:
-                    return "OP_NEGATE";
-                case instruction.OP_ABS:
-                    return "OP_ABS";
-                case instruction.OP_NOT:
-                    return "OP_NOT";
-                case instruction.OP_0NOTEQUAL:
-                    return "OP_0NOTEQUAL";
-                case instruction.OP_ADD:
-                    return "OP_ADD";
-                case instruction.OP_SUB:
-                    return "OP_SUB";
-                case instruction.OP_MUL:
-                    return "OP_MUL";
-                case instruction.OP_DIV:
-                    return "OP_DIV";
-                case instruction.OP_MOD:
-                    return "OP_MOD";
-                case instruction.OP_LSHIFT:
-                    return "OP_LSHIFT";
-                case instruction.OP_RSHIFT:
-                    return "OP_RSHIFT";
-                case instruction.OP_BOOLAND:
-                    return "OP_BOOLAND";
-                case instruction.OP_BOOLOR:
-                    return "OP_BOOLOR";
-                case instruction.OP_NUMEQUAL:
-                    return "OP_NUMEQUAL";
-                case instruction.OP_NUMEQUALVERIFY:
-                    return "OP_NUMEQUALVERIFY";
-                case instruction.OP_NUMNOTEQUAL:
-                    return "OP_NUMNOTEQUAL";
-                case instruction.OP_LESSTHAN:
-                    return "OP_LESSTHAN";
-                case instruction.OP_GREATERTHAN:
-                    return "OP_GREATERTHAN";
-                case instruction.OP_LESSTHANOREQUAL:
-                    return "OP_LESSTHANOREQUAL";
-                case instruction.OP_GREATERTHANOREQUAL:
-                    return "OP_GREATERTHANOREQUAL";
-                case instruction.OP_MIN:
-                    return "OP_MIN";
-                case instruction.OP_MAX:
-                    return "OP_MAX";
-                case instruction.OP_WITHIN:
-                    return "OP_WITHIN";
-
-                // crypto
-                case instruction.OP_RIPEMD160:
-                    return "OP_RIPEMD160";
-                case instruction.OP_SHA1:
-                    return "OP_SHA1";
-                case instruction.OP_SHA256:
-                    return "OP_SHA256";
-                case instruction.OP_HASH160:
-                    return "OP_HASH160";
-                case instruction.OP_HASH256:
-                    return "OP_HASH256";
-                case instruction.OP_CODESEPARATOR:
-                    return "OP_CODESEPARATOR";
-                case instruction.OP_CHECKSIG:
-                    return "OP_CHECKSIG";
-                case instruction.OP_CHECKSIGVERIFY:
-                    return "OP_CHECKSIGVERIFY";
-                case instruction.OP_CHECKMULTISIG:
-                    return "OP_CHECKMULTISIG";
-                case instruction.OP_CHECKMULTISIGVERIFY:
-                    return "OP_CHECKMULTISIGVERIFY";
-
-                // expansion
-                case instruction.OP_NOP1:
-                    return "OP_NOP1";
-                case instruction.OP_NOP2:
-                    return "OP_NOP2";
-                case instruction.OP_NOP3:
-                    return "OP_NOP3";
-                case instruction.OP_NOP4:
-                    return "OP_NOP4";
-                case instruction.OP_NOP5:
-                    return "OP_NOP5";
-                case instruction.OP_NOP6:
-                    return "OP_NOP6";
-                case instruction.OP_NOP7:
-                    return "OP_NOP7";
-                case instruction.OP_NOP8:
-                    return "OP_NOP8";
-                case instruction.OP_NOP9:
-                    return "OP_NOP9";
-                case instruction.OP_NOP10:
-                    return "OP_NOP10";
-
-                // template matching params
-                case instruction.OP_SMALLINTEGER:
-                    return "OP_SMALLINTEGER";
-                case instruction.OP_PUBKEYHASH:
-                    return "OP_PUBKEYHASH";
-                case instruction.OP_PUBKEY:
-                    return "OP_PUBKEY";
-                case instruction.OP_PUBKEYS:
-                    return "OP_PUBKEYS";
-                case instruction.OP_SMALLDATA:
-                    return "OP_SMALLDATA";
-
-                case instruction.OP_INVALIDOPCODE:
-                    return "OP_INVALIDOPCODE";
-                default:
-                    return "OP_UNKNOWN";
-            }
+            if (opcode == instruction.OP_0) // OP_0 and OP_FALSE are synonyms
+                return "OP_0";
+            if (opcode == instruction.OP_1) // OP_1 and OP_TRUE are synonyms
+                return "OP_1";
+
+            return Enum.GetName(typeof(instruction), opcode);
         }
 
         /// <summary>
index e4c3c14..2206ea1 100644 (file)
@@ -189,6 +189,16 @@ namespace NovacoinTest
 
             Console.WriteLine("In addition, -1 is encoded as {0}", ScriptCode.GetOpName(ScriptCode.EncodeOP_N(-1, true)));
 
+            Console.WriteLine(ScriptCode.GetOpName(instruction.OP_TRUE));
+            Console.WriteLine(ScriptCode.GetOpName(instruction.OP_FALSE));
+
+            // Script validation test
+
+            CTransaction txPrev = new CTransaction(Interop.HexToList("0100000079755d53010000000000000000000000000000000000000000000000000000000000000000ffffffff0b03d26401062f503253482fffffffff1cb3250000000000001976a914a1876be00980e343d9fb60b8219e0e8345fc744b88ac7b2c0000000000001976a914549ff7e6fe90d762e2e51678bda26f54fbbfcce388ac4f380000000000001976a9146c923ed1d87738df97301892aca83ba6b262cc4d88acfecc0000000000001976a91458d438e17b2e9f09a79b3920c06e3fd4bdc4cb3788ac84e80000000000001976a914797d85f272d66990adc30a30974c5d643a5dab3f88acc85e0100000000001976a9149a430715e524e951ddd5d947614c6cd4b412ed5888ac4e850100000000001976a914ae0da10f13d51e66fe5559023a2a32ed15ca335f88ac1d180200000000001976a914e2431bf313ac865fd8f1289d1627cf9391fabd7788ac472c0200000000001976a914fcbe5b3267acfea71fe3d768597fdbe0b8a9b16488ace0af0200000000001976a91498facbedc6424820a79c381fdd3c6e7c4389dc3888ac6cbb0200000000001976a9140c3a1469e5088100f11ec56b77fdeba61c25650c88acb8ec0200000000001976a914d99b39f6d1e06c1e2292eb6786188e193c5dec5988acb33c0300000000001976a9141b49aedc9ed1026722b1686e1322be08b998acfe88acca620300000000001976a914753cf85eef5fd49cc9694b67f3ed366508d0562488acc06f0300000000001976a914c157ab891e5f8dfe37a8e7598b53a646eed4028888acb59c0400000000001976a914cad1890de0e59796e501131dc11bd31a6acf96b488ac49070500000000001976a914c7b6639b55215e5d17590f3b5df46ad7ab37ee6d88ac34b20500000000001976a914a8eaab473a06570cafdf2aa44d976d09cc29814d88ac23db0600000000001976a914407356864b5e1b3df8a863d678183140be6ef17588acb55e0700000000001976a914037a31012e8e1962e251c0432d9258058326cdcf88ac278f0800000000001976a914e0e70b5b3192dd3e418642055a50840a19ffcf7088acccad0800000000001976a914640ebcbda496cc9e4fdb2281aeecaa00691007d288ac85ef0800000000001976a91451978f1d2ad964c556127fdb9e201e31a6ca474d88ac45790d00000000001976a9148c0b235018aa2a8f8b884e5fad1e1d1fce4b6cb288aca5a01500000000001976a914b1c9131340b7dbcfc060d977200c43686bcb73f188ac4dce1700000000001976a914684d742a36d06ca1bce3560b00135ca1432b984288ac2dac0000000000004341043b253cc0b5c8ce26f24b84bb955bec955cbb4643f19ab7ea073884f22874abdafc42040b97efec3c9eeb29ce69022a96cc1772f8bc805f78af0d3dc5c441db5fac00000000000000002a6a284d9ca0d38f66957fa8dd5de67fa23034284a51d669ee34b0608e060f56f4dd93000000000200000000000000"));
+
+
+            Console.WriteLine("Script validation result: {0}", ScriptCode.VerifyScript(tx.vin[0].scriptSig, txPrev.vout[1].scriptPubKey, tx, 0, (int)scriptflag.SCRIPT_VERIFY_P2SH, 0));
+
             Console.ReadLine();
         }
     }