line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Blockchain::Ethereum::ABI::Type::Bytes; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2233
|
use v5.26; |
|
4
|
|
|
|
|
15
|
|
4
|
4
|
|
|
4
|
|
26
|
use strict; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
101
|
|
5
|
4
|
|
|
4
|
|
144
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
149
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
23
|
use Carp; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
342
|
|
8
|
4
|
|
|
4
|
|
28
|
use parent qw(Blockchain::Ethereum::ABI::Type); |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub encode { |
11
|
28
|
|
|
28
|
1
|
50
|
my $self = shift; |
12
|
28
|
100
|
|
|
|
63
|
return $self->_encoded if $self->_encoded; |
13
|
|
|
|
|
|
|
# remove 0x and validates the hexadecimal value |
14
|
12
|
50
|
0
|
|
|
42
|
croak 'Invalid hexadecimal value ' . $self->_data // 'undef' |
15
|
|
|
|
|
|
|
unless $self->_data =~ /^(?:0x|0X)?([a-fA-F0-9]+)$/; |
16
|
12
|
|
|
|
|
41
|
my $hex = $1; |
17
|
|
|
|
|
|
|
|
18
|
12
|
|
|
|
|
60
|
my $data_length = length(pack("H*", $hex)); |
19
|
12
|
100
|
|
|
|
38
|
unless ($self->fixed_length) { |
20
|
|
|
|
|
|
|
# for dynamic length basic types the length must be included |
21
|
6
|
|
|
|
|
28
|
$self->_push_dynamic($self->_encode_length($data_length)); |
22
|
6
|
|
|
|
|
26
|
$self->_push_dynamic($self->pad_right($hex)); |
23
|
|
|
|
|
|
|
} else { |
24
|
6
|
50
|
33
|
|
|
15
|
croak "Invalid data length, signature: @{[$self->fixed_length]}, data length: $data_length" |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
if $self->fixed_length && $data_length != $self->fixed_length; |
26
|
6
|
|
|
|
|
28
|
$self->_push_static($self->pad_right($hex)); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
12
|
|
|
|
|
36
|
return $self->_encoded; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub decode { |
33
|
9
|
|
|
9
|
1
|
16
|
my $self = shift; |
34
|
9
|
|
|
|
|
24
|
my @data = $self->_data->@*; |
35
|
|
|
|
|
|
|
|
36
|
9
|
|
|
|
|
17
|
my $hex_data; |
37
|
9
|
|
|
|
|
21
|
my $size = $self->fixed_length; |
38
|
9
|
100
|
|
|
|
21
|
unless ($self->fixed_length) { |
39
|
4
|
|
|
|
|
10
|
$size = hex shift @data; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
14
|
$hex_data = join('', @data); |
42
|
|
|
|
|
|
|
} else { |
43
|
5
|
|
|
|
|
10
|
$hex_data = $data[0]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
9
|
|
|
|
|
55
|
my $bytes = substr(pack("H*", $hex_data), 0, $size); |
47
|
9
|
|
|
|
|
89
|
return sprintf "0x%s", unpack("H*", $bytes); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding UTF-8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Blockchain::Ethereum::ABI::Bytes - Interface for solidity bytes type |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Allows you to define and instantiate a solidity bytes type: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $type = Blockchain::Ethereum::ABI::Bytes->new( |
63
|
|
|
|
|
|
|
signature => $signature, |
64
|
|
|
|
|
|
|
data => $value |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$type->encode(); |
68
|
|
|
|
|
|
|
... |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
In most cases you don't want to use this directly, use instead: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over 4 |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item * B: L |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item * B: L |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 METHODS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 encode |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Encodes the given data to the type of the signature |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Usage: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
encode() -> encoded string |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 4 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=back |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 decode |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Decodes the given data to the type of the signature |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Usage: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
decoded() -> hexadecimal encoded bytes |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
hexadecimal encoded bytes string |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Reginaldo Costa, C<< >> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 BUGS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Please report any bugs or feature requests to L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SUPPORT |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
perldoc Blockchain::Ethereum::ABI::Bytes |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by REFECO. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software, licensed under: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The MIT License |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |