Last active
January 25, 2021 18:00
Revisions
-
descovi revised this gist
Jan 25, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Example of usage: # result = WeiConverter.new(1890000000000000000).call # Result contains 1.89 class WeiConverter -
descovi revised this gist
Jan 25, 2021 . No changes.There are no files selected for viewing
-
descovi revised this gist
Jan 25, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ # Example of usage: # result = WeiConverter.new(1890000000000000000).call # Result contain 1.89 class WeiConverter -
descovi revised this gist
Jan 25, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ # Example: WeiConverter.new(wei_number).call class WeiConverter UNITS = { wei: 1, -
descovi created this gist
Jan 25, 2021 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ class Wei UNITS = { wei: 1, kwei: 1000, ada: 1000, femtoether: 1000, mwei: 1000000, babbage: 1000000, picoether: 1000000, gwei: 1000000000, shannon: 1000000000, nanoether: 1000000000, nano: 1000000000, szabo: 1000000000000, microether: 1000000000000, micro: 1000000000000, finney: 1000000000000000, milliether: 1000000000000000, milli: 1000000000000000, ether: 1000000000000000000, eth: 1000000000000000000, kether: 1000000000000000000000, grand: 1000000000000000000000, einstein: 1000000000000000000000, mether: 1000000000000000000000000, gether: 1000000000000000000000000000, tether: 1000000000000000000000000000000 } def initialize(amount) @amount = amount end def call(unit: "ether") return nil if @amount.nil? unit = UNITS[unit.to_sym] (BigDecimal.new(@amount, 16) / BigDecimal.new(unit, 16)).to_s rescue nil end end