Class: Bitcoin::Descriptor::Multi

Inherits:
Expression show all
Defined in:
lib/bitcoin/descriptor/multi.rb

Overview

multi() expression

Direct Known Subclasses

MultiA, SortedMulti

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#==, #compressed_key?, #derive_path, #extract_pubkey, #to_s

Constructor Details

#initialize(threshold, keys) ⇒ Multi

Returns a new instance of Multi.

[View source]

9
10
11
12
13
# File 'lib/bitcoin/descriptor/multi.rb', line 9

def initialize(threshold, keys)
  validate!(threshold, keys)
  @threshold = threshold
  @keys = keys
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.


7
8
9
# File 'lib/bitcoin/descriptor/multi.rb', line 7

def keys
  @keys
end

#thresholdObject (readonly)

Returns the value of attribute threshold.


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

def threshold
  @threshold
end

Instance Method Details

#argsObject

[View source]

30
31
32
# File 'lib/bitcoin/descriptor/multi.rb', line 30

def args
  "#{threshold},#{keys.join(',')}"
end

#to_hexObject

Raises:

  • (RuntimeError)
[View source]

23
24
25
26
27
28
# File 'lib/bitcoin/descriptor/multi.rb', line 23

def to_hex
  result = to_script
  pubkey_count = result.get_pubkeys.length
  raise RuntimeError, "Cannot have #{pubkey_count} pubkeys in bare multisig; only at most 3 pubkeys." if pubkey_count > 3
  result.to_hex
end

#to_scriptObject

[View source]

19
20
21
# File 'lib/bitcoin/descriptor/multi.rb', line 19

def to_script
  Script.to_multisig_script(threshold, keys.map{|key| extract_pubkey(key).pubkey }, sort: false)
end

#top_level?Boolean

Returns:

  • (Boolean)
[View source]

34
35
36
# File 'lib/bitcoin/descriptor/multi.rb', line 34

def top_level?
  false
end

#typeObject

[View source]

15
16
17
# File 'lib/bitcoin/descriptor/multi.rb', line 15

def type
  :multi
end