Skip to content

Commit

Permalink
Deprecate Script->get_script (use to_serialized)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Oct 7, 2023
1 parent 5012b4c commit 431ec12
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
16 changes: 4 additions & 12 deletions lib/Bitcoin/Crypto/Script.pm
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,12 @@ sub is_native_segwit
return 0 != grep { $script_type eq $_ } @segwit_types;
}

signature_for get_script => (
method => Object,
positional => [],
);

sub get_script
{
my ($self) = @_;

return $self->_serialized;
carp_once "Bitcoin::Crypto::Script->get_script is deprecated. Use Bitcoin::Crypto::Script->to_serialized instead.";
return $self->to_serialized;
}

signature_for get_hash => (
Expand Down Expand Up @@ -559,7 +555,7 @@ sub witness_program
my $program = Bitcoin::Crypto::Script->new(network => $self->network);
$program
->add_operation('OP_' . Bitcoin::Crypto::Constants::segwit_witness_version)
->push_bytes(sha256($self->get_script));
->push_bytes(sha256($self->to_serialized));

return $program;
}
Expand Down Expand Up @@ -682,7 +678,7 @@ Bitcoin::Crypto::Script - Bitcoin script instances
->add_operation('OP_EQUAL');
# getting serialized script
my $serialized = $script->get_script();
my $serialized = $script->to_serialized();
# getting address from script (p2wsh)
my $address = $script->get_segwit_adress();
Expand Down Expand Up @@ -788,10 +784,6 @@ Returns a serialized script as byte string.
Creates a new script instance from a bytestring.
=head2 get_script
Same as L</to_serialized>.
=head2 from_standard
$object = Bitcoin::Crypto::Script->from_standard([P2PKH => '1Ehr6cNDzPCx3wQRu1sMdXWViEi2MQnFzH'])
Expand Down
2 changes: 1 addition & 1 deletion lib/Bitcoin/Crypto/Transaction/Output.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ sub to_serialized

$serialized .= $self->value_serialized;

my $script = $self->locking_script->get_script;
my $script = $self->locking_script->to_serialized;
$serialized .= pack_varint(length $script);
$serialized .= $script;

Expand Down
2 changes: 1 addition & 1 deletion t/10-script/01-addresses.t
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ for my $info (@data) {
my $script = Bitcoin::Crypto::Script->new;
$info->{script}->($script);

is(lc unpack('H*', $script->get_script), $info->{serialized}, 'script created correctly');
is(lc unpack('H*', $script->to_serialized), $info->{serialized}, 'script created correctly');

my ($addr_legacy, $addr_compat, $addr_segwit) = @{$info->{addresses}};
is($script->get_legacy_address, $addr_legacy, 'legacy script address created correctly');
Expand Down

0 comments on commit 431ec12

Please sign in to comment.