Crypto/BIP44.pm

filter: Statementstmt 100% 55 / 55 Branchbran 85.7% 12 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 97.8% 89 / 91 CC 9 SCAR 9.1
CC
9
Cov
97%
as_string
5.0
__ANON__
4.0
_get_network_constant
2.0
CRAP 2.5
« Crypto/Exception.pm ↑ Summary Crypto/Script/Compiler/Opcode.pm »
1 package Bitcoin::Crypto::BIP44;
2 13 $Bitcoin::Crypto::BIP44::VERSION = '4.004';
3 13 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 13 ▶use Bitcoin::Crypto::DerivationPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use Bitcoin::Crypto::Network;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub _get_network_constant
16 {
17 50 ▶ my ($network) = @_;
Subroutine _get_network_constant: called CC=2 SCAR=7.0
18  
19 50 my $coin_type = $network->bip44_coin;
20  
21 50 ▶ Bitcoin::Crypto::Exception::NetworkConfig->raise(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $coin_type 0 50 50
22 'no bip44_coin constant found in network configuration'
23 ) unless defined $coin_type;
24  
25 50 return $coin_type;
26 }
27  
28 13 has param 'purpose' => (
29 isa => BIP44Purpose,
30 default => 44,
31 );
32  
33 has param 'coin_type' => (
34 isa => PositiveOrZeroInt,
35 coerce => sub {
36 52 ▶ my ($coin_type) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
37  
38 52 ▶ if (blessed $coin_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($coin_type)) 48 4 52
39 48 ▶ $coin_type = $coin_type->network
Branch: 1 branch
BranchTrueFalseTotal
if $coin_type->DOES("Bitcoin::Crypto::Role::Network") 47 1 48
40 if $coin_type->DOES('Bitcoin::Crypto::Role::Network');
41  
42 48 ▶ $coin_type = _get_network_constant($coin_type)
Branch: 1 branch
BranchTrueFalseTotal
if $coin_type->isa("Bitcoin::Crypto::Network") 48 0 48
43 if $coin_type->isa('Bitcoin::Crypto::Network');
44 }
45  
46 52 return $coin_type;
47 },
48 default => sub {
49 2 ▶ _get_network_constant(Bitcoin::Crypto::Network->get);
Subroutine __ANON__: called CC=1 SCAR=0.0
50 },
51 13 );
52  
53 13 has param 'account' => (
54 isa => PositiveOrZeroInt,
55 default => 0,
56 );
57  
58 13 has param 'change' => (
59 isa => Enum [1, 0],
60 default => 0,
61 );
62  
63 13 has param 'index' => (
64 isa => PositiveOrZeroInt,
65 default => 0,
66 );
67  
68 13 has param 'get_account' => (
69 isa => Bool,
70 default => !!0,
71 );
72  
73 13 has param 'get_from_account' => (
74 isa => Bool,
75 default => !!0,
76 );
77  
78 13 has param 'public' => (
79 isa => Bool,
80 default => !!0,
81 );
82  
83 13 with qw(Bitcoin::Crypto::Role::WithDerivationPath);
84  
85 use overload
86 4 ▶ q{""} => sub { shift->as_string },
Subroutine __ANON__: called CC=1 SCAR=0.0
87 13 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 sub as_string
90 {
91 52 ▶ my ($self) = @_;
Subroutine as_string: called CC=5 SCAR=16.1
Pod documented
92  
93 # https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
94 # m / purpose' / coin_type' / account' / change / address_index
95  
96 52 ▶ my $path = $self->public ? 'M' : 'm';
Branch: 1 branch
BranchTrueFalseTotal
$self->public ? : 6 46 52
97  
98 52 ▶ $path = sprintf "%s/%u'/%u'/%u'",
Branch: 1 branch
BranchTrueFalseTotal
unless $self->public or $self->get_from_account 32 20 52
Condition100%3/3
$self->public or $self->get_from_account
l!l&&r!l&&!r
61432
MC/DC100%2/2
$self->public or $self->get_from_account
$self->public $self->get_from_account
Truth table100%3/3
A or B
A= $self->publicB= $self->get_from_account
ABresult
1X1
011
000
99 $path, $self->purpose, $self->coin_type, $self->account
100 if !$self->public && !$self->get_from_account;
101  
102 52 ▶ return $path
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_account 15 37 52
103 if $self->get_account;
104  
105 37 return sprintf "%s/%u/%u",
106 $path, $self->change, $self->index;
107 }
108  
109 sub get_derivation_path
110 {
111 48 ▶ my ($self) = @_;
Subroutine get_derivation_path: called CC=1 SCAR=0.0
Pod documented
112  
113 48 return Bitcoin::Crypto::DerivationPath->from_string($self->as_string);
114 }
115  
116 13 1;
117  
118 __END__
« Crypto/Exception.pm ↑ Summary Crypto/Script/Compiler/Opcode.pm »