| 1 | package Ethereum::RPC::Contract::Helper::UnitConversion; | ||
| 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 | 8 | ▶ | use Math::BigInt; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 8 | our $VERSION = '0.05'; | |
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Ethereum::RPC::Contract::Helper::UnitConversion - Ethereum Unit Converter | ||
| 12 | |||
| 13 | wei: '1' | ||
| 14 | kwei: '1E3' | ||
| 15 | mwei: '1E6' | ||
| 16 | gwei: '1E9' | ||
| 17 | szabo: '1E12' | ||
| 18 | finney: '1E15' | ||
| 19 | ether: '1E18' | ||
| 20 | kether: '1E21' | ||
| 21 | mether: '1E24' | ||
| 22 | gether: '1E27' | ||
| 23 | tether: '1E30' | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | 0 | ▶ | sub to_wei { |
|
Subroutine
to_wei: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 28 | 0 | return to_hex(shift, 1); | |
| 29 | } | ||
| 30 | |||
| 31 | 0 | ▶ | sub to_kwei { |
|
Subroutine
to_kwei: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 32 | 0 | return to_hex(shift, 1E3); | |
| 33 | } | ||
| 34 | |||
| 35 | 0 | ▶ | sub to_mwei { |
|
Subroutine
to_mwei: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 36 | 0 | return to_hex(shift, 1E6); | |
| 37 | } | ||
| 38 | |||
| 39 | 0 | ▶ | sub to_gwei { |
|
Subroutine
to_gwei: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 40 | 0 | return to_hex(shift, 1E9); | |
| 41 | } | ||
| 42 | |||
| 43 | 0 | ▶ | sub to_szabo { |
|
Subroutine
to_szabo: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 44 | 0 | return to_hex(shift, 1E12); | |
| 45 | } | ||
| 46 | |||
| 47 | 0 | ▶ | sub to_finney { |
|
Subroutine
to_finney: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 48 | 0 | return to_hex(shift, 1E15); | |
| 49 | } | ||
| 50 | |||
| 51 | 0 | ▶ | sub to_ether { |
|
Subroutine
to_ether: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 52 | 0 | return to_hex(shift, 1E18); | |
| 53 | } | ||
| 54 | |||
| 55 | 0 | ▶ | sub to_kether { |
|
Subroutine
to_kether: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 56 | 0 | return to_hex(shift, 1E21); | |
| 57 | } | ||
| 58 | |||
| 59 | 0 | ▶ | sub to_mether { |
|
Subroutine
to_mether: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 60 | 0 | return to_hex(shift, 1E24); | |
| 61 | } | ||
| 62 | |||
| 63 | 0 | ▶ | sub to_gether { |
|
Subroutine
to_gether: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 64 | 0 | return to_hex(shift, 1E27); | |
| 65 | } | ||
| 66 | |||
| 67 | 0 | ▶ | sub to_tether { |
|
Subroutine
to_tether: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 68 | 0 | return to_hex(shift, 1E30); | |
| 69 | } | ||
| 70 | |||
| 71 | 0 | ▶ | sub to_hex { |
|
Subroutine
to_hex: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 72 | 0 | my ($number, $precision) = @_; | |
| 73 | 0 | return "0x" . Math::BigFloat->new($number)->bmul($precision)->to_hex; | |
| 74 | } | ||
| 75 | |||
| 76 | 8 | 1; | |