Class: Bitcoin::Descriptor::Tr

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

Overview

tr() expression.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

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

Constructor Details

#initialize(key, tree = nil) ⇒ Tr

Constructor.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/bitcoin/descriptor/tr.rb', line 11

def initialize(key, tree = nil)
  raise ArgumentError, "Key must be string." unless key.is_a?(String)
  k = extract_pubkey(key)
  raise ArgumentError, "Uncompressed key are not allowed." unless k.compressed?
  validate_tree!(tree)
  @key = key
  @tree = tree
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#treeObject (readonly)

Returns the value of attribute tree.



8
9
10
# File 'lib/bitcoin/descriptor/tr.rb', line 8

def tree
  @tree
end

Instance Method Details

#argsObject



28
29
30
31
32
33
34
# File 'lib/bitcoin/descriptor/tr.rb', line 28

def args
  if tree.nil?
    key
  else
    tree.is_a?(Array) ? "#{key},#{tree_string(tree)}" : "#{key},#{tree}"
  end
end

#to_scriptObject



36
37
38
39
# File 'lib/bitcoin/descriptor/tr.rb', line 36

def to_script
  builder = build_tree_scripts
  builder.build
end

#top_level?Boolean

Returns:

  • (Boolean)


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

def top_level?
  true
end

#typeObject



20
21
22
# File 'lib/bitcoin/descriptor/tr.rb', line 20

def type
  :tr
end