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 64 $Bitcoin::Crypto::Script::Common::VERSION = '4.005';
3 64 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 64 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 64 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 64 ▶use Bitcoin::Crypto qw(btc_script btc_tapscript);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 64 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 64 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub _make_PKH
13 75 ▶{
Subroutine _make_PKH: called CC=2 SCAR=7.0
14 75 my ($class, $script, $hash) = @_;
15 75 ▶ $script //= btc_script->new;
Condition66%2/3
$script //= btc_script()->new
l!l&&r!l&&!r
26490
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 75 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 20 ▶{
Subroutine _make_SH: called CC=2 SCAR=7.6
27 20 my ($class, $script, $hash) = @_;
28 20 ▶ $script //= btc_script->new;
Condition33%1/3
$script //= btc_script()->new
l!l&&r!l&&!r
2000
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 20 return $script
31 ->add('OP_HASH160')
32 ->push($hash)
33 ->add('OP_EQUAL');
34 }
35  
36 sub _make_WSH
37 21 ▶{
Subroutine _make_WSH: called CC=2 SCAR=7.6
38 21 my ($class, $script, $hash) = @_;
39 21 ▶ $script //= btc_script->new;
Condition33%1/3
$script //= btc_script()->new
l!l&&r!l&&!r
0210
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 21 return $script
42 ->add('OP_SHA256')
43 ->push($hash)
44 ->add('OP_EQUAL');
45 }
46  
47 sub _make_TR
48 30 ▶{
Subroutine _make_TR: called CC=2 SCAR=7.6
49 30 my ($class, $script, $pubkey) = @_;
50 30 ▶ $script //= btc_tapscript->new;
Condition33%1/3
$script //= btc_tapscript()->new
l!l&&r!l&&!r
0300
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 30 return $script
53 ->push($pubkey)
54 ->add('OP_CHECKSIG');
55 }
56  
57 sub new
58 100 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
59 100 my ($class, $type, $data) = @_;
60  
61 100 return $class->fill($type, undef, $data);
62 }
63  
64 sub fill
65 146 ▶{
Subroutine fill: called CC=2 SCAR=7.4
Pod undocumented
66 146 my ($class, $type, $script, $data) = @_;
67  
68 146 state $methods = {
69 PKH => '_make_PKH',
70 SH => '_make_SH',
71 WSH => '_make_WSH',
72 TR => '_make_TR',
73 };
74  
75 146 ▶ 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
14600
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 146 return $class->$method($script, $data);
80 }
81  
82 64 1;
83  
« Crypto/Transaction/Digest/Result.pm ↑ Summary Crypto/Types.pm »