line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bitcoin::Crypto::Types; |
2
|
|
|
|
|
|
|
$Bitcoin::Crypto::Types::VERSION = '2.000_01'; # TRIAL |
3
|
|
|
|
|
|
|
$Bitcoin::Crypto::Types::VERSION = '2.00001'; |
4
|
36
|
|
|
36
|
|
74567
|
use v5.10; |
|
36
|
|
|
|
|
164
|
|
5
|
36
|
|
|
36
|
|
195
|
use strict; |
|
36
|
|
|
|
|
126
|
|
|
36
|
|
|
|
|
834
|
|
6
|
36
|
|
|
36
|
|
186
|
use warnings; |
|
36
|
|
|
|
|
101
|
|
|
36
|
|
|
|
|
1507
|
|
7
|
|
|
|
|
|
|
|
8
|
36
|
|
|
|
|
396
|
use Type::Library -extends => [ |
9
|
|
|
|
|
|
|
qw( |
10
|
|
|
|
|
|
|
Types::Standard |
11
|
|
|
|
|
|
|
Types::Common::Numeric |
12
|
|
|
|
|
|
|
Types::Common::String |
13
|
|
|
|
|
|
|
) |
14
|
36
|
|
|
36
|
|
2360
|
]; |
|
36
|
|
|
|
|
158292
|
|
15
|
36
|
|
|
36
|
|
5192121
|
use Type::Coercion; |
|
36
|
|
|
|
|
89
|
|
|
36
|
|
|
|
|
1007
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# make sure Math::BigInt is properly loaded - this module loads it |
18
|
36
|
|
|
36
|
|
15466
|
use Bitcoin::Crypto::Helpers; |
|
36
|
|
|
|
|
151
|
|
|
36
|
|
|
|
|
2127
|
|
19
|
36
|
|
|
36
|
|
301
|
use Bitcoin::Crypto::Constants; |
|
36
|
|
|
|
|
112
|
|
|
36
|
|
|
|
|
20998
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->add_type( |
22
|
|
|
|
|
|
|
name => 'BIP44Purpose', |
23
|
|
|
|
|
|
|
parent => Maybe [ |
24
|
|
|
|
|
|
|
Enum->of( |
25
|
|
|
|
|
|
|
Bitcoin::Crypto::Constants::bip44_purpose, |
26
|
|
|
|
|
|
|
Bitcoin::Crypto::Constants::bip44_compat_purpose, |
27
|
|
|
|
|
|
|
Bitcoin::Crypto::Constants::bip44_segwit_purpose |
28
|
|
|
|
|
|
|
) |
29
|
|
|
|
|
|
|
], |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $formatstr = __PACKAGE__->add_type( |
33
|
|
|
|
|
|
|
name => 'FormatStr', |
34
|
|
|
|
|
|
|
parent => Enum->of( |
35
|
|
|
|
|
|
|
'bytes', |
36
|
|
|
|
|
|
|
'hex', |
37
|
|
|
|
|
|
|
'base58', |
38
|
|
|
|
|
|
|
) |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $formatdesc = __PACKAGE__->add_type( |
42
|
|
|
|
|
|
|
name => 'FormatDesc', |
43
|
|
|
|
|
|
|
parent => Tuple->of( |
44
|
|
|
|
|
|
|
$formatstr, |
45
|
|
|
|
|
|
|
Str, |
46
|
|
|
|
|
|
|
) |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $bytestr = __PACKAGE__->add_type( |
50
|
|
|
|
|
|
|
name => 'ByteStr', |
51
|
|
|
|
|
|
|
parent => Str, |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
constraint => qq{ (grep { ord > 255 } split //) == 0 }, |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
inline => sub { |
56
|
|
|
|
|
|
|
my $varname = pop; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return (undef, qq{ (grep { ord > 255 } split //, $varname) == 0 }); |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
message => sub { |
62
|
|
|
|
|
|
|
return 'Value is not a bytestring'; |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$bytestr->coercion->add_type_coercions( |
67
|
|
|
|
|
|
|
$formatdesc, q{ Bitcoin::Crypto::Helpers::parse_formatdesc($_) } |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $scripttype = __PACKAGE__->add_type( |
71
|
|
|
|
|
|
|
name => 'ScriptType', |
72
|
|
|
|
|
|
|
parent => Enum->of(qw(P2PK P2PKH P2SH P2MS P2WPKH P2WSH NULLDATA)) |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $scriptdesc = __PACKAGE__->add_type( |
76
|
|
|
|
|
|
|
name => 'ScriptDesc', |
77
|
|
|
|
|
|
|
parent => Tuple->of( |
78
|
|
|
|
|
|
|
$scripttype, |
79
|
|
|
|
|
|
|
Defined, |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $script = __PACKAGE__->add_type( |
84
|
|
|
|
|
|
|
name => 'BitcoinScript', |
85
|
|
|
|
|
|
|
parent => InstanceOf->of('Bitcoin::Crypto::Script'), |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$script->coercion->add_type_coercions( |
89
|
|
|
|
|
|
|
$scriptdesc, q{ require Bitcoin::Crypto::Script; Bitcoin::Crypto::Script->from_standard(@$_) }, |
90
|
|
|
|
|
|
|
$bytestr->coercibles, q{ require Bitcoin::Crypto::Script; Bitcoin::Crypto::Script->from_serialized($_) }, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__PACKAGE__->add_type( |
94
|
|
|
|
|
|
|
name => 'IntMaxBits', |
95
|
|
|
|
|
|
|
parent => PositiveOrZeroInt, |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
constraint_generator => sub { |
98
|
|
|
|
|
|
|
my $bits = assert_PositiveInt(shift); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# for same bits as system, no need for special constraint |
101
|
|
|
|
|
|
|
return sub { 1 } |
102
|
|
|
|
|
|
|
if Bitcoin::Crypto::Constants::ivsize * 8 == $bits; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# can't handle |
105
|
|
|
|
|
|
|
die 'IntMaxBits only handles up to ' . (Bitcoin::Crypto::Constants::ivsize * 8) . ' bits on this system' |
106
|
|
|
|
|
|
|
if Bitcoin::Crypto::Constants::ivsize * 8 < $bits; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $limit = 1 << $bits; |
109
|
|
|
|
|
|
|
return sub { |
110
|
|
|
|
|
|
|
return $_ < $limit; |
111
|
|
|
|
|
|
|
}; |
112
|
|
|
|
|
|
|
}, |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
inline_generator => sub { |
115
|
|
|
|
|
|
|
my $bits = shift; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return sub { |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# for same bits as system, no need for special constraint |
120
|
|
|
|
|
|
|
return (undef, qq{ 1 }) |
121
|
|
|
|
|
|
|
if Bitcoin::Crypto::Constants::ivsize * 8 == $bits; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $varname = pop; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $limit = 1 << $bits; |
126
|
|
|
|
|
|
|
return (undef, qq{ $varname < $limit }); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
}, |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
message => sub { |
131
|
|
|
|
|
|
|
my $bits = shift; |
132
|
|
|
|
|
|
|
return "Value does not fit in $bits bits"; |
133
|
|
|
|
|
|
|
}, |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__PACKAGE__->make_immutable; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Internal use only |
141
|
|
|
|
|
|
|
|