Skip to content

Commit

Permalink
Add Bitcoin::Descriptor::KeyExpression#extracted_key
Browse files Browse the repository at this point in the history
  • Loading branch information
azuchi committed Jul 14, 2024
1 parent 6f72a45 commit 1164a77
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/bitcoin/descriptor/combo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def type

def to_scripts
candidates = [Pk.new(key), Pkh.new(key)]
pubkey = extract_pubkey(key)
pubkey = extracted_key
if pubkey.compressed?
candidates << Wpkh.new(pubkey.pubkey)
candidates << Sh.new(candidates.last)
Expand Down
7 changes: 7 additions & 0 deletions lib/bitcoin/descriptor/key_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def args
def top_level?
false
end

# Get extracted key.
# @return [Bitcoin::Key] Extracted key.
def extracted_key
extract_pubkey(key)
end

end
end
end
2 changes: 1 addition & 1 deletion lib/bitcoin/descriptor/pk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def type
# Convert to bitcoin script.
# @return [Bitcoin::Script]
def to_script
k = extract_pubkey(key)
k = extracted_key
target_key = xonly ? k.xonly_pubkey : k.pubkey
Bitcoin::Script.new << target_key << OP_CHECKSIG
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bitcoin/descriptor/pkh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def type
end

def to_script
Script.to_p2pkh(extract_pubkey(key).hash160)
Script.to_p2pkh(extracted_key.hash160)
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/bitcoin/descriptor/raw_tr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def top_level?
end

def to_script
k = extract_pubkey(key)
Bitcoin::Script.new << OP_1 << k.xonly_pubkey
Bitcoin::Script.new << OP_1 << extract_pubkey(key).xonly_pubkey
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bitcoin/descriptor/wpkh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def type
end

def to_script
Script.to_p2wpkh(extract_pubkey(key).hash160)
Script.to_p2wpkh(extracted_key.hash160)
end
end
end
Expand Down

0 comments on commit 1164a77

Please sign in to comment.