ethereum 0.4.32 → 0.4.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5948872c1eb072bbcb97c3df39d9469f4e749ae3
4
- data.tar.gz: 474467c32c29e5df065ba20b2753a5170c3d591d
3
+ metadata.gz: 00f65f65034d0a9963c72cc2ff55296446dbbafe
4
+ data.tar.gz: 9d512ea06ecfcf9792c655f96c62aa591c812685
5
5
  SHA512:
6
- metadata.gz: 0d0fa5e9efe21ed8c3f33a1fbef141f64f1f8efe5d429fa40e1f015e3c14744ac2e6aa40e2b5fabed3b9f53373ce91cfd8c9e976c5ce53ed70687fa4d28f3ca0
7
- data.tar.gz: 950cc2a17be9a12de38587015e623b88e157b802d091fae6e3fbeaed8578673ed5609603dec14c7f8ba69497a9f4e389ad1fd98532343a52d769e8d78777279f
6
+ metadata.gz: ff9343ac8ffecc0ca2785f4cb8c0f985acec77c723946754873cd225c63e7bb051ef8b57fb7ebb87eda13ff2782e02b6f7963b3a71a1696434c0bf848ff84fe1
7
+ data.tar.gz: 5aca32e5e46303a92b98aa790ccd28a0544b09ada6ca4bbada48cced11b77575c1bfc9d1a9cca0dd5daa336da9be55ce23ce6aca8023ca8c7d91c2ca159ad9dd
@@ -1,6 +1,34 @@
1
1
  module Ethereum
2
2
  class Formatter
3
3
 
4
+ UNITS = {
5
+ wei: 1,
6
+ kwei: 1000,
7
+ ada: 1000,
8
+ femtoether: 1000,
9
+ mwei: 1000000,
10
+ babbage: 1000000,
11
+ picoether: 1000000,
12
+ gwei: 1000000000,
13
+ shannon: 1000000000,
14
+ nanoether: 1000000000,
15
+ nano: 1000000000,
16
+ szabo: 1000000000000,
17
+ microether: 1000000000000,
18
+ micro: 1000000000000,
19
+ finney: 1000000000000000,
20
+ milliether: 1000000000000000,
21
+ milli: 1000000000000000,
22
+ ether: 1000000000000000000,
23
+ eth: 1000000000000000000,
24
+ kether: 1000000000000000000000,
25
+ grand: 1000000000000000000000,
26
+ einstein: 1000000000000000000000,
27
+ mether: 1000000000000000000000000,
28
+ gether: 1000000000000000000000000000,
29
+ tether: 1000000000000000000000000000000
30
+ }
31
+
4
32
  def from_bool(boolval)
5
33
  boolval ? "1" : "0"
6
34
  end
@@ -29,6 +57,14 @@ module Ethereum
29
57
  "0x" + hexstring[-40..-1]
30
58
  end
31
59
 
60
+ def to_wei(amount, unit)
61
+ BigDecimal.new(UNITS[unit.to_sym] * amount, 18).to_s.to_i
62
+ end
63
+
64
+ def from_wei(amount, unit)
65
+ (BigDecimal.new(amount, 18) / BigDecimal.new(UNITS[unit.to_sym], 18)).to_s
66
+ end
67
+
32
68
  def from_address(address)
33
69
  address.gsub(/^0x/,'').rjust(64, "0")
34
70
  end
@@ -1,3 +1,3 @@
1
1
  module Ethereum
2
- VERSION = "0.4.32"
2
+ VERSION = "0.4.35"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethereum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.32
4
+ version: 0.4.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - DigixGlobal Pte Ltd (https://dgx.io)