| 1 | package Ethereum::RPC::Contract::ContractResponse; | ||||||||||
| 2 | |||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 8 | our $VERSION = '0.05'; | |||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Ethereum::Contract::RPC::ContractResponse - Centralize contract response | ||||||||||
| 11 | |||||||||||
| 12 | =cut | ||||||||||
| 13 | |||||||||||
| 14 | 8 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 8 | ▶ | use Encode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 8 | ▶ | use Math::BigInt; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 8 | ▶ | use Math::BigFloat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 8 | has response => (is => 'ro'); | |||||||||
| 20 | |||||||||||
| 21 | =head2 to_big_int | ||||||||||
| 22 | |||||||||||
| 23 | Convert response to a Math::BigInt if not undef | ||||||||||
| 24 | |||||||||||
| 25 | Parameters: | ||||||||||
| 26 | hexadecimal response | ||||||||||
| 27 | |||||||||||
| 28 | Return: | ||||||||||
| 29 | new Math::BigInt | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub to_big_int { | ||||||||
|
Subroutine
to_big_int: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 34 | 0 | my $self = shift; | |||||||||
| 35 | 0 | ▶ | return Math::BigInt->from_hex($self->response) if $self->response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | return undef; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | =head2 to_big_float | ||||||||||
| 40 | |||||||||||
| 41 | Convert response to a Math::BigFloat if not undef | ||||||||||
| 42 | |||||||||||
| 43 | Parameters: | ||||||||||
| 44 | hexadecimal response | ||||||||||
| 45 | |||||||||||
| 46 | Return: | ||||||||||
| 47 | new Math::BigFloat | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub to_big_float { | ||||||||
|
Subroutine
to_big_float: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 52 | 0 | my $self = shift; | |||||||||
| 53 | 0 | ▶ | return Math::BigFloat->from_hex($self->response) if $self->response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | return undef; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | =head2 to_string | ||||||||||
| 58 | |||||||||||
| 59 | Convert response to a string if not undef | ||||||||||
| 60 | |||||||||||
| 61 | Parameters: | ||||||||||
| 62 | hexadecimal response | ||||||||||
| 63 | |||||||||||
| 64 | Return: | ||||||||||
| 65 | string | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub to_string { | ||||||||
|
Subroutine
to_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 70 | 0 | my $self = shift; | |||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | return undef unless $self->response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | |||||||||||
| 74 | 0 | my $packed_response = pack('H*', substr($self->response, -64)); | |||||||||
| 75 | 0 | $packed_response =~ s/\0+$//; | |||||||||
| 76 | |||||||||||
| 77 | 0 | return $packed_response; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | =head2 to_hex | ||||||||||
| 81 | |||||||||||
| 82 | Convert response to a hexadecimal if not undef and is not already a hex | ||||||||||
| 83 | |||||||||||
| 84 | Parameters: | ||||||||||
| 85 | hexadecimal response | ||||||||||
| 86 | |||||||||||
| 87 | Return: | ||||||||||
| 88 | hexadecimal string | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub to_hex { | ||||||||
|
Subroutine
to_hex: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 93 | 0 | my $self = shift; | |||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | return undef unless $self->response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | if ($self->response =~ /^0x[0-9A-F]+$/i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | return $self->response; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 0 | return undef; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 8 | 1; | |||||||||