Skip to content

Commit 11e0d12

Browse files
committed
fix broken script types in namecoin module
1 parent 86de930 commit 11e0d12

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

lib/bitcoin/namecoin.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,15 @@ def get_hash160
3737
end
3838

3939
# get all addresses this script corresponds to (if possible)
40-
def get_addresses
40+
def new_get_addresses
4141
return [get_pubkey_address] if is_pubkey?
42-
return [get_hash160_address] if is_hash160? || is_namecoin?
42+
return [get_hash160_address] if is_pubkey_hash? || is_namecoin?
4343
return get_multisig_addresses if is_multisig?
44+
return [get_p2sh_address] if is_script_hash?
45+
[]
4446
end
4547

46-
# get type of this tx
47-
def type
48-
if is_name_new?; :name_new
49-
elsif is_name_firstupdate?; :name_firstupdate
50-
elsif is_name_update?; :name_update
51-
elsif is_pubkey_hash?; :pubkey_hash
52-
elsif is_pubkey?; :pubkey
53-
elsif is_multisig?; :multisig
54-
elsif is_script_hash?; :script_hash
55-
else; :unknown
56-
end
57-
end
48+
TYPES.unshift :name_new, :name_firstupdate, :name_update
5849

5950
# is namecoin name_new script
6051
# OP_1 name_hash OP_2DROP <hash160_script>

lib/bitcoin/script.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,14 @@ def is_op_return?
492492
@chunks[0] == OP_RETURN && @chunks.size <= 2
493493
end
494494

495+
TYPES = [:pubkey_hash, :pubkey, :multisig, :script_hash, :op_return]
496+
495497
# get type of this script
496498
def type
497-
if is_pubkey_hash?; :pubkey_hash
498-
elsif is_pubkey?; :pubkey
499-
elsif is_multisig?; :multisig
500-
elsif is_p2sh?; :script_hash
501-
elsif is_op_return?;:op_return
502-
else; :unknown
499+
TYPES.each do |type|
500+
return type if send("is_#{type}?")
503501
end
502+
:unknown
504503
end
505504

506505
# get the public key for this pubkey script

lib/bitcoin/storage/storage.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ class StoreBase
4343
ORPHAN = 2
4444

4545
# possible script types
46-
SCRIPT_TYPES = [:unknown, :pubkey, :pubkey_hash, :multisig, :script_hash, :op_return]
47-
if Bitcoin.namecoin?
48-
[:name_new, :name_firstupdate, :name_update].each {|n| SCRIPT_TYPES << n }
49-
end
46+
SCRIPT_TYPES = [:unknown] + Bitcoin::Script::TYPES
5047

5148
# possible address types
5249
ADDRESS_TYPES = [:pubkey_hash, :script_hash]

0 commit comments

Comments
 (0)