| 1 | package Bitcoin::Crypto::Transaction; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 38 | $Bitcoin::Crypto::Transaction::VERSION = '4.006'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 38 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 38 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 38 | ▶ | use Mooish::Base -standard; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 38 | ▶ | use Types::Common -sigs; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 38 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 38 | ▶ | use Carp qw(carp); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 38 | ▶ | use List::Util qw(any uniqstr); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 38 | ▶ | use Feature::Compat::Try; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 38 | ▶ | use Bitcoin::Crypto qw(btc_pub btc_script btc_tapscript btc_script_tree btc_utxo); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 38 | ▶ | use Bitcoin::Crypto::Constants qw(:script :transaction :coin); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 38 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 38 | ▶ | use Bitcoin::Crypto::Transaction::Input; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 38 | ▶ | use Bitcoin::Crypto::Transaction::Output; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 38 | ▶ | use Bitcoin::Crypto::Transaction::Digest; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 38 | ▶ | use Bitcoin::Crypto::Util::Internal qw(pack_compactsize unpack_compactsize hash256 to_format lift_x has_even_y); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 38 | ▶ | use Bitcoin::Crypto::Helpers qw(die_no_trace); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 38 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 38 | ▶ | use Bitcoin::Crypto::Script::Common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 38 | ▶ | use Bitcoin::Crypto::Script::Tree; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 38 | ▶ | use Bitcoin::Crypto::Transaction::ControlBlock; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 38 | ▶ | use Bitcoin::Crypto::Transaction::Flags; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 38 | ▶ | use Bitcoin::Crypto::Transaction::Signer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 38 | has param 'version' => ( | |||||||||||||||||||||||||||||||||||||||||
| 29 | isa => IntMaxBits [32], | ||||||||||||||||||||||||||||||||||||||||||
| 30 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 38 | has option 'block' => ( | |||||||||||||||||||||||||||||||||||||||||
| 34 | isa => InstanceOf ['Bitcoin::Crypto::Block'], | ||||||||||||||||||||||||||||||||||||||||||
| 35 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | writer => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | has field 'inputs' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 40 | isa => ArrayRef [InstanceOf ['Bitcoin::Crypto::Transaction::Input']], | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 700 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 38 | ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | has field 'outputs' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | isa => ArrayRef [InstanceOf ['Bitcoin::Crypto::Transaction::Output']], | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 700 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 38 | ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 38 | has param 'locktime' => ( | |||||||||||||||||||||||||||||||||||||||||
| 50 | isa => IntMaxBits [32], | ||||||||||||||||||||||||||||||||||||||||||
| 51 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # used to mark whether the transaction was serialized with witness data, even | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # if no actual witness data was present (it was empty) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 38 | has param 'had_witness_flag' => ( | |||||||||||||||||||||||||||||||||||||||||
| 57 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | default => !!0, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | has field '_digest_object' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 62 | isa => InstanceOf ['Bitcoin::Crypto::Transaction::Digest'], | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 131 | ▶ | lazy => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 131 | Bitcoin::Crypto::Transaction::Digest->new(transaction => shift); | |||||||||||||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 38 | clearer => -public, | |||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 38 | with qw( | |||||||||||||||||||||||||||||||||||||||||
| 70 | Bitcoin::Crypto::Role::ShallowClone | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 157 | ▶ | after _cloned => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 157 | shift->clear_digest_object; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 38 | }; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub add_input | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 149 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_input: called CC=4 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 149 | my ($self, @data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 149 | my $input; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 149 | ▶ | if (@data == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $input = $data[0]; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($input) and $input->isa("Bitcoin::Crypto::Transaction::Input")
MC/DC0%0/2
builtin::blessed($input) and $input->isa("Bitcoin::Crypto::Transaction::Input")
builtin::blessed($input)
$input->isa("Bitcoin::Crypto::Transaction::Input")
Truth table0%0/3
A and B
A= builtin::blessed($input)B= $input->isa("Bitcoin::Crypto::Transaction::Input")
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 'expected an input object' | ||||||||||||||||||||||||||||||||||||||||||
| 87 | ) unless blessed $input && $input->isa('Bitcoin::Crypto::Transaction::Input'); | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 149 | $input = Bitcoin::Crypto::Transaction::Input->new(@data); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 149 | push @{$self->inputs}, $input; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 149 | $self->clear_digest_object; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 149 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | sub add_output | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 142 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_output: called CC=4 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 142 | my ($self, @data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 142 | my $output; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 142 | ▶ | if (@data == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $output = $data[0]; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($output) and $output->isa("Bitcoin::Crypto::Transaction::Output")
MC/DC0%0/2
builtin::blessed($output) and $output->isa("Bitcoin::Crypto::Transaction::Output")
builtin::blessed($output)
$output->isa("Bitcoin::Crypto::Transaction::Output")
Truth table0%0/3
A and B
A= builtin::blessed($output)B= $output->isa("Bitcoin::Crypto::Transaction::Output")
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 'expected an output object' | ||||||||||||||||||||||||||||||||||||||||||
| 108 | ) unless blessed $output && $output->isa('Bitcoin::Crypto::Transaction::Output'); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 142 | $output = Bitcoin::Crypto::Transaction::Output->new(@data); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 142 | push @{$self->outputs}, $output; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 142 | $self->clear_digest_object; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 142 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 38 | signature_for to_serialized => ( | |||||||||||||||||||||||||||||||||||||||||
| 120 | method => !!1, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | named => [ | ||||||||||||||||||||||||||||||||||||||||||
| 122 | witness => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | {default => 1}, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 125 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | sub to_serialized | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 404 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_serialized: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 404 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 404 | my $inputs = $self->inputs; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 404 | my $outputs = $self->outputs; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # NOTE: this avoids the bug where segwit flag 0x0001 may get recognized | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # from a transaction with no witness data, but zero inputs. We can't simply | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # disallow empty transactions, as some code may use them. The middle ground | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # is to disallow transactions that may trigger this problem - 0 inputs, and | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # >0 outputs. More broad criteria (>0 outputs rather than 1 output) will | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # help users to spot the problem sooner | ||||||||||||||||||||||||||||||||||||||||||
| 141 | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 'cannot serialize a transaction with zero inputs and non-zero outputs' | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 404 | ▶ | ) if @{$inputs} == 0 && @{$outputs} > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$inputs;} == 0 and @{$outputs;} > 0
MC/DC100%2/2
@{$inputs;} == 0 and @{$outputs;} > 0
@{$inputs;} == 0
@{$outputs;} > 0
Truth table100%3/3
A and B
A= @{$inputs;} == 0B= @{$outputs;} > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | my $with_witness = $args->{witness} | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 403 | ▶ | && ($self->had_witness_flag || any { $_->has_witness } @{$inputs}); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Condition100%6/6
$args->{'witness'} && ($self->had_witness_flag || &any(sub {
$_->has_witness;
}
, @{$inputs;}))
$self->had_witness_flag or &any(sub {
$_->has_witness;
}
, @{$inputs;})
MC/DC100%3/3
$args->{'witness'} && ($self->had_witness_flag || &any(sub {
$_->has_witness;
}
, @{$inputs;}))
$args->{'witness'}
$self->had_witness_flag
&any(sub {
$_->has_witness;
}
, @{$inputs;})
Truth table100%4/4
A && B or C
A= $args->{'witness'}B= $self->had_witness_flagC= &any(sub {
$_->has_witness;
}
, @{$inputs;})
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # transaction should be serialized as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 149 | # - version, 4 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 150 | # - number of inputs, 1-9 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 151 | # - serialized inputs | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # - number of outputs, 1-9 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # - serialized outputs | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # - lock time, 4 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | # segwit transaction should be serialized as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 157 | # - version, 4 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # - 0x0001, if witness data is present | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # - number of inputs, 1-9 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # - serialized inputs | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # - number of outputs, 1-9 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # - serialized outputs | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # - witness data | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # - lock time, 4 bytes | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 403 | my $serialized = pack 'V', $self->version; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 403 | ▶ | $serialized .= pack 'n', 0x0001 if $with_witness; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | # Process inputs | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 403 | $serialized .= pack_compactsize(scalar @{$inputs}); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 403 | $serialized .= join '', map { $_->to_serialized } @{$inputs}; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Process outputs | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 403 | $serialized .= pack_compactsize(scalar @{$outputs}); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 403 | $serialized .= join '', map { $_->to_serialized } @{$outputs}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 403 | ▶ | $serialized .= join '', map { $_->serialized_witness } @{$inputs} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | if $with_witness; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 403 | $serialized .= pack 'V', $self->locktime; | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 403 | return $serialized; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 38 | signature_for from_serialized => ( | |||||||||||||||||||||||||||||||||||||||||
| 186 | method => !!1, | ||||||||||||||||||||||||||||||||||||||||||
| 187 | head => [ByteStr], | ||||||||||||||||||||||||||||||||||||||||||
| 188 | named => [ | ||||||||||||||||||||||||||||||||||||||||||
| 189 | pos => Maybe [ScalarRef [PositiveOrZeroInt]], | ||||||||||||||||||||||||||||||||||||||||||
| 190 | {default => undef}, | ||||||||||||||||||||||||||||||||||||||||||
| 191 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 192 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | sub from_serialized | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 565 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_serialized: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 565 | my ($class, $serialized, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 565 | my $partial = !!$args->{pos}; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 565 | ▶ | my $pos = $partial ? ${$args->{pos}} : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | # optimization - no need to keep checking bytestrings on every level. It | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # has already been checked. | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 565 | local $Bitcoin::Crypto::Types::CHECK_BYTESTRINGS = !!0; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 565 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 'cannot deserialize transaction: no data in stream' | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ) if length $serialized < $pos + 6; | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 563 | my ($version, $witness_flag) = unpack "\@$pos Vn", $serialized; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 563 | $pos += 6; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | # back off if no witness equal to 0x0001 | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 563 | ▶ | if ($witness_flag != 0x0001) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 484 | $pos -= 2; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 484 | $witness_flag = 0; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 563 | my $input_count = unpack_compactsize $serialized, \$pos; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 563 | my @inputs; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 563 | for (1 .. $input_count) { | |||||||||||||||||||||||||||||||||||||||||
| 221 | 689 | push @inputs, Bitcoin::Crypto::Transaction::Input->from_serialized( | |||||||||||||||||||||||||||||||||||||||||
| 222 | $serialized, pos => \$pos | ||||||||||||||||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 563 | my $output_count = unpack_compactsize $serialized, \$pos; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 563 | my @outputs; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 563 | for (1 .. $output_count) { | |||||||||||||||||||||||||||||||||||||||||
| 229 | 857 | push @outputs, Bitcoin::Crypto::Transaction::Output->from_serialized( | |||||||||||||||||||||||||||||||||||||||||
| 230 | $serialized, pos => \$pos | ||||||||||||||||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 563 | ▶ | if ($witness_flag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 79 | foreach my $input (@inputs) { | |||||||||||||||||||||||||||||||||||||||||
| 236 | 142 | $input->set_serialized_witness($serialized, pos => \$pos); | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 563 | my $locktime = unpack "\@$pos V", $serialized; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 563 | $pos += 4; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 563 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 'serialized transaction data is corrupted' | ||||||||||||||||||||||||||||||||||||||||||
| 245 | ) if !$partial && $pos != length $serialized; | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 563 | ▶ | ${$args->{pos}} = $pos | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | if $partial; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 563 | my $tx = $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 251 | version => $version, | ||||||||||||||||||||||||||||||||||||||||||
| 252 | locktime => $locktime, | ||||||||||||||||||||||||||||||||||||||||||
| 253 | had_witness_flag => $witness_flag, | ||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 563 | @{$tx->inputs} = @inputs; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 563 | @{$tx->outputs} = @outputs; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 563 | return $tx; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 38 | signature_for get_hash => ( | |||||||||||||||||||||||||||||||||||||||||
| 263 | method => !!1, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | named => [ | ||||||||||||||||||||||||||||||||||||||||||
| 265 | witness => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | {default => 0}, | ||||||||||||||||||||||||||||||||||||||||||
| 267 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 268 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | sub get_hash | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 186 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 186 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 186 | return scalar reverse hash256($self->to_serialized(%$args)); | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | sub txid | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 24 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 24 | return $self->get_hash(witness => 0); | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | sub wtxid | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wtxid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | return $self->get_hash(witness => 1); | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | sub get_digest | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_digest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 19 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 19 | return $self->get_digest_object(%params)->get_digest; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | sub get_digest_object | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 262 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_digest_object: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 262 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 262 | my $digest = $self->_digest_object; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 262 | $digest->set_config(\%params); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 262 | return $digest; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | sub fee | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 133 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fee: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 133 | my ($self, $require_value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 133 | my $value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 133 | try { | |||||||||||||||||||||||||||||||||||||||||
| 315 | 133 | foreach my $input (@{$self->inputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 316 | 179 | $value += $input->utxo->output->value; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | catch ($e) { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | # utxos are unregistered - cannot calculate | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | ▶ | die $e if $require_value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 131 | foreach my $output (@{$self->outputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 327 | 180 | $value -= $output->value; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 131 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | sub fee_rate | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fee_rate: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | my $fee = $self->fee; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | ▶ | return undef unless defined $fee; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # assume $fee will be small enough to be numified from BigInt on 32 bit. | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # This may be false, but we do not focus on 32 bit support | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | my $size = $self->virtual_size; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | return "$fee" / $size; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | sub set_rbf | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_rbf: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # rules according to BIP125 | ||||||||||||||||||||||||||||||||||||||||||
| 351 | # https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 3 | ▶ | if (!$self->has_rbf) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | my $input = $self->inputs->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 'set_rbf can only be called on a transaction with at least one input' | ||||||||||||||||||||||||||||||||||||||||||
| 357 | ) unless defined $input; | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | $input->set_sequence_no(RBF_SEQUENCE_NO_THRESHOLD); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | $self->clear_digest_object; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | sub has_rbf | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_rbf: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 6 | foreach my $input (@{$self->inputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 371 | 5 | ▶ | return !!1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | if $input->sequence_no <= RBF_SEQUENCE_NO_THRESHOLD; | ||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 5 | return !!0; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | sub virtual_size | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
virtual_size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 4 | my $base = length $self->to_serialized(witness => 0); | |||||||||||||||||||||||||||||||||||||||||
| 383 | 4 | my $with_witness = length $self->to_serialized; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 4 | my $witness = $with_witness - $base; | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 4 | return $base + $witness / 4; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | sub weight | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
weight: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | my $base = length $self->to_serialized(witness => 0); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | my $with_witness = length $self->to_serialized; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | my $witness = $with_witness - $base; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | return $base * 4 + $witness; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | sub update_utxos | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_utxos: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 4 | foreach my $input (@{$self->inputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 405 | 7 | ▶ | $input->utxo->unregister if $input->utxo_registered; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 4 | foreach my $output_index (0 .. $#{$self->outputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 409 | 8 | my $output = $self->outputs->[$output_index]; | |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 8 | ▶ | btc_utxo->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | txid => $self->get_hash, | ||||||||||||||||||||||||||||||||||||||||||
| 413 | output_index => $output_index, | ||||||||||||||||||||||||||||||||||||||||||
| 414 | output => $output, | ||||||||||||||||||||||||||||||||||||||||||
| 415 | ($self->has_block ? (block => $self->block) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 416 | )->register; | ||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | sub is_coinbase | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 139 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_coinbase: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 139 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 139 | my $inputs = $self->inputs; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 139 | ▶ | return !!0 unless @{$inputs} == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 112 | my $null_prevout = NULL_UTXO; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 112 | my $utxo_prevout = $inputs->[0]->utxo_location; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 112 | ▶ | return $null_prevout->[0] eq $utxo_prevout->[0] && $null_prevout->[1] == $utxo_prevout->[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$null_prevout->[0] eq $utxo_prevout->[0] && $null_prevout->[1] == $utxo_prevout->[1]
MC/DC50%1/2
$null_prevout->[0] eq $utxo_prevout->[0] && $null_prevout->[1] == $utxo_prevout->[1]
$null_prevout->[0] eq $utxo_prevout->[0]
$null_prevout->[1] == $utxo_prevout->[1]
Truth table66%2/3
A && B
A= $null_prevout->[0] eq $utxo_prevout->[0]B= $null_prevout->[1] == $utxo_prevout->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | sub _verify_script_default | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 97 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_script_default: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 97 | my ($self, $input, $script_runner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 97 | my $locking_script = $input->utxo->output->locking_script; | |||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 97 | ▶ | my $is_p2sh = $script_runner->flags->p2sh && ($locking_script->type // '') eq 'P2SH'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$script_runner->flags->p2sh && ($locking_script->type // '') eq 'P2SH'
$locking_script->type // ""
MC/DC100%2/2
$script_runner->flags->p2sh && ($locking_script->type // '') eq 'P2SH'
$script_runner->flags->p2sh
$locking_script->type
Truth table100%3/3
A && B
A= $script_runner->flags->p2shB= $locking_script->type
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 97 | ▶ | my $is_pushes_only = $is_p2sh || $script_runner->flags->signature_pushes_only; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$is_p2sh || $script_runner->flags->signature_pushes_only
MC/DC100%2/2
$is_p2sh || $script_runner->flags->signature_pushes_only
$is_p2sh
$script_runner->flags->signature_pushes_only
Truth table100%3/3
A || B
A= $is_p2shB= $script_runner->flags->signature_pushes_only
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 97 | ▶ | Bitcoin::Crypto::Exception::TransactionScript->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_pushes_only and not $input->signature_script->is_pushes_only
MC/DC100%2/2
$is_pushes_only and not $input->signature_script->is_pushes_only
$is_pushes_only
not $input->signature_script->is_pushes_only
Truth table100%3/3
A and not(B)
A= $is_pushes_onlyB= not $input->signature_script->is_pushes_only
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 'signature script must only contain push opcodes' | ||||||||||||||||||||||||||||||||||||||||||
| 444 | ) if $is_pushes_only && !$input->signature_script->is_pushes_only; | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | # execute input to get initial stack | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 96 | $script_runner->execute($input->signature_script); | |||||||||||||||||||||||||||||||||||||||||
| 448 | 95 | my @stack = @{$script_runner->stack}; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 95 | my @locking_stack; | |||||||||||||||||||||||||||||||||||||||||
| 450 | my $redeem_script; | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 95 | ▶ | if ($is_p2sh) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 28 | $redeem_script = pop @stack; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 28 | ▶ | @locking_stack = ($redeem_script) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | if defined $redeem_script; | ||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 67 | @locking_stack = @stack; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | # execute previous output | ||||||||||||||||||||||||||||||||||||||||||
| 462 | Bitcoin::Crypto::Exception::TransactionScript->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 95 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 95 | $script_runner->execute($locking_script, \@locking_stack); | |||||||||||||||||||||||||||||||||||||||||
| 465 | 74 | ▶ | die_no_trace 'execution yielded failure' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | unless $script_runner->success; | ||||||||||||||||||||||||||||||||||||||||||
| 467 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 95 | 'locking script' | |||||||||||||||||||||||||||||||||||||||||
| 469 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 72 | ▶ | if (defined $redeem_script) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 28 | $redeem_script = btc_script->from_serialized($redeem_script); | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 28 | ▶ | if ($script_runner->flags->segwit && $redeem_script->is_native_segwit) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$script_runner->flags->segwit and $redeem_script->is_native_segwit
MC/DC100%2/2
$script_runner->flags->segwit and $redeem_script->is_native_segwit
$script_runner->flags->segwit
$redeem_script->is_native_segwit
Truth table100%3/3
A and B
A= $script_runner->flags->segwitB= $redeem_script->is_native_segwit
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 19 | $self->_verify_script_segwit($input, $script_runner, $redeem_script); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 478 | Bitcoin::Crypto::Exception::TransactionScript->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 9 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 9 | $script_runner->execute($redeem_script, \@stack); | |||||||||||||||||||||||||||||||||||||||||
| 481 | 8 | ▶ | die_no_trace 'execution yielded failure' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | unless $script_runner->success; | ||||||||||||||||||||||||||||||||||||||||||
| 483 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 9 | 'redeem script' | |||||||||||||||||||||||||||||||||||||||||
| 485 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | sub _verify_script_segwit | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 46 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_script_segwit: called CC=11 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 46 | my ($self, $input, $script_runner, $compat_script) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 46 | ▶ | die_no_trace 'signature script is not empty in segwit input' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$compat_script or $input->signature_script->is_empty
MC/DC0%0/2
$compat_script or $input->signature_script->is_empty
$compat_script
$input->signature_script->is_empty
Truth table66%2/3
A or B
A= $compat_scriptB= $input->signature_script->is_empty
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | unless $compat_script || $input->signature_script->is_empty; | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | # use shallow copy of witness as initial stack | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 46 | ▶ | my @stack = @{$input->witness // []}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$input->witness // []
MC/DC0%0/1
$input->witness // []
$input->witness
Truth table50%1/2
A
A= $input->witness
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 46 | my $redeem_script; | |||||||||||||||||||||||||||||||||||||||||
| 500 | my @locking_stack; | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 46 | ▶ | my $locking_script = $compat_script // $input->utxo->output->locking_script; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$compat_script // $input->utxo->output->locking_script
MC/DC0%0/2
$compat_script // $input->utxo->output->locking_script
$compat_script
$input->utxo->output->locking_script
Truth table66%2/3
A // B
A= $compat_scriptB= $input->utxo->output->locking_script
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 46 | my $hash = substr $locking_script->to_serialized, 2; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 46 | my $actual_locking_script; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 46 | ▶ | if ($locking_script->type eq 'P2WPKH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 19 | $actual_locking_script = Bitcoin::Crypto::Script::Common->new(PKH => $hash); | |||||||||||||||||||||||||||||||||||||||||
| 507 | 19 | @locking_stack = @stack; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | elsif ($locking_script->type eq 'P2WSH') { | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 24 | $actual_locking_script = Bitcoin::Crypto::Script::Common->new(WSH => $hash); | |||||||||||||||||||||||||||||||||||||||||
| 511 | 24 | $redeem_script = pop @stack; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 24 | ▶ | @locking_stack = ($redeem_script) if defined $redeem_script; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # not a known segwit version 0 output | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 3 | ▶ | die_no_trace 'unknown witness v0 program' if $locking_script->segwit_version == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 3 | ▶ | die_no_trace 'unknown witness program' if $script_runner->flags->known_witness; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | # execute locking script | ||||||||||||||||||||||||||||||||||||||||||
| 523 | Bitcoin::Crypto::Exception::TransactionScript->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 43 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 43 | $script_runner->execute($actual_locking_script, \@locking_stack); | |||||||||||||||||||||||||||||||||||||||||
| 526 | 39 | ▶ | die_no_trace 'execution yielded failure' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | unless $script_runner->success; | ||||||||||||||||||||||||||||||||||||||||||
| 528 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 43 | 'segwit locking script' | |||||||||||||||||||||||||||||||||||||||||
| 530 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | # execute redeem script | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 39 | ▶ | if (defined $redeem_script) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 24 | $redeem_script = btc_script->from_serialized($redeem_script); | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | Bitcoin::Crypto::Exception::TransactionScript->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 24 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 24 | $script_runner->execute($redeem_script, \@stack); | |||||||||||||||||||||||||||||||||||||||||
| 539 | 19 | ▶ | die_no_trace 'execution yielded failure' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | unless $script_runner->success; | ||||||||||||||||||||||||||||||||||||||||||
| 541 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 24 | 'segwit redeem script' | |||||||||||||||||||||||||||||||||||||||||
| 543 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | sub _verify_script_taproot | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 34 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_script_taproot: called CC=11 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 34 | my ($self, $input, $script_runner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 550 | 34 | my $run_script = !!1; | |||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 34 | ▶ | die_no_trace 'signature script is not empty in taproot input' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | unless $input->signature_script->is_empty; | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 34 | ▶ | die_no_trace 'witness stack has 0 elements' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | unless $input->has_witness; | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | # shallow copy of the witness - avoid modifying the transaction | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 34 | my @witness_stack = @{$input->witness}; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 34 | my $pubkey = $input->utxo->output->locking_script->get_raw_address; | |||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | # consensus rules from https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#script-validation-rules | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | # remove the annex from the witness stack - annex first byte is 0x50 | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 34 | ▶ | $script_runner->transaction->set_taproot_annex(pop @witness_stack) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
@witness_stack >= 2 and (unpack("C", $witness_stack[-1]) // 0) == 80
unpack("C", $witness_stack[-1]) // 0
MC/DC50%1/2
@witness_stack >= 2 and (unpack("C", $witness_stack[-1]) // 0) == 80
@witness_stack >= 2
unpack("C", $witness_stack[-1])
Truth table66%2/3
A and B
A= @witness_stack >= 2B= unpack("C", $witness_stack[-1])
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | if @witness_stack >= 2 && (unpack('C', $witness_stack[-1]) // 0) == 0x50; | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 34 | my $script; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 34 | ▶ | if (@witness_stack == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 22 | $script = Bitcoin::Crypto::Script::Common->new(TR => $pubkey); | |||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 12 | my $control_block = Bitcoin::Crypto::Transaction::ControlBlock->from_serialized(pop @witness_stack); | |||||||||||||||||||||||||||||||||||||||||
| 574 | 12 | my $raw_script = pop @witness_stack; | |||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 12 | my $leaf_version = $control_block->get_leaf_version; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 12 | ▶ | if ($leaf_version == TAPSCRIPT_LEAF_VERSION) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 10 | $script = btc_tapscript->from_serialized($raw_script); | |||||||||||||||||||||||||||||||||||||||||
| 579 | 10 | $script_runner->transaction->set_taproot_ext_flag(1); | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 582 | 2 | $script = btc_script->from_serialized($raw_script); | |||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | # future compatibility - script must succeed | ||||||||||||||||||||||||||||||||||||||||||
| 585 | # https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-12 | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 2 | $run_script = !!0; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | 12 | my $tree = btc_script_tree->from_path( | |||||||||||||||||||||||||||||||||||||||||
| 590 | { | ||||||||||||||||||||||||||||||||||||||||||
| 591 | id => 'spending script', | ||||||||||||||||||||||||||||||||||||||||||
| 592 | leaf_version => $leaf_version, | ||||||||||||||||||||||||||||||||||||||||||
| 593 | script => $script, | ||||||||||||||||||||||||||||||||||||||||||
| 594 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 595 | $control_block->script_blocks | ||||||||||||||||||||||||||||||||||||||||||
| 596 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 12 | $script_runner->transaction->set_script_tree($tree); | |||||||||||||||||||||||||||||||||||||||||
| 599 | 12 | $script_runner->transaction->set_leaf_id('spending script'); | |||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 12 | my $tweaked = $control_block->public_key->get_taproot_output_key($tree->get_merkle_root); | |||||||||||||||||||||||||||||||||||||||||
| 602 | 12 | my $expected_parity = !has_even_y($tweaked); | |||||||||||||||||||||||||||||||||||||||||
| 603 | 12 | ▶ | die_no_trace 'invalid public key or control block' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tweaked->get_xonly_key eq $pubkey and $expected_parity == ($control_block->control_byte & 1)
MC/DC50%1/2
$tweaked->get_xonly_key eq $pubkey and $expected_parity == ($control_block->control_byte & 1)
$tweaked->get_xonly_key eq $pubkey
$expected_parity == ($control_block->control_byte & 1)
Truth table66%2/3
A and B
A= $tweaked->get_xonly_key eq $pubkeyB= $expected_parity == ($control_block->control_byte & 1)
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | unless $tweaked->get_xonly_key eq $pubkey | ||||||||||||||||||||||||||||||||||||||||||
| 605 | && $expected_parity == ($control_block->control_byte & 1); | ||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | # execute script | ||||||||||||||||||||||||||||||||||||||||||
| 609 | # use remaining witness elements as initial stack | ||||||||||||||||||||||||||||||||||||||||||
| 610 | Bitcoin::Crypto::Exception::TransactionScript->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 611 | 32 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 32 | $script_runner->transaction->set_sigop_budget(length $input->serialized_witness); | |||||||||||||||||||||||||||||||||||||||||
| 613 | 32 | $script_runner->execute($script, \@witness_stack); | |||||||||||||||||||||||||||||||||||||||||
| 614 | 29 | ▶ | die_no_trace 'execution yielded failure' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | unless $script_runner->success; | ||||||||||||||||||||||||||||||||||||||||||
| 616 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 617 | 33 | ▶ | 'taproot script' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | ) if $run_script; | ||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | sub verify_script | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 158 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_script: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 158 | my ($self, $input_index, $script_runner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | # optimization - no need to keep checking bytestrings on every level. All | ||||||||||||||||||||||||||||||||||||||||||
| 626 | # input has already been checked. | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 158 | local $Bitcoin::Crypto::Types::CHECK_BYTESTRINGS = !!0; | |||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 158 | $script_runner->transaction->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 630 | 158 | $script_runner->transaction->set_input_index($input_index); | |||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 158 | my $input = $self->inputs->[$input_index]; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 158 | my $utxo = $input->utxo; | |||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | # run bitcoin script | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 158 | my $procedure = '_verify_script_default'; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 158 | ▶ | if ($script_runner->flags->taproot && $utxo->output->locking_script->is_taproot) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$script_runner->flags->taproot and $utxo->output->locking_script->is_taproot
MC/DC100%2/2
$script_runner->flags->taproot and $utxo->output->locking_script->is_taproot
$script_runner->flags->taproot
$utxo->output->locking_script->is_taproot
Truth table100%3/3
A and B
A= $script_runner->flags->taprootB= $utxo->output->locking_script->is_taproot
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 34 | $procedure = '_verify_script_taproot'; | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | ▶ | elsif ($script_runner->flags->segwit && $utxo->output->locking_script->is_native_segwit) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$script_runner->flags->segwit and $utxo->output->locking_script->is_native_segwit
MC/DC100%2/2
$script_runner->flags->segwit and $utxo->output->locking_script->is_native_segwit
$script_runner->flags->segwit
$utxo->output->locking_script->is_native_segwit
Truth table100%3/3
A and B
A= $script_runner->flags->segwitB= $utxo->output->locking_script->is_native_segwit
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 27 | $procedure = '_verify_script_segwit'; | |||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | Bitcoin::Crypto::Exception::TransactionScript->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 158 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 158 | ▶ | die_no_trace 'witness in non-witness input' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $input->is_segwit and $input->has_witness
MC/DC0%0/2
not $input->is_segwit and $input->has_witness
not $input->is_segwit
$input->has_witness
Truth table66%2/3
not(A) and B
A= not $input->is_segwitB= $input->has_witness
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | if !$input->is_segwit && $input->has_witness; | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 158 | $self->$procedure($input, $script_runner); | |||||||||||||||||||||||||||||||||||||||||
| 650 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 651 | 158 | "transaction input $input_index verification has failed" | |||||||||||||||||||||||||||||||||||||||||
| 652 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | sub _verify_coinbase | ||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_coinbase: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my ($self, $script_runner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | my $block = $self->block; | |||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 'coinbase transaction must have one input' | ||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | ▶ | ) if @{$self->inputs} != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | my $coinbase_data = $self->inputs->[0]->signature_script->to_serialized; | |||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $coinbase_data < 2 or length $coinbase_data > 100
MC/DC0%0/2
length $coinbase_data < 2 or length $coinbase_data > 100
length $coinbase_data < 2
length $coinbase_data > 100
Truth table0%0/3
A or B
A= length $coinbase_data < 2B= length $coinbase_data > 100
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 'coinbase data not between 2 and 100 bytes' | ||||||||||||||||||||||||||||||||||||||||||
| 668 | ) if length $coinbase_data < 2 || length $coinbase_data > 100; | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | if (!defined $block) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | carp 'trying to verify coinbase transaction but block was not set'; | |||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | 'coinbase must be the first transaction in a block' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | ) unless $block->transactions->[0] == $self; | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | # NOTE: most of other coinbase verification (like block reward checking) | ||||||||||||||||||||||||||||||||||||||||||
| 680 | # will be done in a block | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 38 | signature_for verify => ( | |||||||||||||||||||||||||||||||||||||||||
| 686 | method => !!1, | ||||||||||||||||||||||||||||||||||||||||||
| 687 | named => [ | ||||||||||||||||||||||||||||||||||||||||||
| 688 | block => Maybe [InstanceOf ['Bitcoin::Crypto::Block']], | ||||||||||||||||||||||||||||||||||||||||||
| 689 | {default => undef}, | ||||||||||||||||||||||||||||||||||||||||||
| 690 | flags => TransactionFlags, | ||||||||||||||||||||||||||||||||||||||||||
| 691 | {default => undef}, | ||||||||||||||||||||||||||||||||||||||||||
| 692 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 693 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||
| 694 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | sub verify | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 176 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=28 SCAR=36.6
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | if ($args->{block}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | 127 | carp 'passing block parameter to verify method is deprecated: call set_block on transaction instead'; | |||||||||||||||||||||||||||||||||||||||||
| 702 | 127 | $self->set_block($args->{block}); | |||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 127 | my $block = $self->block; | |||||||||||||||||||||||||||||||||||||||||
| 706 | 127 | my $inputs = $self->inputs; | |||||||||||||||||||||||||||||||||||||||||
| 707 | 127 | my $outputs = $self->outputs; | |||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | 127 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | 'transaction has no inputs' | ||||||||||||||||||||||||||||||||||||||||||
| 711 | ) if !@$inputs; | ||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | 127 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | 'transaction has no outputs' | ||||||||||||||||||||||||||||||||||||||||||
| 715 | ) if !@$outputs; | ||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | my $script_runner = Bitcoin::Crypto::Script::Runner->new( | ||||||||||||||||||||||||||||||||||||||||||
| 718 | transaction => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 719 | flags => $args->{flags}, | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 127 | ); | |||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | # check output values | ||||||||||||||||||||||||||||||||||||||||||
| 723 | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 'output value is out of range' | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 127 | ▶ | ) if any { $_->value > MAX_MONEY } @$outputs; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | # use special procedure if coinbase | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 173 | ▶ | return $self->_verify_coinbase($script_runner) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | if $self->is_coinbase; | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 'transaction has duplicate inputs' | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 127 | ▶ | ) if @$inputs != uniqstr map { $_->prevout } @$inputs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | 18 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | 'output value exceeds input' | ||||||||||||||||||||||||||||||||||||||||||
| 737 | ) if $self->fee(!!1) < 0; | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | # locktime checking | ||||||||||||||||||||||||||||||||||||||||||
| 740 | 18 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->locktime > 0 and &any(sub {
$_->sequence_no != 4294967295;
}
, @$inputs)
MC/DC50%1/2
$self->locktime > 0 and &any(sub {
$_->sequence_no != 4294967295;
}
, @$inputs)
$self->locktime > 0
&any(sub {
$_->sequence_no != 4294967295;
}
, @$inputs)
Truth table66%2/3
A and B
A= $self->locktime > 0B= &any(sub {
$_->sequence_no != 4294967295;
}
, @$inputs)
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | $self->locktime > 0 && any { | ||||||||||||||||||||||||||||||||||||||||||
| 742 | $_->sequence_no != MAX_SEQUENCE_NO | ||||||||||||||||||||||||||||||||||||||||||
| 743 | } @$inputs | ||||||||||||||||||||||||||||||||||||||||||
| 744 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 745 | { | ||||||||||||||||||||||||||||||||||||||||||
| 746 | 18 | my $locktime = $self->locktime; | |||||||||||||||||||||||||||||||||||||||||
| 747 | 18 | my $is_timestamp = $locktime >= LOCKTIME_HEIGHT_THRESHOLD; | |||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | if (defined $block && ($is_timestamp || $block->has_height)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $block and $is_timestamp || $block->has_height
$is_timestamp or $block->has_height
MC/DC0%0/3
defined $block and $is_timestamp || $block->has_height
defined $block
$is_timestamp
$block->has_height
Truth table50%2/4
A and B or C
A= defined $blockB= $is_timestampC= $block->has_height
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | 123 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 'locktime was not satisfied' | ||||||||||||||||||||||||||||||||||||||||||
| 751 | ) if $locktime >= ($is_timestamp ? $block->median_time_past : $block->height); | ||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||
| 753 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 754 | 123 | carp 'trying to verify locktime but block was not set'; | |||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | # per-input verification | ||||||||||||||||||||||||||||||||||||||||||
| 759 | 158 | foreach my $input_index (keys @{$inputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 760 | 7 | $self->verify_script($input_index, $script_runner); | |||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | # check sequence (BIP 68) | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 7 | ▶ | if ($self->version >= 2 && !($inputs->[$input_index]->sequence_no & (1 << 31))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->version >= 2 and not $inputs->[$input_index]->sequence_no & 2147483648
MC/DC100%2/2
$self->version >= 2 and not $inputs->[$input_index]->sequence_no & 2147483648
$self->version >= 2
not $inputs->[$input_index]->sequence_no & 2147483648
Truth table100%3/3
A and not(B)
A= $self->version >= 2B= not $inputs->[$input_index]->sequence_no & 2147483648
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | 7 | my $sequence = $inputs->[$input_index]->sequence_no; | |||||||||||||||||||||||||||||||||||||||||
| 765 | 7 | my $utxo = $inputs->[$input_index]->utxo; | |||||||||||||||||||||||||||||||||||||||||
| 766 | 7 | my $time_based = $sequence & (1 << 22); | |||||||||||||||||||||||||||||||||||||||||
| 767 | 7 | my $relative_locktime = $sequence & 0x0000ffff; | |||||||||||||||||||||||||||||||||||||||||
| 768 | 7 | ▶ | my $has_block = defined $block && ($time_based || $block->has_height); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
defined $block && ($time_based || $block->has_height)
$time_based or $block->has_height
MC/DC0%0/3
defined $block && ($time_based || $block->has_height)
defined $block
$time_based
$block->has_height
Truth table50%2/4
A && B or C
A= defined $blockB= $time_basedC= $block->has_height
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | 7 | ▶ | my $has_utxo_block = $utxo->has_block && ($time_based || $utxo->block->has_height); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$utxo->has_block && ($time_based || $utxo->block->has_height)
$time_based or $utxo->block->has_height
MC/DC0%0/3
$utxo->has_block && ($time_based || $utxo->block->has_height)
$utxo->has_block
$time_based
$utxo->block->has_height
Truth table50%2/4
A && B or C
A= $utxo->has_blockB= $time_basedC= $utxo->block->has_height
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||
| 771 | 7 | ▶ | if ($has_block && $has_utxo_block) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$has_block and $has_utxo_block
MC/DC0%0/2
$has_block and $has_utxo_block
$has_block
$has_utxo_block
Truth table33%1/3
A and B
A= $has_blockB= $has_utxo_block
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | 7 | my $utxo_block = $utxo->block; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 7 | ▶ | my $now = $time_based ? $block->median_time_past : $block->height; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 7 | ▶ | my $then = $time_based ? $utxo_block->median_time_past : $utxo_block->height; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | ▶ | $relative_locktime <<= 9 if $time_based; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | 79 | ▶ | Bitcoin::Crypto::Exception::Transaction->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 'relative locktime was not satisfied' | ||||||||||||||||||||||||||||||||||||||||||
| 779 | ) if $now < $then + $relative_locktime; | ||||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||
| 781 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 176 | carp 'trying to verify relative locktime but block or utxo block was not set'; | |||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | # TODO: check if coinbase transaction within 100 blocks is spent in any input | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | # TODO: check outputs | ||||||||||||||||||||||||||||||||||||||||||
| 790 | # - do they have non-zero values (other than OP_RETURN)? | ||||||||||||||||||||||||||||||||||||||||||
| 791 | # - do OP_RETURN scripts keep data limit | ||||||||||||||||||||||||||||||||||||||||||
| 792 | # - do they have valid script | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | 18 | return; | |||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | sub verify_standard | ||||||||||||||||||||||||||||||||||||||||||
| 798 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_standard: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 1 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 1 | return $self->verify( | |||||||||||||||||||||||||||||||||||||||||
| 802 | @args, | ||||||||||||||||||||||||||||||||||||||||||
| 803 | flags => Bitcoin::Crypto::Transaction::Flags->new_full | ||||||||||||||||||||||||||||||||||||||||||
| 804 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | sub sign | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 73 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sign: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 809 | 73 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | 73 | return Bitcoin::Crypto::Transaction::Signer->new_impl($self, \%args); | |||||||||||||||||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | sub dump | ||||||||||||||||||||||||||||||||||||||||||
| 815 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 816 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | 1 | my $fee = $self->fee; | |||||||||||||||||||||||||||||||||||||||||
| 819 | 1 | ▶ | my $fee_rate = defined $fee ? int($self->fee_rate * 100) / 100 : '??'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | 1 | ▶ | $fee //= '??'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fee //= "??"
MC/DC0%0/1
$fee //= "??"
$fee
Truth table50%1/2
A
A= $fee
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | 1 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 823 | 1 | push @result, 'Transaction ' . to_format [hex => $self->get_hash]; | |||||||||||||||||||||||||||||||||||||||||
| 824 | 1 | push @result, 'version: ' . $self->version; | |||||||||||||||||||||||||||||||||||||||||
| 825 | 1 | push @result, 'size: ' . $self->virtual_size . 'vB, ' . $self->weight . 'WU'; | |||||||||||||||||||||||||||||||||||||||||
| 826 | 1 | push @result, "fee: $fee sat (~$fee_rate sat/vB)"; | |||||||||||||||||||||||||||||||||||||||||
| 827 | 1 | ▶ | push @result, 'replace-by-fee: ' . ($self->has_rbf ? 'yes' : 'no'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | 1 | push @result, 'locktime: ' . $self->locktime; | |||||||||||||||||||||||||||||||||||||||||
| 829 | 1 | push @result, ''; | |||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | 1 | push @result, @{$self->inputs} . ' inputs:'; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 1 | foreach my $input (@{$self->inputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 833 | 1 | push @result, $input->dump; | |||||||||||||||||||||||||||||||||||||||||
| 834 | 1 | push @result, ''; | |||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||
| 837 | 1 | push @result, @{$self->outputs} . ' outputs:'; | |||||||||||||||||||||||||||||||||||||||||
| 838 | 1 | foreach my $output (@{$self->outputs}) { | |||||||||||||||||||||||||||||||||||||||||
| 839 | 1 | push @result, $output->dump; | |||||||||||||||||||||||||||||||||||||||||
| 840 | 1 | push @result, ''; | |||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | 1 | return join "\n", @result; | |||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||
| 846 | 38 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | __END__ | ||||||||||||||||||||||||||||||||||||||||||