File Coverage

blib/lib/Ethereum/RPC/Contract/Helper/UnitConversion.pm
Criterion Covered Total %
statement 9 22 40.9
branch n/a
condition n/a
subroutine 3 15 20.0
pod 0 12 0.0
total 12 49 24.4


line stmt bran cond sub pod time code
1             package Ethereum::RPC::Contract::Helper::UnitConversion;
2              
3 4     4   28 use strict;
  4         11  
  4         130  
4 4     4   24 use warnings;
  4         10  
  4         92  
5 4     4   20 use Math::BigInt;
  4         9  
  4         35  
6              
7             our $VERSION = '0.04';
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             sub to_wei {
28 0     0 0   return to_hex(shift, 1);
29             }
30              
31             sub to_kwei {
32 0     0 0   return to_hex(shift, 1E3);
33             }
34              
35             sub to_mwei {
36 0     0 0   return to_hex(shift, 1E6);
37             }
38              
39             sub to_gwei {
40 0     0 0   return to_hex(shift, 1E9);
41             }
42              
43             sub to_szabo {
44 0     0 0   return to_hex(shift, 1E12);
45             }
46              
47             sub to_finney {
48 0     0 0   return to_hex(shift, 1E15);
49             }
50              
51             sub to_ether {
52 0     0 0   return to_hex(shift, 1E18);
53             }
54              
55             sub to_kether {
56 0     0 0   return to_hex(shift, 1E21);
57             }
58              
59             sub to_mether {
60 0     0 0   return to_hex(shift, 1E24);
61             }
62              
63             sub to_gether {
64 0     0 0   return to_hex(shift, 1E27);
65             }
66              
67             sub to_tether {
68 0     0 0   return to_hex(shift, 1E30);
69             }
70              
71             sub to_hex {
72 0     0 0   my ($number, $precision) = @_;
73 0           return "0x" . Math::BigFloat->new($number)->bmul($precision)->to_hex;
74             }
75              
76             1;