Crypto/Script/Common.pm

filter: Statementstmt 100% 37 / 37 Branchbran n/a Conditioncond 40.0% 6 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 2 totaltotal 72.3% 55 / 76 CC 6 SCAR 5.0
CC
6
Cov
83%
_make_SH
2.1
_make_WSH
2.1
_make_TR
2.1
CRAP 1.7
« Crypto/Transaction/Digest/Result.pm ↑ Summary Crypto/Types.pm »
1 package Bitcoin::Crypto::Script::Common;
2 68 $Bitcoin::Crypto::Script::Common::VERSION = '4.006';
3 68 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 68 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 68 ▶use Bitcoin::Crypto qw(btc_script btc_tapscript);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 68 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 68 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub _make_PKH
13 97 ▶{
Subroutine _make_PKH: called CC=2 SCAR=7.0
14 97 my ($class, $script, $hash) = @_;
15 97 ▶ $script //= btc_script->new;
Condition66%2/3
$script //= btc_script()->new
l!l&&r!l&&!r
29680
MC/DC0%0/2
$script //= btc_script()->new
$script btc_script()->new
Truth table66%2/3
A //= B
A= $scriptB= btc_script()->new
ABresult
1X1
011
000
16  
17 97 return $script
18 ->add('OP_DUP')
19 ->add('OP_HASH160')
20 ->push($hash)
21 ->add('OP_EQUALVERIFY')
22 ->add('OP_CHECKSIG');
23 }
24  
25 sub _make_SH
26 27 ▶{
Subroutine _make_SH: called CC=2 SCAR=7.6
27 27 my ($class, $script, $hash) = @_;
28 27 ▶ $script //= btc_script->new;
Condition33%1/3
$script //= btc_script()->new
l!l&&r!l&&!r
2700
MC/DC0%0/2
$script //= btc_script()->new
$script btc_script()->new
Truth table33%1/3
A //= B
A= $scriptB= btc_script()->new
ABresult
1X1
011
000
29  
30 27 return $script
31 ->add('OP_HASH160')
32 ->push($hash)
33 ->add('OP_EQUAL');
34 }
35  
36 sub _make_WSH
37 24 ▶{
Subroutine _make_WSH: called CC=2 SCAR=7.6
38 24 my ($class, $script, $hash) = @_;
39 24 ▶ $script //= btc_script->new;
Condition33%1/3
$script //= btc_script()->new
l!l&&r!l&&!r
0240
MC/DC0%0/2
$script //= btc_script()->new
$script btc_script()->new
Truth table33%1/3
A //= B
A= $scriptB= btc_script()->new
ABresult
1X1
011
000
40  
41 24 return $script
42 ->add('OP_SHA256')
43 ->push($hash)
44 ->add('OP_EQUAL');
45 }
46  
47 sub _make_TR
48 35 ▶{
Subroutine _make_TR: called CC=2 SCAR=7.6
49 35 my ($class, $script, $pubkey) = @_;
50 35 ▶ $script //= btc_tapscript->new;
Condition33%1/3
$script //= btc_tapscript()->new
l!l&&r!l&&!r
0350
MC/DC0%0/2
$script //= btc_tapscript()->new
$script btc_tapscript()->new
Truth table33%1/3
A //= B
A= $scriptB= btc_tapscript()->new
ABresult
1X1
011
000
51  
52 35 return $script
53 ->push($pubkey)
54 ->add('OP_CHECKSIG');
55 }
56  
57 sub new
58 127 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
59 127 my ($class, $type, $data) = @_;
60  
61 127 return $class->fill($type, undef, $data);
62 }
63  
64 sub fill
65 183 ▶{
Subroutine fill: called CC=2 SCAR=7.4
Pod undocumented
66 183 my ($class, $type, $script, $data) = @_;
67  
68 183 state $methods = {
69 PKH => '_make_PKH',
70 SH => '_make_SH',
71 WSH => '_make_WSH',
72 TR => '_make_TR',
73 };
74  
75 183 ▶ my $method = $methods->{$type} // Bitcoin::Crypto::Exception::ScriptType->raise(
Condition33%1/3
$methods->{$type} // "Bitcoin::Crypto::Exception::ScriptType"->raise("cannot create common script of type $type")
l!l&&r!l&&!r
18300
MC/DC0%0/2
$methods->{$type} // "Bitcoin::Crypto::Exception::ScriptType"->raise("cannot create common script of type $type")
$methods->{$type} "Bitcoin::Crypto::Exception::ScriptType"->raise("cannot create common script of type $type")
Truth table33%1/3
A // B
A= $methods->{$type}B= "Bitcoin::Crypto::Exception::ScriptType"->raise("cannot create common script of type $type")
ABresult
1X1
011
000
76 "cannot create common script of type $type"
77 );
78  
79 183 return $class->$method($script, $data);
80 }
81  
82 68 1;
83  
« Crypto/Transaction/Digest/Result.pm ↑ Summary Crypto/Types.pm »