Crypto/Script/Transaction.pm

filter: Statementstmt 96.0% 49 / 51 Branchbran 75.0% 6 / 8 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 8 totaltotal 76.2% 74 / 97 CC 8 SCAR 8.3
CC
8
Cov
87%
is_taproot
6.0
get_digest_object
4.0
is_segwit
2.0
CRAP 2.3
« Crypto/Transaction/Signer/Legacy.pm ↑ Summary Crypto/Transaction/Signer/P2TR.pm »
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
BranchTrueFalseTotal
defined $annex ? : 0 194 194
defined $args{'sighash'} ? : 149 45 194
defined $args{'taproot_ext'} ? : 16 178 194
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
BranchTrueFalseTotal
unless defined $budget 0 42 42
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
!ll&&!rl&&r
049
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
ABresult
0X0
100
111
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
!ll&&!rl&&r
2150
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
ABresult
0X0
100
111
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
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
151 && $self->this_input->is_taproot;
152 }
153  
154 65 1;
155  
« Crypto/Transaction/Signer/Legacy.pm ↑ Summary Crypto/Transaction/Signer/P2TR.pm »