Class: Bitcoin::Taproot::LeafNode

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/taproot/leaf_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, leaf_ver = Bitcoin::TAPROOT_LEAF_TAPSCRIPT) ⇒ LeafNode

Initialize

Parameters:

  • script (Bitcoin::Script)

    Locking script

  • leaf_ver (Integer) (defaults to: Bitcoin::TAPROOT_LEAF_TAPSCRIPT)

    The leaf version of this script.

Raises:



10
11
12
13
14
# File 'lib/bitcoin/taproot/leaf_node.rb', line 10

def initialize(script, leaf_ver = Bitcoin::TAPROOT_LEAF_TAPSCRIPT)
  raise Taproot::Error, 'script must be Bitcoin::Script object' unless script.is_a?(Bitcoin::Script)
  @script = script
  @leaf_ver = leaf_ver
end

Instance Attribute Details

#leaf_verObject (readonly)

Returns the value of attribute leaf_ver.



5
6
7
# File 'lib/bitcoin/taproot/leaf_node.rb', line 5

def leaf_ver
  @leaf_ver
end

#scriptObject (readonly)

Returns the value of attribute script.



5
6
7
# File 'lib/bitcoin/taproot/leaf_node.rb', line 5

def script
  @script
end

Instance Method Details

#leaf_hashString

Calculate leaf hash.

Returns:



18
19
20
# File 'lib/bitcoin/taproot/leaf_node.rb', line 18

def leaf_hash
  @hash_value ||= Bitcoin.tagged_hash('TapLeaf', [leaf_ver].pack('C') + Bitcoin.pack_var_string(script.to_payload))
end