NAME

Bitcoin::Crypto::Transaction::ControlBlock - BIP341 Control blocks

SYNOPSIS

# get control block from Bitcoin::Crypto::Script::Tree and $public_key
# (tree must have a leaf with id => $leaf_id)
my $control_block = $tree->get_control_block($leaf_id, $public_key);

# get serialized form of the control block (used in taproot script path spending)
$control_block->to_serialized;

DESCRIPTION

This module contains implementation of control blocks described in BIP341. These blocks are used by taproot and are necessary to build transactions using custom taproot scripts. Taproot outputs spent by scripts must have a serialized control block in their witness data (after the serialized script leaf data).

INTERFACE

Attributes

control_byte

Required in constructor.

This attribute contains a control byte in form of an integer.

public_key

Required in constructor.

This attribute contains an instance of Bitcoin::Crypto::Key::Public.

script_blocks

Required in constructor.

This attribute contains an array reference of bytestrings. It represents a path to build a merkle root for a tree. These blocks can be used in "from_path" in Bitcoin::Crypto::Script::Tree.

METHODS

new

$tree = $class->new(%args)

Standard Moo constructor - see "Attributes".

from_serialized

$object = $class->from_serialized($bytestr)

Standard deserialization method. Returns a new instance.

to_serialized

$bytestr = $object->to_serialized()

Standard serialization method.

get_leaf_version

$leaf_version = $object->get_leaf_version()

Returns a leaf version, which is equal to control_byte & 0xfe.

SEE ALSO

Bitcoin::Crypto::Script::Tree
Bitcoin::Crypto::Transaction