Module: BTC::Opcode
- Extended by:
- Opcode
- Includes:
- Opcodes
- Included in:
- Opcode
- Defined in:
- lib/btcruby/script/opcode.rb,
lib/btcruby/script/opcode.rb
Constant Summary
Constants included from Opcodes
BTC::Opcodes::OPCODE_NAME_TO_VALUE, BTC::Opcodes::OPCODE_VALUE_TO_NAME, BTC::Opcodes::OP_0, BTC::Opcodes::OP_0NOTEQUAL, BTC::Opcodes::OP_1, BTC::Opcodes::OP_10, BTC::Opcodes::OP_11, BTC::Opcodes::OP_12, BTC::Opcodes::OP_13, BTC::Opcodes::OP_14, BTC::Opcodes::OP_15, BTC::Opcodes::OP_16, BTC::Opcodes::OP_1ADD, BTC::Opcodes::OP_1NEGATE, BTC::Opcodes::OP_1SUB, BTC::Opcodes::OP_2, BTC::Opcodes::OP_2DIV, BTC::Opcodes::OP_2DROP, BTC::Opcodes::OP_2DUP, BTC::Opcodes::OP_2MUL, BTC::Opcodes::OP_2OVER, BTC::Opcodes::OP_2ROT, BTC::Opcodes::OP_2SWAP, BTC::Opcodes::OP_3, BTC::Opcodes::OP_3DUP, BTC::Opcodes::OP_4, BTC::Opcodes::OP_5, BTC::Opcodes::OP_6, BTC::Opcodes::OP_7, BTC::Opcodes::OP_8, BTC::Opcodes::OP_9, BTC::Opcodes::OP_ABS, BTC::Opcodes::OP_ADD, BTC::Opcodes::OP_AND, BTC::Opcodes::OP_BOOLAND, BTC::Opcodes::OP_BOOLOR, BTC::Opcodes::OP_CAT, BTC::Opcodes::OP_CHECKLOCKTIMEVERIFY, BTC::Opcodes::OP_CHECKMULTISIG, BTC::Opcodes::OP_CHECKMULTISIGVERIFY, BTC::Opcodes::OP_CHECKSIG, BTC::Opcodes::OP_CHECKSIGVERIFY, BTC::Opcodes::OP_CODESEPARATOR, BTC::Opcodes::OP_DEPTH, BTC::Opcodes::OP_DIV, BTC::Opcodes::OP_DROP, BTC::Opcodes::OP_DUP, BTC::Opcodes::OP_ELSE, BTC::Opcodes::OP_ENDIF, BTC::Opcodes::OP_EQUAL, BTC::Opcodes::OP_EQUALVERIFY, BTC::Opcodes::OP_FALSE, BTC::Opcodes::OP_FROMALTSTACK, BTC::Opcodes::OP_GREATERTHAN, BTC::Opcodes::OP_GREATERTHANOREQUAL, BTC::Opcodes::OP_HASH160, BTC::Opcodes::OP_HASH256, BTC::Opcodes::OP_IF, BTC::Opcodes::OP_IFDUP, BTC::Opcodes::OP_INVALIDOPCODE, BTC::Opcodes::OP_INVERT, BTC::Opcodes::OP_LEFT, BTC::Opcodes::OP_LESSTHAN, BTC::Opcodes::OP_LESSTHANOREQUAL, BTC::Opcodes::OP_LSHIFT, BTC::Opcodes::OP_MAX, BTC::Opcodes::OP_MIN, BTC::Opcodes::OP_MOD, BTC::Opcodes::OP_MUL, BTC::Opcodes::OP_NEGATE, BTC::Opcodes::OP_NIP, BTC::Opcodes::OP_NOP, BTC::Opcodes::OP_NOP1, BTC::Opcodes::OP_NOP10, BTC::Opcodes::OP_NOP2, BTC::Opcodes::OP_NOP3, BTC::Opcodes::OP_NOP4, BTC::Opcodes::OP_NOP5, BTC::Opcodes::OP_NOP6, BTC::Opcodes::OP_NOP7, BTC::Opcodes::OP_NOP8, BTC::Opcodes::OP_NOP9, BTC::Opcodes::OP_NOT, BTC::Opcodes::OP_NOTIF, BTC::Opcodes::OP_NUMEQUAL, BTC::Opcodes::OP_NUMEQUALVERIFY, BTC::Opcodes::OP_NUMNOTEQUAL, BTC::Opcodes::OP_OR, BTC::Opcodes::OP_OVER, BTC::Opcodes::OP_PICK, BTC::Opcodes::OP_PUSHDATA1, BTC::Opcodes::OP_PUSHDATA2, BTC::Opcodes::OP_PUSHDATA4, BTC::Opcodes::OP_RESERVED, BTC::Opcodes::OP_RESERVED1, BTC::Opcodes::OP_RESERVED2, BTC::Opcodes::OP_RETURN, BTC::Opcodes::OP_RIGHT, BTC::Opcodes::OP_RIPEMD160, BTC::Opcodes::OP_ROLL, BTC::Opcodes::OP_ROT, BTC::Opcodes::OP_RSHIFT, BTC::Opcodes::OP_SHA1, BTC::Opcodes::OP_SHA256, BTC::Opcodes::OP_SIZE, BTC::Opcodes::OP_SUB, BTC::Opcodes::OP_SUBSTR, BTC::Opcodes::OP_SWAP, BTC::Opcodes::OP_TOALTSTACK, BTC::Opcodes::OP_TRUE, BTC::Opcodes::OP_TUCK, BTC::Opcodes::OP_VER, BTC::Opcodes::OP_VERIF, BTC::Opcodes::OP_VERIFY, BTC::Opcodes::OP_VERNOTIF, BTC::Opcodes::OP_WITHIN, BTC::Opcodes::OP_XOR
Instance Method Summary collapse
-
#name_for_opcode(opcode) ⇒ Object
Returns a human-readable name for a given opcode byte value.
-
#opcode_for_name(name) ⇒ Object
Returns an opcode byte value for a given name (“OP_…”).
-
#opcode_for_small_integer(small_int) ⇒ Object
Returns OP_1NEGATE, OP_0 ..
-
#small_integer_from_opcode(opcode) ⇒ Object
Converts opcode OP_<N> or OP_1NEGATE to an integer value.
Instance Method Details
#name_for_opcode(opcode) ⇒ Object
Returns a human-readable name for a given opcode byte value.
8 9 10 |
# File 'lib/btcruby/script/opcode.rb', line 8 def name_for_opcode(opcode) OPCODE_VALUE_TO_NAME[opcode] || "OP_UNKNOWN" end |
#opcode_for_name(name) ⇒ Object
Returns an opcode byte value for a given name (“OP_…”).
13 14 15 |
# File 'lib/btcruby/script/opcode.rb', line 13 def opcode_for_name(name) OPCODE_NAME_TO_VALUE[name] || OP_INVALIDOPCODE end |
#opcode_for_small_integer(small_int) ⇒ Object
Returns OP_1NEGATE, OP_0 .. OP_16 for ints from -1 to 16. Returns OP_INVALIDOPCODE for other ints.
19 20 21 22 23 24 25 26 27 |
# File 'lib/btcruby/script/opcode.rb', line 19 def opcode_for_small_integer(small_int) raise ArgumentError, "small_int must not be nil" if !small_int return OP_0 if small_int == 0 return OP_1NEGATE if small_int == -1 if small_int >= 1 && small_int <= 16 return OP_1 + (small_int - 1) end return OP_INVALIDOPCODE end |
#small_integer_from_opcode(opcode) ⇒ Object
Converts opcode OP_<N> or OP_1NEGATE to an integer value. If incorrect opcode is given, nil is returned.
31 32 33 34 35 36 37 38 39 |
# File 'lib/btcruby/script/opcode.rb', line 31 def small_integer_from_opcode(opcode) return 0 if opcode == "".b # OP_O return 0 if opcode == OP_0 return -1 if opcode == OP_1NEGATE if opcode >= OP_1 && opcode <= OP_16 return opcode - (OP_1 - 1) end return nil end |