Skip to content

Commit

Permalink
Documentation and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Jul 24, 2024
1 parent b04339c commit 247b0f6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 31 deletions.
4 changes: 4 additions & 0 deletions lib/Bitcoin/Crypto.pm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ Loads L<Bitcoin::Crypto::Transaction::UTXO>
Loads L<Bitcoin::Crypto::Block>
=head2 btc_psbt
Loads L<Bitcoin::Crypto::PSBT>
=head1 SEE ALSO
L<Bitcoin::RPC::Client>
Expand Down
10 changes: 5 additions & 5 deletions lib/Bitcoin/Crypto/DerivationPath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ the C<m> notation. It is returned by L<Bitcoin::Crypto::Util/get_path_info>.
=head3 private
B<Required>. A boolean - whether the path is private (started with lowercase
B<Required in the constructor>. A boolean - whether the path is private (started with lowercase
C<m>).
=head3 path
B<Required>. An array reference of unsigned integers - the derivation path.
Hardened keys are greater than or equal to 2^32
B<Required in the constructor>. An array reference of unsigned integers - the derivation path.
Hardened keys are greater than or equal to C<2^31>
(C<Bitcoin::Crypto::Constants::max_child_keys>).
=head2 Methods
=head3 from_string
my $path = Bitcoin::Crypto::DerivationPath->from_string($m_notation_string)
$path = Bitcoin::Crypto::DerivationPath->from_string($m_notation_string)
Constructs a new derivation path based on the string.
=head3 get_derivation_path
my $self = $path->get_derivation_path()
$path = $path->get_derivation_path()
A helper which returns self.
12 changes: 6 additions & 6 deletions lib/Bitcoin/Crypto/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ including running the script step by step, stopping after each opcode.

=item * work with Bitcoin-related encodings

There are L<Bitcoin::Crypto::Base58> and L<Bitcoin::Crypto::Bech32>. You can
validate an address and get its type using
L<Bitcoin::Crypto::Util/get_address_type>.
There are L<Bitcoin::Crypto::Base58> and L<Bitcoin::Crypto::Bech32>. PSBT
format is supported in L<Bitcoin::Crypto::PSBT>. You can validate an address
and get its type using L<Bitcoin::Crypto::Util/get_address_type>.

=item * work with other cryptocurrencies

Expand Down Expand Up @@ -136,11 +136,11 @@ Currently supported values for the first argument are:

=over

=item C<hex> (hexadecimal string, may be prefixed by C<0x>)
=item * C<hex> (hexadecimal string, may be prefixed by C<0x>)

=item C<base58> (base58-encoded string with the checksum)
=item * C<base58> (base58-encoded string with the checksum)

=item C<base64> (base64-encoded string)
=item * C<base64> (base64-encoded string)

=back

Expand Down
8 changes: 4 additions & 4 deletions lib/Bitcoin/Crypto/PSBT/FieldType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ my %types = (
%uint_32bitLE_serializers,
validator => sub {
my ($value) = @_;
die 'must be greather than or equal to 500000000'
if $value < 500000000;
die 'must be greather than or equal to ' . Bitcoin::Crypto::Constants::locktime_height_threshold
if $value < Bitcoin::Crypto::Constants::locktime_height_threshold;
},
version_status => {
2 => AVAILABLE,
Expand All @@ -514,8 +514,8 @@ my %types = (
%uint_32bitLE_serializers,
validator => sub {
my ($value) = @_;
die 'must be less than 500000000'
unless $value < 500000000;
die 'must be less than ' . Bitcoin::Crypto::Constants::locktime_height_threshold
unless $value < Bitcoin::Crypto::Constants::locktime_height_threshold;
},
version_status => {
2 => AVAILABLE,
Expand Down
8 changes: 4 additions & 4 deletions lib/Bitcoin/Crypto/Transaction.pm
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,10 @@ data. Note that this is a no-op in non-segwit transactions.
Deserializes the bytestring C<$data> into a transaction object.
Keep in mind deserialization requires a full set of UTXO to be registered. If
they are not, an exception will be raised with missing transaction id and
output index, which should help you fill in the blanks. See
L<Bitcoin::Crypto::Transaction::UTXO> for details.
Keep in mind it's best to have a full set of UTXOs registered. If they are not,
an exception may be raised if a function requires full UTXO data. That
exception will contain transaction ID and output index, which should help you
fill in the blanks. See L<Bitcoin::Crypto::Transaction::UTXO> for details.
=head3 get_hash
Expand Down
5 changes: 3 additions & 2 deletions lib/Bitcoin/Crypto/Transaction/Input.pm
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ Returns boolean value indicating whether UTXO for this input is reachable. If
it isn't, getting L</utxo> will throw an exception.
Creating transactions without registered UTXOs will work in very basic cases
but can randomly throw C<Bitcoin::Crypto::Exception::UTXO> exception. It is
mainly useful for getting data encoded in a serialized transaction.
but can raise C<Bitcoin::Crypto::Exception::UTXO> exception if a function
cannot be finished without a full UTXO data. It is mainly useful for getting
data encoded in a serialized transaction.
=head3 to_serialized
Expand Down
5 changes: 3 additions & 2 deletions lib/Bitcoin/Crypto/Transaction/UTXO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ Bitcoin::Crypto::Transaction::UTXO - Unspent transaction output instance
=head1 DESCRIPTION
UTXO is a transaction output which hasn't been spent yet. All transaction
inputs must be UTXOs. Bitcoin::Crypto requires you to register UTXOs before you
can create a transaction.
inputs must be UTXOs. You need to register UTXOs before you can fully utilize a
transaction. If a transaction has its UTXOs unregistered, its methods may raise
an exception if they require full UTXO data.
=head1 INTERFACE
Expand Down
20 changes: 12 additions & 8 deletions lib/Bitcoin/Crypto/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,17 @@ manual unpacking.
Supported C<$format> values are:
C<bytes>, does nothing
=over
C<hex>, encodes as a hexadecimal string (no C<0x> prefix)
=item * C<bytes>, does nothing
C<base58>, uses base58 and includes the checksum (base58check)
=item * C<hex>, encodes as a hexadecimal string (no C<0x> prefix)
C<base64>, uses base64
=item * C<base58>, uses base58 and includes the checksum (base58check)
=item * C<base64>, uses base64
=back
=head2 from_format
Expand All @@ -594,13 +598,13 @@ parameter of the module will do this conversion implicitly.>
=head2 pack_compactsize
my $bytestr = pack_compactsize($integer);
$bytestr = pack_compactsize($integer);
Serializes C<$integer> as Bitcoin's CompactSize format and returns it as a byte string.
=head2 unpack_compactsize
my $integer = unpack_compactsize($bytestr, $pos = undef);
$integer = unpack_compactsize($bytestr, $pos = undef);
Deserializes CompactSize from C<$bytestr>, returning an integer.
Expand All @@ -611,13 +615,13 @@ an exception if C<$bytestr> contains anything other than CompactSize.
=head2 hash160
my $hash = hash160($data);
$hash = hash160($data);
This is hash160 used by Bitcoin (C<RIPEMD160> of C<SHA256>)
=head2 hash256
my $hash = hash256($data);
$hash = hash256($data);
This is hash256 used by Bitcoin (C<SHA256> of C<SHA256>)
Expand Down
4 changes: 4 additions & 0 deletions t/40-transaction/80-edge-cases.t
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ subtest 'should be able to create transactions without registered UTXOs' => sub
);

ok !defined $tx->fee, 'fee is not defined without the UTXOs';

throws_ok {
$tx->verify;
} 'Bitcoin::Crypto::Exception::UTXO';
};

done_testing;
Expand Down

0 comments on commit 247b0f6

Please sign in to comment.