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::FieldType - PSBT field types

SYNOPSIS

        use Bitcoin::Crypto::PSBT::FieldType;

        my $type = Bitcoin::Crypto::PSBT::FieldType->get_field_by_name('PSBT_IN_OUTPUT_INDEX');

DESCRIPTION

This is both a library of field types and a small struct-like class for types.

An anonymous instance of this class can be created when a non-defined field type is encountered.

INTERFACE

Attributes

name

Required in the constructor. Name of the field type defined in BIP174.

code

Required in the constructor. Code of the field type defined in BIP174.

map_type

Available in the constructor. A map type this field belongs to. If not passed, it will be guessed from "name". Map types are defined as constants in Bitcoin::Crypto::Constants.

serializer

Available in the constructor. A coderef which will be used to do DWIM serialization of the value for easier handling. If not passed, a simple coderef will be installed which will only coerce format descriptions into bytestrings.

deserializer

Available in the constructor. A coderef which will be used to do DWIM deserialization of the value, the reverse of "serializer".

key_serializer

Available in the constructor. A coderef which will be used to do DWIM serialization of the key for easier handling. If not passed, a simple coderef will be installed which will only coerce format descriptions into bytestrings.

key_deserializer

Available in the constructor. A coderef which will be used to do DWIM deserialization of the key, the reverse of "key_serializer".

validator

Available in the constructor. A coderef which will be used to validate the value. It will be passed deserialized key (if available) and value. It should throw a string exception if it encounters a problem. This exception will be then turned to Bitcoin::Crypto::Exception::PSBT. The return value will be ignored.

predicate: has_validator

key_data

Available in the constructor. Key data of the field type. It should be a string describing what is the effect of deserialization and what the serializer expects. It may be undefined if the field does not support extra key data.

predicate: has_key_data

value_data

Required in the constructor. Value data of the field type. It should be a string describing what is the effect of deserialization and what the serializer expects.

version_status

Required in the constructor. A hash reference, where keys are PSBT versions and values are string, either required or available.

Methods

new

        $field = $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.

get_field_by_code

        $type = $class->get_field_by_code($map_type, $code)

Returns a field type with a given $code for $map_type.

If no such field is defined, a new unknown field type will be created.

get_field_by_name

        $type = $class->get_field_by_name($name)

Returns a field type with a given $name.

If no such field is defined, an exception will be thrown.

get_fields_required_in_version

        $fields_aref = $class->get_fields_required_in_version($version)

Returns an array reference of field types which are required in a given $version number.

required_in_version

        $boolean = $object->required_in_version($version)

Returns true if this field type is required in a given $version number.

available_in_version

        $boolean = $object->available_in_version($version)

Returns true if this field type is available in a given $version number.

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