The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bitcoin::Crypto::PSBT::Map - Single map of a PSBT

SYNOPSIS

        use Bitcoin::Crypto qw(btc_psbt);

        my $maps = btc_psbt->from_serialized([base64 => $psbt_string])->maps;

DESCRIPTION

This is a helper class which holds a number of PSBT fields in a single namespace.

INTERFACE

Attributes

type

Required in the constructor. The type of the map. Must be one of the psbt_*_map constants defined in Bitcoin::Crypto::Constants.

index

Available in the constructor. This is the index of this map. It is required for input and output maps and will be ignored for global maps.

fields

An array reference holding the fields for this map, instances of Bitcoin::Crypto::PSBT::Field.

Methods

new

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

This is a standard Moo constructor, which can be used to create the object. It takes arguments specified in "Attributes".

Returns class instance.

name

        $name = $map->name()

Returns a human-readabable name of this map.

need_index

        $bool = $map->need_index;

Whether this map requires an index.

add

        $map = $map->add($field);

Same as "add_field" in Bitcoin::Crypto::PSBT, but only accepts a constructed field. There is also no need to specify the index, since the map knows its own index.

find

        @fields = $map->find($field_type, $key = undef);

Similar to "get_all_fields" in Bitcoin::Crypto::PSBT. Instead of index, accepts raw $key data as second argument.

to_serialized

        $serialized = $object->to_serialized()

Serializes a map into a bytestring.

from_serialized

        $object = $class->from_serialized($data, %params)

Deserializes the bytestring $data into a map.

%params can be any of:

  • map_type

    A constant for map type - required.

  • index

    An index of the map. Required if the map is for input or for output.

  • pos

    Position for partial string decoding. Optional. If passed, must be a scalar reference to an integer value.

    This integer will mark the starting position of $bytestring from which to start decoding. It will be set to the next byte after end of input stream.

dump

        $text = $object->dump()

Returns a readable description of all the fields in the map.

EXCEPTIONS

This module throws an instance of Bitcoin::Crypto::Exception if it encounters an error. It can produce the following error types from the Bitcoin::Crypto::Exception namespace:

  • PSBT - general error with the PSBT

SEE ALSO

Bitcoin::Crypto::PSBT
Bitcoin::Crypto::PSBT::Field