CryptoTron-JsonHttp
view release on metacpan or search on metacpan
lib/CryptoTron/BroadcastTransaction.pm view on Meta::CPAN
# from the HTTP response using the method POST. #
# #
# @argument $content Response content (scalar) #
# @returns $json_encode Encoded content (scalar) #
# ---------------------------------------------------------------------------- #
sub encode {
# Assign the argument to the local variable.
my $content = $_[0];
# Decode the content from the response.
my $json_decode = $JSON->decode($content);
# Encode the decoded content from the response.
my $json_encode = $JSON->encode($json_decode);
# Return the encoded content.
return $json_encode;
};
# ---------------------------------------------------------------------------- #
# Subroutine get_response() #
# #
# Description: #
# The subroutine is using the HTTP method POST to retrieve the response from #
lib/CryptoTron/JsonHttp.pm view on Meta::CPAN
# Encode the content.
$output = encode_data($content);
};
# Return formatted output.
return $output;
};
# ---------------------------------------------------------------------------- #
# Subroutine encode_data() #
# #
# Description: #
# At first glance, it is not obvious why the response should be decoded and #
# then encoded back again. However, if one assumes that the response can have #
# any structure, this procedure makes sense. Decoding creates a Perl data #
# structure from the response. Encoding then creates a formatted string from #
# the Perl data structure. #
# #
# @argument $content Content from response (scalar) #
# @return $encoded Encoded formatted content (scalar) #
# ---------------------------------------------------------------------------- #
sub encode_data {
# Assign the subroutine argument to the local variable.
my $content = $_[0];
# Decode the content of the response using 'JSON:PP'.
my $decoded = $JSON->decode($content);
# Encode the content of the response using 'JSON:PP'.
my $encoded = $JSON->encode($decoded);
# Return the encoded formatted JSON content.
return $encoded;
};
# ---------------------------------------------------------------------------- #
# Subroutine HTTP_Request() #
# #
# Description: #
# The subroutine is using the HTTP methods GET or POST to send a request to a #
# known servive url of the FULL-NODE HTTP API. On success a content in form of #
lib/CryptoTron/ParseAccount.pm view on Meta::CPAN
# Description: #
# Parse the JSON account data and determine the relevant balance values. #
# #
# @argument $_[0] -> $json_data Raw JSON data (scalar) #
# @return ($free, $frozen, $energy) Balance values (array) #
# ---------------------------------------------------------------------------- #
sub getValues{
# Assign the argument to the local variable.
my $json_data = (defined $_[0] ? $_[0] : '{}');
# Declare the local variables.
my $decoded;
my $free;
my $frozen;
my $energy;
# Try to decode the JSON data.
try {
# Decode the JSON data to get a valid hash.
$decoded = $JSON->decode($json_data);
# Get the balance values from the JSON data.
$free = $decoded->{$KEYS[0]};
$frozen = $decoded->{$KEYS[1]}[0]{$KEYS[2]};
$energy = $decoded->{$KEYS[3]}{$KEYS[4]}{$KEYS[2]};
} catch {
# Silent interception of an error.
# print "Something went wrong using the raw JSON data.\n";
;
};
# Check the values.
$free = (defined $free ? $free : 0);
$frozen = (defined $frozen ? $frozen : 0);
$energy = (defined $energy ? $energy : 0);
# Return the balance values.
lib/CryptoTron/ParseAccount.pm view on Meta::CPAN
return $total_frozen;
};
# ---------------------------------------------------------------------------- #
# Subroutine getTimeValues() #
# ---------------------------------------------------------------------------- #
sub getTimeValues {
# Assign the argument to the local variable.
my $json_data = (defined $_[0] ? $_[0] : '{}');
# Declare the local variables.
my $decoded;
my $create_time;
my $latest_withdraw_time;
my $next_withdraw_time;
# Try to decode the JSON data.
try {
# Decode the JSON data to get a valid hash.
$decoded = $JSON->decode($json_data);
# Get the balance values from the JSON data.
$create_time = date_time($decoded->{$TIME_KEYS[0]});
$latest_withdraw_time = date_time($decoded->{$TIME_KEYS[1]});
$next_withdraw_time = date_time($decoded->{$TIME_KEYS[1]} + 86400*1000);
} catch {
# Silent interception of an error.
# print "Something went wrong using the raw JSON data.\n";
;
};
# Check the values.
$create_time = (defined $create_time ? $create_time : 0);
$latest_withdraw_time = (defined $latest_withdraw_time ? $latest_withdraw_time : 0);
$next_withdraw_time = (defined $next_withdraw_time ? $next_withdraw_time : 0);
# Return the balance values.
( run in 0.275 second using v1.01-cache-2.11-cpan-26ccb49234f )