Crypto/Script/Transaction.pm

filter: Statementstmt 92.4% 49 / 53 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 3 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 86.6% 13 / 15 Podpod 0.0% 0 / 8 totaltotal 73.7% 73 / 99 CC 8 SCAR 9.7
CC
8
Cov
83%
is_native_segwit
6.0
is_taproot
6.0
get_digest_object
4.0
CRAP 2.6
« Crypto/Key/Public.pm ↑ Summary Crypto/Role/ShallowClone.pm »
1 package Bitcoin::Crypto::Script::Transaction;
2 69 $Bitcoin::Crypto::Script::Transaction::VERSION = '4.006';
3 69 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 69 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 69 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 69 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 69 ▶use Bitcoin::Crypto::Helpers qw(die_no_trace);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 69 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # must be set via a trigger
13 69 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 69 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 69 has param 'input_index' => (
37 isa => PositiveOrZeroInt,
38 writer => 1,
39 default => 0,
40 );
41  
42 69 has param 'taproot_ext_flag' => (
43 isa => PositiveOrZeroInt,
44 writer => 1,
45 default => 0,
46 );
47  
48 69 has param 'taproot_annex' => (
49 coerce => ByteStr,
50 writer => 1,
51 required => 0,
52 clearer => -hidden,
53 );
54  
55 69 has option 'script_tree' => (
56 isa => InstanceOf ['Bitcoin::Crypto::Script::Tree'],
57 writer => 1,
58 clearer => -hidden,
59 );
60  
61 69 has option 'leaf_id' => (
62 coerce => ByteStr,
63 writer => 1,
64 clearer => -hidden,
65 );
66  
67 69 has option 'sigop_budget' => (
68 isa => Int,
69 writer => -hidden,
70 clearer => -hidden,
71 );
72  
73 sub _clear
74 158 ▶{
Subroutine _clear: called CC=1 SCAR=0.0
75 158 my $self = shift;
76  
77 # IMPORTANT: all data but input_index MUST be cleared here (clear or set
78 # default)
79 158 $self->set_taproot_ext_flag(0);
80 158 $self->_clear_taproot_annex;
81 158 $self->_clear_script_tree;
82 158 $self->_clear_leaf_id;
83 158 $self->_clear_sigop_budget;
84 }
85  
86 sub get_digest_object
87 242 ▶{
Subroutine get_digest_object: called CC=4 SCAR=13.9
Pod undocumented
88 242 my ($self, %args) = @_;
89  
90 242 my $annex = $self->taproot_annex;
91  
92 return $self->transaction->get_digest_object(
93 signing_index => $self->input_index,
94 signing_subscript => $self->runner->subscript($args{signatures}),
95 taproot_ext_flag => $self->taproot_ext_flag,
96 (defined $annex ? (taproot_annex => $annex) : ()),
97 (defined $args{sighash} ? (sighash => $args{sighash}) : ()),
98 242 ▶ (defined $args{taproot_ext} ? (taproot_ext => $args{taproot_ext}) : ()),
Branch: 3 branches
BranchTrueFalseTotal
defined $annex ? : 0 241 241
defined $args{'sighash'} ? : 172 69 241
defined $args{'taproot_ext'} ? : 27 214 241
99 );
100 }
101  
102 sub get_digest
103 180 ▶{
Subroutine get_digest: called CC=1 SCAR=0.0
Pod undocumented
104 180 return shift->get_digest_object(@_)->get_digest;
105 }
106  
107 sub this_input
108 289 ▶{
Subroutine this_input: called CC=1 SCAR=0.0
Pod undocumented
109 289 my $self = shift;
110  
111 289 return $self->inputs->[$self->input_index];
112 }
113  
114 sub set_sigop_budget
115 62 ▶{
Subroutine set_sigop_budget: called CC=1 SCAR=0.0
Pod undocumented
116 62 my ($self, $witness_size) = @_;
117  
118 62 $self->_set_sigop_budget(50 + $witness_size);
119 }
120  
121 sub reduce_sigop_budget
122 54 ▶{
Subroutine reduce_sigop_budget: called CC=2 SCAR=7.0
Pod undocumented
123 54 my $self = shift;
124  
125 54 my $budget = $self->sigop_budget;
126 54 ▶ die_no_trace 'no sigop budget defined for the transaction object'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $budget 0 54 54
127 unless defined $budget;
128  
129 54 $budget -= 50;
130 54 $self->_set_sigop_budget($budget);
131 54 return $budget >= 0;
132 }
133  
134 sub is_segwit
135 38 ▶{
Subroutine is_segwit: called CC=2 SCAR=6.9
Pod undocumented
136 38 my $self = shift;
137  
138 return
139 38 ▶ $self->flags->segwit
Condition100%3/3
$self->flags->segwit && $self->this_input->is_segwit
!ll&&!rl&&r
22115
MC/DC100%2/2
$self->flags->segwit && $self->this_input->is_segwit
$self->flags->segwit $self->this_input->is_segwit
Truth table100%3/3
A && B
A= $self->flags->segwitB= $self->this_input->is_segwit
ABresult
0X0
100
111
140 && $self->this_input->is_segwit;
141 }
142  
143 sub is_native_segwit
144 0 ▶{
Subroutine is_native_segwit: not called CC=2 SCAR=17.9
Pod undocumented
145 0 my $self = shift;
146  
147 return
148 0 ▶ $self->flags->segwit
Condition0%0/3
$self->flags->segwit && $self->this_input->utxo->output->locking_script->is_native_segwit
!ll&&!rl&&r
000
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 table0%0/3
A && B
A= $self->flags->segwitB= $self->this_input->utxo->output->locking_script->is_native_segwit
ABresult
0X0
100
111
149 && $self->this_input->utxo->output->locking_script->is_native_segwit;
150 }
151  
152 sub is_taproot
153 0 ▶{
Subroutine is_taproot: not called CC=2 SCAR=17.9
Pod undocumented
154 0 my $self = shift;
155  
156 return
157 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
158 && $self->this_input->is_taproot;
159 }
160  
161 69 1;
162  
« Crypto/Key/Public.pm ↑ Summary Crypto/Role/ShallowClone.pm »