line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Blockchain::Ethereum::ABI::Type::Tuple; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
61
|
use v5.26; |
|
5
|
|
|
|
|
19
|
|
4
|
5
|
|
|
5
|
|
53
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
155
|
|
5
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
123
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
29
|
use Carp; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
313
|
|
8
|
5
|
|
|
5
|
|
472
|
use parent qw(Blockchain::Ethereum::ABI::Type); |
|
5
|
|
|
|
|
328
|
|
|
5
|
|
|
|
|
40
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _configure { |
11
|
33
|
|
|
33
|
|
75
|
my $self = shift; |
12
|
33
|
100
|
|
|
|
108
|
return unless $self->_data; |
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
|
|
27
|
my @splited_signatures = $self->_split_tuple_signature->@*; |
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
|
|
32
|
for (my $sig_index = 0; $sig_index < @splited_signatures; $sig_index++) { |
17
|
29
|
|
|
|
|
83
|
push $self->_instances->@*, |
18
|
|
|
|
|
|
|
$self->new_type( |
19
|
|
|
|
|
|
|
signature => $splited_signatures[$sig_index], |
20
|
|
|
|
|
|
|
data => $self->_data->[$sig_index]); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _split_tuple_signature { |
26
|
18
|
|
|
18
|
|
32
|
my $self = shift; |
27
|
|
|
|
|
|
|
# remove the parentheses from tuple signature |
28
|
18
|
|
|
|
|
43
|
$self->_signature =~ /^\((.*)\)$/; |
29
|
18
|
|
|
|
|
51
|
my $tuple_signatures = $1; |
30
|
|
|
|
|
|
|
|
31
|
18
|
50
|
|
|
|
43
|
croak "Invalid tuple signature" unless $tuple_signatures; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# this looks through tuple signature recursively and break it into lines |
34
|
|
|
|
|
|
|
# this is to help splitting tuples inside tuples that also contains comma |
35
|
18
|
|
|
|
|
222
|
$tuple_signatures =~ s/((\((?>[^)(]*(?2)?)*\))|[^,()]*)(*SKIP),/$1\n/g; |
36
|
18
|
|
|
|
|
82
|
my @types = split('\n', $tuple_signatures); |
37
|
18
|
|
|
|
|
88
|
return \@types; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub encode { |
41
|
35
|
|
|
35
|
1
|
58
|
my $self = shift; |
42
|
35
|
100
|
|
|
|
113
|
return $self->_encoded if $self->_encoded; |
43
|
|
|
|
|
|
|
|
44
|
22
|
|
|
|
|
77
|
my $offset = $self->_get_initial_offset; |
45
|
|
|
|
|
|
|
|
46
|
16
|
|
|
|
|
57
|
for my $instance ($self->_instances->@*) { |
47
|
50
|
|
|
|
|
147
|
$instance->encode; |
48
|
50
|
100
|
|
|
|
187
|
if ($instance->is_dynamic) { |
49
|
14
|
|
|
|
|
57
|
$self->_push_static($self->_encode_offset($offset)); |
50
|
14
|
|
|
|
|
42
|
$self->_push_dynamic($instance->_encoded); |
51
|
14
|
|
|
|
|
54
|
$offset += scalar $instance->_encoded->@*; |
52
|
14
|
|
|
|
|
48
|
next; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
36
|
|
|
|
|
95
|
$self->_push_static($instance->_encoded); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
16
|
|
|
|
|
46
|
return $self->_encoded; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub decode { |
62
|
11
|
|
|
11
|
1
|
19
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
11
|
100
|
|
|
|
28
|
unless (scalar $self->_instances->@* > 0) { |
65
|
4
|
|
|
|
|
13
|
push $self->_instances->@*, $self->new_type(signature => $_) for $self->_split_tuple_signature->@*; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
11
|
|
|
|
|
53
|
return $self->_read_stack_set_data; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _static_size { |
72
|
6
|
|
|
6
|
|
13
|
my $self = shift; |
73
|
6
|
50
|
|
|
|
14
|
return 1 if $self->is_dynamic; |
74
|
6
|
|
|
|
|
13
|
my $size = 1; |
75
|
6
|
|
|
|
|
9
|
my $instance_size = 0; |
76
|
6
|
|
|
|
|
13
|
for my $signature ($self->_split_tuple_signature->@*) { |
77
|
12
|
|
|
|
|
32
|
my $instance = $self->new_type(signature => $signature); |
78
|
12
|
|
50
|
|
|
56
|
$instance_size += $instance->_static_size // 0; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
6
|
|
|
|
|
17
|
return $size * $instance_size; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding UTF-8 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Blockchain::Ethereum::ABI::Tuple - Interface for solidity tuple type |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Allows you to define and instantiate a solidity tuple type: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $type = Blockchain::Ethereum::ABI::Tuple->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::Tuple |
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 |