File Coverage

blib/lib/CryptoTron/GetAccount.pm
Criterion Covered Total %
statement 20 26 76.9
branch n/a
condition n/a
subroutine 7 8 87.5
pod 0 1 0.0
total 27 35 77.1


line stmt bran cond sub pod time code
1             package CryptoTron::GetAccount;
2              
3             # Load the Perl pragmas.
4 1     1   67160 use 5.010001;
  1         4  
5 1     1   5 use strict;
  1         2  
  1         18  
6 1     1   5 use warnings;
  1         2  
  1         50  
7              
8             # Load the Perl pragma Exporter.
9 1     1   6 use vars qw(@ISA @EXPORT @EXPORT_OK);
  1         2  
  1         69  
10 1     1   7 use Exporter 'import';
  1         1  
  1         71  
11              
12             # Base class of this module.
13             our @ISA = qw(Exporter);
14              
15             # Exporting the implemented subroutine.
16             our @EXPORT = qw(GetAccount);
17              
18             # Set the package version.
19             our $VERSION = '0.18';
20              
21             # Load the required Perl module.
22 1     1   7 use File::Basename;
  1         1  
  1         121  
23              
24             # Load the required package module.
25 1     1   429 use CryptoTron::JsonHttp;
  1         3  
  1         257  
26              
27             # Get the package name.
28             our ($MODULE_NAME, undef, undef) = fileparse(__FILE__, '\..*');
29              
30             # ---------------------------------------------------------------------------- #
31             # Subroutine GetAccount() #
32             # #
33             # Description: #
34             # Get the account information of a Tron account from the Tron blockchain using #
35             # the full-node HTTP Tron API. #
36             # #
37             # @argument {PublicKey => $PublicKey, #
38             # VisibleFlag => ["True"|"False"|""], #
39             # ControlFlag => ["True"|"False"|""], #
40             # OutputFormat => ["RAW"|"STR"|""]} (hash) #
41             # @return $output_data Response content (scalar) #
42             # ---------------------------------------------------------------------------- #
43             sub GetAccount {
44             # Assign the subroutine arguments to the local array.
45 0     0 0   my (%param) = @_;
46             # Create the payload.
47 0           my $payload = payload_standard(\%param);
48             # Add the payload to the given hash.
49 0           $param{'PayloadString'} = $payload;
50             # Add the module name to the given hash.
51 0           $param{'ModuleName'} = $MODULE_NAME;
52             # Get the ouput data.
53 0           my $output_data = json_data(\%param);
54             # Return the ouput data.
55 0           return $output_data;
56             };
57              
58             1;
59              
60             __END__
61              
62             =head1 NAME
63              
64             CryptoTron::GetAccount - Perl extension for use with the blockchain of the crypto coin Tron.
65              
66             =head1 SYNOPSIS
67              
68             use CryptoTron::GetAccount;
69              
70             # Set the public key as Base58 address.
71             my $PublicKeyBase58 = "TY2fJ7AcsnQhfW3UJ1cjEUak5vkM87KC6R";
72              
73             # Set the visible flag.
74             my $VisibleFlag = ["True"|"False"|""];
75              
76             # Set the control flag.
77             my $ControlFlag = ["True"|"False"|""];
78              
79             # Set the output format.
80             my $OutputFormat = ["RAW"|"STR"|""];
81              
82             # Request the account info from the mainnet.
83             my $account_info = GetAccount(
84             PublicKey => $PublicKeyBase58
85             [, VisibleFlag => $VisibleFlag]
86             [, ControlFlag => $ControlFlag]
87             [, OutputFormat => $OutputFormat]
88             );
89              
90             # Print the account info into the terminal window.
91             print $account_info;
92              
93             =head1 DESCRIPTION
94              
95             The module requests the account information of an Tron account from the Tron
96             blockchain using the so-called full-node HTTP API from the Tron developer
97             network. The module is designed for use with Tron Mainnet. For HTTP requests
98             the methods C<POST> or C<GET> can be used in general. For the method
99             C<GetAccount> the needed method is C<POST>. The payload of the HTTP request
100             consists of the key 'address' and the key 'visible' and the related values.
101             The switch 'visible' can be set to C<"True"> or C<"False">. If the switch is
102             set to C<"True"> a Base58 address is used. If the switch is set to C<"False">
103             a Hex address is used. A request of the service API results in a response in
104             JSON format. The module returns formatted string JSON data as well as
105             unformated raw JSON data based on the output format flag. The parsing of the
106             account information is done by a separate module.
107              
108             =head1 METHOD
109              
110             GetAccount()
111              
112             =head1 OPTIONS
113              
114             The named subroutine argument key C<PublicKey> and the related value are
115             mandatory, the named subroutine arguments keys C<OutputFormat> as well as
116             C<VisibleFlag> and there values are optional. The value of the subroutine
117             argument key C<PublicKey> can be a Base58 address or a Hex address. The
118             value of the subroutine argument key C<VisibleFlag> can be "True" or
119             "False".
120              
121             Public key and visible flag are related to each other:
122              
123             C<PublicKey>: Base58 address => C<VisibleFlag>: True
124              
125             C<PublicKey>: Hex address => C<VisibleFlag>: False
126              
127             If the given combination in the subroutine arguments is not valid, an error
128             will be returned from the request.
129              
130             The subroutine argument key C<ControlFlag> and his value controls if the given
131             combination of public key and visible flag should be checked. If visible is not
132             set in a correct way, the value will be corrected if the flag is "True" and if
133             the flag is "False" it will not be corrected.
134              
135             The subroutine argument key C<OutputFormat> and his value controls wether the
136             output is raw JSON or or formatted JSON.
137              
138             =head1 METHOD RETURN
139              
140             Next others, the method returns informations about the balance, the staked and
141             voted balance, and timestamps.
142              
143             =over 4
144              
145             =item * Free available balance
146              
147             =item * Frozen staked balance
148              
149             =back
150              
151             =over 4
152              
153             =item * Voted balance
154              
155             =item * SR vote address and number of votes
156              
157             =back
158              
159             =over 4
160              
161             =item * Frozen BANDWIDTH
162              
163             =item * Expiration date and time of frozen BANDWIDTH
164              
165             =item * Frozen ENERGY
166              
167             =item * Expiration date and time of frozen ENERGY
168              
169             =back
170              
171             =over 4
172              
173             =item * Creation date and time of account
174              
175             =item * Date and time of last operation
176              
177             =item * Last date and time when BANDWIDTH was consumed
178              
179             =item * Last date and time when ENERGY was consumed
180              
181             =item * Lastest consume date and time
182              
183             =item * Lastest withdraw date and time
184              
185             =back
186              
187             The format of returned data and time is a Epoch Unix timestamp given in
188             milliseconds. 1 second equals to 1 milliseconds. The epoch Unix timestamp
189             is a way to track time as a running total of seconds since the Epoch on
190             January 1st, 1970 at UTC.
191              
192             The values of the balances are returned in SUN. 1 TRX equals to 1,000,000
193             SUN. SUN is named after the founder of Tron. A Tron balance in TRX given as
194             a decimal value can never have more than six digits after the decimal point.
195              
196             With the above knowledge, both raw JSON data as well as string JSON data can
197             be interpreted directly by the user without automated parsing.
198              
199             =head1 EXAMPLES
200              
201             =head2 Example 1
202              
203             # Load the required module.
204             use CryptoTron::GetAccount;
205              
206             # Set the public key as Base58 address.
207             my $PublicKeyBase58 = "TY2fJ7AcsnQhfW3UJ1cjEUak5vkM87KC6R";
208              
209             # Set the visible flag.
210             my $VisibleFlag = "True";
211              
212             # Set the control flag.
213             my $ControlFlag = "True";
214              
215             # Set the output format.
216             my $OutputFormat = "RAW";
217              
218             # Request the account info from the mainnet.
219             my $account_info = GetAccount({
220             PublicKey => $PublicKeyBase58,
221             VisibleFlag => $VisibleFlag,
222             ControlFlag => $ControlFlag,
223             OutputFormat => $OutputFormat
224             });
225              
226             # Print the account info into the terminal window.
227             print $account_info;
228              
229             =head2 Example 2
230              
231             # Load the required module.
232             use CryptoTron::GetAccount;
233              
234             # Set the public key as Base58 address.
235             my $PublicKeyBase58 = "TY2fJ7AcsnQhfW3UJ1cjEUak5vkM87KC6R";
236              
237             # Set the output format.
238             my $OutputFormat = "STR";
239              
240             # Request the account info from the mainnet.
241             my $response = GetAccount({PublicKey => $PublicKeyBase58});
242              
243             # Print the account info into the terminal window.
244             print $response;
245              
246              
247             =head1 LIMITATIONS
248              
249             The module is working with the Tron Mainnet, but not with other existing
250             Tron Testnets.
251              
252             =head1 NOTES
253              
254             As long as there is no balance in a Tron account, information's about such an
255             account cannot be retrieved. It is only possible to check if the Tron public
256             address is valid or not.
257              
258             =head1 ERROR CODES
259              
260             No error codes returned yet.
261              
262             =head1 OPEN ISSUES
263              
264             No open issues yet.
265              
266             =head1 BUGS
267              
268             No known bugs yet.
269              
270             =head1 TODO
271              
272             Nothing to do yet.
273              
274             =head1 SEE ALSO
275              
276             CryptoTron::JsonHttp
277              
278             CryptoTron:ParseAccount
279              
280             CryptoTron:AddressCheck
281              
282             CryptoTron:AddressConvert
283              
284             L<File::Basename|https://metacpan.org/pod/File::Basename/>
285              
286             L<TRON Developer Hub|https://developers.tron.network/>
287              
288             =head1 AUTHOR
289              
290             Dr. Peter Netz, E<lt>ztenretep@cpan.orgE<gt>
291              
292             =head1 COPYRIGHT AND LICENSE
293              
294             Copyright (C) 2022 by Dr. Peter Netz
295              
296             This library is free software; you can redistribute it and/or modify it
297             under the same terms of The MIT License. For more details, see the full
298             text of the license in the attached file LICENSE in the main module folder.
299             This program is distributed in the hope that it will be useful, but without
300             any warranty; without even the implied warranty of merchantability or fitness
301             for a particular purpose.
302              
303             =cut