line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Blockchain::Ethereum::ABI::Type::Array; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
2840
|
use v5.26; |
|
5
|
|
|
|
|
24
|
|
4
|
5
|
|
|
5
|
|
28
|
use strict; |
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
115
|
|
5
|
5
|
|
|
5
|
|
23
|
use warnings; |
|
5
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
154
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
23
|
use Carp; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
373
|
|
8
|
5
|
|
|
5
|
|
33
|
use parent qw(Blockchain::Ethereum::ABI::Type); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _configure { |
11
|
20
|
|
|
20
|
|
40
|
my $self = shift; |
12
|
20
|
100
|
|
|
|
71
|
return unless $self->_data; |
13
|
|
|
|
|
|
|
|
14
|
17
|
|
|
|
|
58
|
for my $item ($self->_data->@*) { |
15
|
36
|
|
|
|
|
100
|
push $self->_instances->@*, |
16
|
|
|
|
|
|
|
$self->new_type( |
17
|
|
|
|
|
|
|
signature => $self->_remove_parent, |
18
|
|
|
|
|
|
|
data => $item |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub encode { |
24
|
39
|
|
|
39
|
1
|
63
|
my $self = shift; |
25
|
39
|
100
|
|
|
|
94
|
return $self->_encoded if $self->_encoded; |
26
|
|
|
|
|
|
|
|
27
|
17
|
|
|
|
|
47
|
my $length = scalar $self->_data->@*; |
28
|
|
|
|
|
|
|
# for dynamic length arrays the length must be included |
29
|
17
|
100
|
|
|
|
39
|
$self->_push_static($self->_encode_length($length)) |
30
|
|
|
|
|
|
|
unless $self->fixed_length; |
31
|
|
|
|
|
|
|
|
32
|
17
|
100
|
100
|
|
|
53
|
croak "Invalid array size, signature @{[$self->fixed_length]}, data: $length" |
|
1
|
|
|
|
|
3
|
|
33
|
|
|
|
|
|
|
if $self->fixed_length && $length > $self->fixed_length; |
34
|
|
|
|
|
|
|
|
35
|
16
|
|
|
|
|
61
|
my $offset = $self->_get_initial_offset; |
36
|
|
|
|
|
|
|
|
37
|
16
|
|
|
|
|
46
|
for my $instance ($self->_instances->@*) { |
38
|
32
|
100
|
|
|
|
70
|
$self->_push_static($self->_encode_offset($offset)) |
39
|
|
|
|
|
|
|
if $instance->is_dynamic; |
40
|
|
|
|
|
|
|
|
41
|
32
|
|
|
|
|
83
|
$self->_push_dynamic($instance->encode); |
42
|
32
|
|
|
|
|
96
|
$offset += scalar $instance->encode()->@*; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
16
|
|
|
|
|
36
|
return $self->_encoded; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub decode { |
49
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
50
|
3
|
|
|
|
|
12
|
my @data = $self->_data->@*; |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
66
|
|
|
7
|
my $size = $self->fixed_length // shift $self->_data->@*; |
53
|
3
|
|
|
|
|
15
|
push $self->_instances->@*, $self->new_type(signature => $self->_remove_parent) for 0 .. $size - 1; |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
17
|
return $self->_read_stack_set_data; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _remove_parent { |
59
|
43
|
|
|
43
|
|
75
|
my $self = shift; |
60
|
43
|
|
|
|
|
106
|
$self->_signature =~ /(\[(\d+)?\]$)/; |
61
|
43
|
|
50
|
|
|
114
|
return substr $self->_signature, 0, length($self->_signature) - length($1 // ''); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub fixed_length { |
65
|
44
|
|
|
44
|
1
|
83
|
my $self = shift; |
66
|
44
|
50
|
|
|
|
107
|
if ($self->_signature =~ /\[(\d+)?\]$/) { |
67
|
44
|
|
|
|
|
599
|
return $1; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
0
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _static_size { |
73
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
74
|
2
|
50
|
|
|
|
5
|
return 1 if $self->is_dynamic; |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
7
|
my $size = $self->fixed_length; |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
3
|
my $instance_size = 1; |
79
|
2
|
|
|
|
|
9
|
for my $instance ($self->_instances->@*) { |
80
|
0
|
|
|
|
|
0
|
$instance_size += $instance->_static_size; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
8
|
return $size * $instance_size; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding UTF-8 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Blockchain::Ethereum::ABI::Array - Interface for solidity array type |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Allows you to define and instantiate a solidity tuple type: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $type = Blockchain::Ethereum::ABI::Array->new( |
99
|
|
|
|
|
|
|
signature => $signature, |
100
|
|
|
|
|
|
|
data => $value |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$type->encode(); |
104
|
|
|
|
|
|
|
... |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
In most cases you don't want to use this directly, use instead: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=over 4 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * B: L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * B: L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 encode |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Encodes the given data to the type of the signature |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Usage: |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
encode() -> encoded string |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over 4 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 decode |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Decodes the given data to the type of the signature |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Usage: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
decoded() -> array reference |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Array reference |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Reginaldo Costa, C<< >> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 BUGS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Please report any bugs or feature requests to L |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SUPPORT |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
perldoc Blockchain::Ethereum::ABI::Array |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by REFECO. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This is free software, licensed under: |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
The MIT License |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |