| 1 | package Bitcoin::Crypto::Script::Transaction; | ||||||||||||||||||||
| 2 | 65 | $Bitcoin::Crypto::Script::Transaction::VERSION = '4.005'; | |||||||||||||||||||
| 3 | 65 | ▶ | use v5.14; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 65 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 65 | ▶ | use Mooish::Base -standard; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 65 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 65 | ▶ | use Bitcoin::Crypto::Helpers qw(die_no_trace); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 65 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # must be set via a trigger | ||||||||||||||||||||
| 13 | 65 | has field 'runner' => ( | |||||||||||||||||||
| 14 | isa => InstanceOf ['Bitcoin::Crypto::Script::Runner'], | ||||||||||||||||||||
| 15 | writer => 1, | ||||||||||||||||||||
| 16 | weak_ref => 1, | ||||||||||||||||||||
| 17 | handles => [ | ||||||||||||||||||||
| 18 | qw( | ||||||||||||||||||||
| 19 | flags | ||||||||||||||||||||
| 20 | ), | ||||||||||||||||||||
| 21 | ], | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 65 | has param 'transaction' => ( | |||||||||||||||||||
| 25 | isa => InstanceOf ['Bitcoin::Crypto::Transaction'], | ||||||||||||||||||||
| 26 | handles => [ | ||||||||||||||||||||
| 27 | qw( | ||||||||||||||||||||
| 28 | version | ||||||||||||||||||||
| 29 | locktime | ||||||||||||||||||||
| 30 | inputs | ||||||||||||||||||||
| 31 | outputs | ||||||||||||||||||||
| 32 | ) | ||||||||||||||||||||
| 33 | ], | ||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 65 | has param 'input_index' => ( | |||||||||||||||||||
| 37 | isa => PositiveOrZeroInt, | ||||||||||||||||||||
| 38 | writer => 1, | ||||||||||||||||||||
| 39 | default => 0, | ||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 65 | has param 'taproot_ext_flag' => ( | |||||||||||||||||||
| 43 | isa => PositiveOrZeroInt, | ||||||||||||||||||||
| 44 | writer => 1, | ||||||||||||||||||||
| 45 | default => 0, | ||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 65 | has param 'taproot_annex' => ( | |||||||||||||||||||
| 49 | coerce => ByteStr, | ||||||||||||||||||||
| 50 | writer => 1, | ||||||||||||||||||||
| 51 | required => 0, | ||||||||||||||||||||
| 52 | clearer => -hidden, | ||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 65 | has option 'script_tree' => ( | |||||||||||||||||||
| 56 | isa => InstanceOf ['Bitcoin::Crypto::Script::Tree'], | ||||||||||||||||||||
| 57 | writer => 1, | ||||||||||||||||||||
| 58 | clearer => -hidden, | ||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 65 | has option 'sigop_budget' => ( | |||||||||||||||||||
| 62 | isa => Int, | ||||||||||||||||||||
| 63 | writer => -hidden, | ||||||||||||||||||||
| 64 | clearer => -hidden, | ||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | sub _clear | ||||||||||||||||||||
| 68 | 143 | ▶ | { | ||||||||||||||||||
|
Subroutine
_clear: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 69 | 143 | my $self = shift; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | # IMPORTANT: all data but input_index MUST be cleared here (clear or set | ||||||||||||||||||||
| 72 | # default) | ||||||||||||||||||||
| 73 | 143 | $self->set_taproot_ext_flag(0); | |||||||||||||||||||
| 74 | 143 | $self->_clear_taproot_annex; | |||||||||||||||||||
| 75 | 143 | $self->_clear_script_tree; | |||||||||||||||||||
| 76 | 143 | $self->_clear_sigop_budget; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub get_digest_object | ||||||||||||||||||||
| 80 | 195 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_digest_object: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 81 | 195 | my ($self, %args) = @_; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 195 | my $annex = $self->taproot_annex; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | return $self->transaction->get_digest_object( | ||||||||||||||||||||
| 86 | signing_index => $self->input_index, | ||||||||||||||||||||
| 87 | signing_subscript => $self->runner->subscript($args{signatures}), | ||||||||||||||||||||
| 88 | taproot_ext_flag => $self->taproot_ext_flag, | ||||||||||||||||||||
| 89 | (defined $annex ? (taproot_annex => $annex) : ()), | ||||||||||||||||||||
| 90 | (defined $args{sighash} ? (sighash => $args{sighash}) : ()), | ||||||||||||||||||||
| 91 | 195 | ▶ | (defined $args{taproot_ext} ? (taproot_ext => $args{taproot_ext}) : ()), | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | sub get_digest | ||||||||||||||||||||
| 96 | 154 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_digest: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 97 | 154 | return shift->get_digest_object(@_)->get_digest; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | sub this_input | ||||||||||||||||||||
| 101 | 234 | ▶ | { | ||||||||||||||||||
|
Subroutine
this_input: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 102 | 234 | my $self = shift; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 234 | return $self->inputs->[$self->input_index]; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub set_sigop_budget | ||||||||||||||||||||
| 108 | 49 | ▶ | { | ||||||||||||||||||
|
Subroutine
set_sigop_budget: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 109 | 49 | my ($self, $witness_size) = @_; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 49 | $self->_set_sigop_budget(50 + $witness_size); | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | sub reduce_sigop_budget | ||||||||||||||||||||
| 115 | 42 | ▶ | { | ||||||||||||||||||
|
Subroutine
reduce_sigop_budget: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 116 | 42 | my $self = shift; | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 42 | my $budget = $self->sigop_budget; | |||||||||||||||||||
| 119 | 42 | ▶ | die_no_trace 'no sigop budget defined for the transaction object' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | unless defined $budget; | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 42 | $budget -= 50; | |||||||||||||||||||
| 123 | 42 | $self->_set_sigop_budget($budget); | |||||||||||||||||||
| 124 | 42 | return $budget >= 0; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | sub is_segwit | ||||||||||||||||||||
| 128 | 13 | ▶ | { | ||||||||||||||||||
|
Subroutine
is_segwit: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 129 | 13 | my $self = shift; | |||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | return | ||||||||||||||||||||
| 132 | 13 | ▶ | $self->flags->segwit | ||||||||||||||||||
|
Condition66%2/3
$self->flags->segwit && $self->this_input->is_segwit
MC/DC50%1/2
$self->flags->segwit && $self->this_input->is_segwit
$self->flags->segwit
$self->this_input->is_segwit
Truth table66%2/3
A && B
A= $self->flags->segwitB= $self->this_input->is_segwit
| |||||||||||||||||||||
| 133 | && $self->this_input->is_segwit; | ||||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | sub is_native_segwit | ||||||||||||||||||||
| 137 | 17 | ▶ | { | ||||||||||||||||||
|
Subroutine
is_native_segwit: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 138 | 17 | my $self = shift; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | return | ||||||||||||||||||||
| 141 | 17 | ▶ | $self->flags->segwit | ||||||||||||||||||
|
Condition66%2/3
$self->flags->segwit && $self->this_input->utxo->output->locking_script->is_native_segwit
MC/DC0%0/2
$self->flags->segwit && $self->this_input->utxo->output->locking_script->is_native_segwit
$self->flags->segwit
$self->this_input->utxo->output->locking_script->is_native_segwit
Truth table66%2/3
A && B
A= $self->flags->segwitB= $self->this_input->utxo->output->locking_script->is_native_segwit
| |||||||||||||||||||||
| 142 | && $self->this_input->utxo->output->locking_script->is_native_segwit; | ||||||||||||||||||||
| 143 | } | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | sub is_taproot | ||||||||||||||||||||
| 146 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
is_taproot: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | return | ||||||||||||||||||||
| 150 | 0 | ▶ | $self->flags->taproot | ||||||||||||||||||
|
Condition0%0/3
$self->flags->taproot && $self->this_input->is_taproot
MC/DC0%0/2
$self->flags->taproot && $self->this_input->is_taproot
$self->flags->taproot
$self->this_input->is_taproot
Truth table0%0/3
A && B
A= $self->flags->taprootB= $self->this_input->is_taproot
| |||||||||||||||||||||
| 151 | && $self->this_input->is_taproot; | ||||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 65 | 1; | |||||||||||||||||||
| 155 | |||||||||||||||||||||