Class: Bitcoin::Descriptor::Combo

Inherits:
KeyExpression show all
Defined in:
lib/bitcoin/descriptor/combo.rb

Overview

combo() expression

Instance Attribute Summary

Attributes inherited from KeyExpression

#key

Instance Method Summary collapse

Methods inherited from KeyExpression

#args, #extracted_key, #initialize, #musig?

Methods inherited from Expression

#args, #compressed_key?, #derive_path, #extract_pubkey, #to_s, #to_script

Constructor Details

This class inherits a constructor from Bitcoin::Descriptor::KeyExpression

Instance Method Details

#==(other) ⇒ Object



24
25
26
27
# File 'lib/bitcoin/descriptor/combo.rb', line 24

def ==(other)
  return false unless other.is_a?(Combo)
  type == other.type && to_scripts == other.to_scripts
end

#to_hexObject

Raises:

  • (ArgumentError)


10
11
12
# File 'lib/bitcoin/descriptor/combo.rb', line 10

def to_hex
  raise ArgumentError, 'musig() is not allowed in top-level combo().' if musig?
end

#to_scriptsObject



14
15
16
17
18
19
20
21
22
# File 'lib/bitcoin/descriptor/combo.rb', line 14

def to_scripts
  candidates = [Pk.new(key), Pkh.new(key)]
  pubkey = extracted_key
  if pubkey.compressed?
    candidates << Wpkh.new(pubkey.pubkey)
    candidates << Sh.new(candidates.last)
  end
  candidates.map(&:to_script)
end

#top_level?Boolean



29
30
31
# File 'lib/bitcoin/descriptor/combo.rb', line 29

def top_level?
  true
end

#typeObject



6
7
8
# File 'lib/bitcoin/descriptor/combo.rb', line 6

def type
  :combo
end