line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
102653
|
use v5.26; |
|
4
|
|
|
|
|
23
|
|
2
|
4
|
|
|
4
|
|
679
|
use Object::Pad; |
|
4
|
|
|
|
|
10938
|
|
|
4
|
|
|
|
|
29
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Blockchain::Ethereum::Keystore::Address; |
5
|
|
|
|
|
|
|
class Blockchain::Ethereum::Keystore::Address; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:REFECO'; # AUTHORITY |
8
|
|
|
|
|
|
|
our $VERSION = '0.006'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
1568
|
use Carp; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
277
|
|
11
|
4
|
|
|
4
|
|
554
|
use Crypt::Digest::Keccak256 qw(keccak256_hex); |
|
4
|
|
|
|
|
4339
|
|
|
4
|
|
|
|
|
2727
|
|
12
|
|
|
|
|
|
|
|
13
|
90
|
|
|
90
|
0
|
176
|
field $address :reader :writer :param; |
|
90
|
|
|
18
|
0
|
565
|
|
|
18
|
|
|
|
|
51
|
|
|
18
|
|
|
|
|
245
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
ADJUST { |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $unprefixed = $self->address =~ s/^0x//r; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
croak 'Invalid address format' unless length($unprefixed) == 40; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my @hashed_chars = split //, keccak256_hex(lc $unprefixed); |
22
|
|
|
|
|
|
|
my @address_chars = split //, $unprefixed; |
23
|
|
|
|
|
|
|
my $checksummed_chars = ''; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$checksummed_chars .= hex $hashed_chars[$_] >= 8 ? uc $address_chars[$_] : lc $address_chars[$_] for 0 .. length($unprefixed) - 1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$self->set_address($checksummed_chars); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
18
|
|
|
18
|
1
|
54
|
method no_prefix { |
31
|
|
|
|
|
|
|
|
32
|
18
|
|
|
|
|
34
|
my $unprefixed = $self->address =~ s/^0x//r; |
33
|
18
|
|
|
|
|
87
|
return $unprefixed; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use overload |
37
|
4
|
|
|
|
|
41
|
fallback => 1, |
38
|
4
|
|
|
4
|
|
1301
|
'""' => \&to_string; |
|
4
|
|
|
|
|
1030
|
|
39
|
|
|
|
|
|
|
|
40
|
27
|
|
|
27
|
1
|
7386
|
method to_string { |
41
|
|
|
|
|
|
|
|
42
|
27
|
50
|
|
|
|
90
|
return $self->address if $self->address =~ /^0x/; |
43
|
27
|
|
|
|
|
85
|
return '0x' . $self->address; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding UTF-8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Blockchain::Ethereum::Keystore::Address |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 VERSION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
version 0.006 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Import an existing address: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $address = Blockchain::Ethereum::Address->new(0x...); |
67
|
|
|
|
|
|
|
# print checksummed address |
68
|
|
|
|
|
|
|
print $address; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Generate a new address: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $key = Blockchain::Ethereum::Key->new; |
73
|
|
|
|
|
|
|
my $address = $key->address; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 no_prefix |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Returns the checksummed address without the 0x prefix |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 to_string |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Returns the checksummed 0x prefixed address |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This function will be called as the default stringification method |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Reginaldo Costa <refeco@cpan.org> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by REFECO. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This is free software, licensed under: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The MIT (X11) License |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |