Bitcoin-Crypto
view release on metacpan or search on metacpan
lib/Bitcoin/Crypto/PSBT.pm view on Meta::CPAN
Bitcoin::Crypto::Exception::PSBT->raise(
"PSBT output map index " . $map->index . " out of range"
) unless $map->index < $output_count;
}
foreach my $field (@{$map->fields}) {
Bitcoin::Crypto::Exception::PSBT->raise(
"PSBT field " . $field->type->name . " is not available in version $version"
) unless $field->type->available_in_version($version);
}
}
return $self;
}
sub dump
{
my ($self) = @_;
my @result;
my @maps = sort {
my $ret = $a->type cmp $b->type;
if ($ret == 0 && $a->need_index) {
$ret = $a->index <=> $b->index;
}
$ret;
} @{$self->maps};
foreach my $map (@maps) {
push @result, $map->name . ' map:';
my $dumped = $map->dump;
push @result, $dumped
if length $dumped;
}
return join "\n", @result;
}
1;
__END__
=head1 NAME
Bitcoin::Crypto::PSBT - Partially Signed Bitcoin Transactions
=head1 SYNOPSIS
use Bitcoin::Crypto qw(btc_psbt);
# import PSBT from a serialized form
my $psbt = btc_psbt->from_serialized([base64 => $psbt_string]);
# dump in readable format
print $psbt->dump;
# get a single PSBT field
my $field = $psbt->get_field('PSBT_GLOBAL_TX_VERSION');
# get decoded field key and value
my $key = $field->key;
my $value = $field->value;
# get all PSBT fields of a given type
my @fields = $psbt->get_all_fields('PSBT_GLOBAL_PROPRIETARY');
=head1 DESCRIPTION
This is a class implementing the PSBT format as described in BIP174 and
BIP370. It currently supports versions 0 and 2 of the spec. It allows
serialization, deserialization, validation and access to PSBT fields. It
currently does not support the roles defined by the PSBT documents, so all the
operations on PSBTs (like adding inputs or creating a final transaction out of
it) must be done manually.
PSBT consists of a number of maps: one global, one for each transaction input
and one for each transaction output. Each map holds a number of fields. Each
field has a value and can optionally have extra key data.
=head1 INTERFACE
=head2 Attributes
=head3 maps
B<Not assignable in the constructor>
An array reference of PSBT internal maps - objects of class
L<Bitcoin::Crypto::PSBT::Map>. It should seldom be handled manually - use
L</get_field>, L</get_all_fields> and L</add_field> to access fields of
specific map.
=head2 Methods
=head3 new
$psbt = $class->new(%args)
This is a standard Moo constructor, which can be used to create the object.
Returns class instance.
=head3 version
$version = $object->version()
Returns the version of the PSBT (C<0> or C<2>).
=head3 input_count
$int = $object->input_count()
Returns the number of inputs the PSBT defines.
=head3 output_count
$int = $object->output_count()
Returns the number of outputs the PSBT defines.
( run in 0.804 second using v1.01-cache-2.11-cpan-39bf76dae61 )