lib/bitcoin/script.rb in bitcoin-ruby-0.0.4 vs lib/bitcoin/script.rb in bitcoin-ruby-0.0.5

- old
+ new

@@ -98,10 +98,11 @@ OP_DIV = 150 OP_MOD = 151 OP_LSHIFT = 152 OP_RSHIFT = 153 + OP_INVALIDOPCODE = 0xff OPCODES = Hash[*constants.grep(/^OP_/).map{|i| [const_get(i), i.to_s] }.flatten] OPCODES[0] = "0" OPCODES[81] = "1" @@ -445,11 +446,11 @@ @chunks[2].is_a?(String) && @chunks[2].bytesize == 20 end # is this a multisig tx def is_multisig? - return false if @chunks.size > 6 || @chunks.size < 4 + return false if @chunks.size > 6 || @chunks.size < 4 || !@chunks[-2].is_a?(Fixnum) @chunks[-1] == OP_CHECKMULTISIG and get_multisig_pubkeys.all?{|c| c.is_a?(String) } end # get type of this tx def type @@ -473,10 +474,11 @@ end # get the hash160 for this hash160 or pubkey script def get_hash160 return @chunks[2..-3][0].unpack("H*")[0] if is_hash160? + return @chunks[-2].unpack("H*")[0] if is_p2sh? return Bitcoin.hash160(get_pubkey) if is_pubkey? end # get the hash160 address for this hash160 script def get_hash160_address @@ -496,14 +498,19 @@ rescue OpenSSL::PKey::ECError, OpenSSL::PKey::EC::Point::Error end }.compact end + def get_p2sh_address + Bitcoin.hash160_to_p2sh_address(get_hash160) + end + # get all addresses this script corresponds to (if possible) def get_addresses return [get_pubkey_address] if is_pubkey? return [get_hash160_address] if is_hash160? return get_multisig_addresses if is_multisig? + return [get_p2sh_address] if is_p2sh? [] end # get single address, or first for multisig script def get_address