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 +4 -4
- data/lib/ethereum/formatter.rb +36 -0
- data/lib/ethereum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00f65f65034d0a9963c72cc2ff55296446dbbafe
|
4
|
+
data.tar.gz: 9d512ea06ecfcf9792c655f96c62aa591c812685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff9343ac8ffecc0ca2785f4cb8c0f985acec77c723946754873cd225c63e7bb051ef8b57fb7ebb87eda13ff2782e02b6f7963b3a71a1696434c0bf848ff84fe1
|
7
|
+
data.tar.gz: 5aca32e5e46303a92b98aa790ccd28a0544b09ada6ca4bbada48cced11b77575c1bfc9d1a9cca0dd5daa336da9be55ce23ce6aca8023ca8c7d91c2ca159ad9dd
|
data/lib/ethereum/formatter.rb
CHANGED
@@ -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
|
data/lib/ethereum/version.rb
CHANGED