lib/bitcoin/opcodes.rb in bitcoinrb-0.5.0 vs lib/bitcoin/opcodes.rb in bitcoinrb-0.6.0
- old
+ new
@@ -134,19 +134,24 @@
OP_NOP7 = 0xb6
OP_NOP8 = 0xb7
OP_NOP9 = 0xb8
OP_NOP10 = 0xb9
+ OP_CHECKSIGADD = 0xba # BIP 342 opcodes (Tapscript)
+
# https://en.bitcoin.it/wiki/Script#Pseudo-words
OP_PUBKEYHASH = 0xfd
OP_PUBKEY = 0xfe
OP_INVALIDOPCODE = 0xff
DUPLICATE_KEY = [:OP_NOP2, :OP_NOP3]
OPCODES_MAP = Hash[*(constants.grep(/^OP_/) - [:OP_NOP2, :OP_NOP3, :OP_CHECKLOCKTIMEVERIFY, :OP_CHECKSEQUENCEVERIFY]).map { |c| [const_get(c), c.to_s] }.flatten]
NAME_MAP = Hash[*constants.grep(/^OP_/).map { |c| [c.to_s, const_get(c)] }.flatten]
+ OP_SUCCESSES = [0x50, 0x62, 0x89, 0x8a, 0x8d, 0x8e, (0x7e..0x81).to_a,
+ (0x83..0x86).to_a, (0x95..0x99).to_a, (0xbb..0xfe).to_a].flatten
+
def opcode_to_name(opcode)
return OPCODES_MAP[opcode].delete('OP_') if opcode == OP_0 || (opcode <= OP_16 && opcode >= OP_1)
OPCODES_MAP[opcode]
end
@@ -154,11 +159,12 @@
return NAME_MAP['OP_' + name] if name =~ /^\d/ && name.to_i < 17 && name.to_i > -1
NAME_MAP[name]
end
# whether opcode is predefined opcode
- def defined?(opcode)
+ def defined?(opcode, allow_success = false)
+ return true if allow_success && op_success?(opcode)
!opcode_to_name(opcode).nil?
end
def small_int_to_opcode(int)
return OP_0 if int == 0
@@ -170,9 +176,16 @@
def opcode_to_small_int(opcode)
return 0 if opcode == ''.b || opcode == OP_0
return -1 if opcode == OP_1NEGATE
return opcode - (OP_1 - 1) if opcode >= OP_1 && opcode <= OP_16
nil
+ end
+
+ # Check whether +opcode+ is OP_SUCCESSx or not?
+ # @param [Integer] opcode an opcode.
+ # @return [Boolean] if +opcode+ is OP_SUCCESSx return true, otherwise false.
+ def op_success?(opcode)
+ OP_SUCCESSES.include?(opcode)
end
end
end
\ No newline at end of file