| 1 | package Bitcoin::Crypto::Transaction::Output; | ||||||||||||||||||||||||||||
| 2 | 34 | $Bitcoin::Crypto::Transaction::Output::VERSION = '4.005'; | |||||||||||||||||||||||||||
| 3 | 34 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 34 | ▶ | use Mooish::Base -standard; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 34 | ▶ | use Types::Common -sigs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 34 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 34 | ▶ | use Bitcoin::Crypto::Helpers qw(encode_64bit decode_64bit); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 34 | ▶ | use Bitcoin::Crypto::Util::Internal qw(pack_compactsize unpack_compactsize); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 34 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 34 | ▶ | use Bitcoin::Crypto::Constants qw(USE_BIGINTS); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 34 | has param 'value' => ( | |||||||||||||||||||||||||||
| 16 | writer => 1, | ||||||||||||||||||||||||||||
| 17 | coerce => SatoshiAmount, | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 34 | has param 'locking_script' => ( | |||||||||||||||||||||||||||
| 21 | coerce => BitcoinScript, | ||||||||||||||||||||||||||||
| 22 | writer => 1, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 34 | with qw( | |||||||||||||||||||||||||||
| 26 | Bitcoin::Crypto::Role::ShallowClone | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub is_standard | ||||||||||||||||||||||||||||
| 30 | 121 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_standard: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 121 | my ($self) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 121 | return $self->locking_script->has_type; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub set_max_value | ||||||||||||||||||||||||||||
| 37 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_max_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | if (USE_BIGINTS) { | |||||||||||||||||||||||||||
| 41 | $self->set_value('0xffffffffffffffff'); | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | 1 | $self->set_value((1 << 63) - 1 + (1 << 63)); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | return $self; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub value_serialized | ||||||||||||||||||||||||||||
| 51 | 1080 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
value_serialized: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 1080 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1080 | return encode_64bit($self->value); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub to_serialized | ||||||||||||||||||||||||||||
| 58 | 903 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
to_serialized: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 903 | my ($self) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # output should be serialized as follows: | ||||||||||||||||||||||||||||
| 62 | # - value, 8 bytes | ||||||||||||||||||||||||||||
| 63 | # - locking script length, 1-9 bytes | ||||||||||||||||||||||||||||
| 64 | # - locking script | ||||||||||||||||||||||||||||
| 65 | 903 | my $serialized = $self->value_serialized; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 903 | my $script = $self->locking_script->to_serialized; | |||||||||||||||||||||||||||
| 68 | 903 | $serialized .= pack_compactsize(length $script) . $script; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 903 | return $serialized; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 34 | signature_for from_serialized => ( | |||||||||||||||||||||||||||
| 74 | method => !!1, | ||||||||||||||||||||||||||||
| 75 | head => [ByteStr], | ||||||||||||||||||||||||||||
| 76 | named => [ | ||||||||||||||||||||||||||||
| 77 | pos => Maybe [ScalarRef [PositiveOrZeroInt]], | ||||||||||||||||||||||||||||
| 78 | {default => undef}, | ||||||||||||||||||||||||||||
| 79 | ], | ||||||||||||||||||||||||||||
| 80 | bless => !!0, | ||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub from_serialized | ||||||||||||||||||||||||||||
| 84 | 916 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
from_serialized: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 85 | 916 | my ($class, $serialized, $args) = @_; | |||||||||||||||||||||||||||
| 86 | 916 | my $partial = !!$args->{pos}; | |||||||||||||||||||||||||||
| 87 | 916 | ▶ | my $pos = $partial ? ${$args->{pos}} : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 916 | my $value = substr $serialized, $pos, 8; | |||||||||||||||||||||||||||
| 90 | 916 | $pos += 8; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 916 | $value = decode_64bit($value); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 916 | my $script_size = unpack_compactsize $serialized, \$pos; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 916 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 'serialized input script data is corrupted' | ||||||||||||||||||||||||||||
| 98 | ) if $pos + $script_size > length $serialized; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 916 | my $script = substr $serialized, $pos, $script_size; | |||||||||||||||||||||||||||
| 101 | 916 | $pos += $script_size; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 916 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $partial and $pos != length $serialized
MC/DC0%0/2
not $partial and $pos != length $serialized
not $partial
$pos != length $serialized
Truth table66%2/3
not(A) and B
A= not $partialB= $pos != length $serialized
| |||||||||||||||||||||||||||||
| 104 | 'serialized output data is corrupted' | ||||||||||||||||||||||||||||
| 105 | ) if !$partial && $pos != length $serialized; | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 916 | ▶ | ${$args->{pos}} = $pos | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | if $partial; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 916 | return $class->new( | |||||||||||||||||||||||||||
| 111 | value => $value, | ||||||||||||||||||||||||||||
| 112 | locking_script => $script, | ||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub dump | ||||||||||||||||||||||||||||
| 117 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dump: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | ▶ | my $type = $self->locking_script->type // 'Custom'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->locking_script->type // "Custom"
MC/DC0%0/1
$self->locking_script->type // "Custom"
$self->locking_script->type
Truth table50%1/2
A
A= $self->locking_script->type
| |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | my $address = $self->locking_script->get_address // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->locking_script->get_address // ""
MC/DC0%0/1
$self->locking_script->get_address // ""
$self->locking_script->get_address
Truth table50%1/2
A
A= $self->locking_script->get_address
| |||||||||||||||||||||||||||||
| 122 | 1 | ▶ | $address = " to $address" if $address; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | my @result; | |||||||||||||||||||||||||||
| 125 | 1 | push @result, "$type Output$address"; | |||||||||||||||||||||||||||
| 126 | 1 | push @result, 'value: ' . $self->value; | |||||||||||||||||||||||||||
| 127 | 1 | push @result, 'locking script: ' . $self->locking_script->dump; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | return join "\n", @result; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 34 | 1; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||