ethereum_unit_converter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e7fb532ab5c4c60424366af349aa39d67052683488bb1fe13fe718d19defc98d
4
+ data.tar.gz: 2ca2a32732b0e6d022f2dd10fb4ad348f2c535334107069a365c5e01c3422b2f
5
+ SHA512:
6
+ metadata.gz: bfb81ebae308c5be9b2f82fc6eccfd0537968d243b82c8432104df5b944e4f76121040c9205acfc1141129d224c4b29ee3a25f269a789fd7cb9853d334f3ba4f
7
+ data.tar.gz: 2d65cea859e5cba8ec12cb8875ac0db1b2c346079ab129b9d639cc1fd4c4f82f7407627481c82e7fdff69c1ba910c1840bcd639604e02e9c9c47e5f288a7017f
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ethereum_unit_converter.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ethereum_unit_converter (0.1.0)
5
+ bigdecimal (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ bigdecimal (3.0.0)
11
+ minitest (5.14.2)
12
+ rake (13.0.3)
13
+
14
+ PLATFORMS
15
+ x86_64-darwin-20
16
+
17
+ DEPENDENCIES
18
+ ethereum_unit_converter!
19
+ minitest (~> 5.0)
20
+ rake (~> 13.0)
21
+
22
+ BUNDLED WITH
23
+ 2.3.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # EthereumUnitConverter
2
+
3
+ Ethereum unit converter in Ruby
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'ethereum_unit_converter'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle install
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install ethereum_unit_converter
19
+
20
+ ## Usage
21
+
22
+ ### Convert from unit to unit
23
+ ```ruby
24
+ # EthereumUnitConverter.convert(amount, unit = 'wei', to_unit = 'ether')
25
+ EthereumUnitConverter.convert(10000, 'wei', 'eth') # "0.00000000000001"
26
+ EthereumUnitConverter.convert(1, 'eth', 'wei') # "1000000000000000000.0"
27
+ EthereumUnitConverter.convert(1, 'eth', 'tether') # "0.000000000001"
28
+ EthereumUnitConverter.convert(100, 'ada', 'eth') # "0.0000000000001"
29
+ ```
30
+ ### Supported Unit
31
+ ```
32
+ UNITS = {
33
+ wei: 1,
34
+ kwei: 1000,
35
+ ada: 1000,
36
+ femtoether: 1000,
37
+ mwei: 1_000_000,
38
+ babbage: 1_000_000,
39
+ picoether: 1_000_000,
40
+ gwei: 1_000_000_000,
41
+ shannon: 1_000_000_000,
42
+ nanoether: 1_000_000_000,
43
+ nano: 1_000_000_000,
44
+ szabo: 1_000_000_000_000,
45
+ microether: 1_000_000_000_000,
46
+ micro: 1_000_000_000_000,
47
+ finney: 1_000_000_000_000_000,
48
+ milliether: 1_000_000_000_000_000,
49
+ milli: 1_000_000_000_000_000,
50
+ ether: 1_000_000_000_000_000_000,
51
+ eth: 1_000_000_000_000_000_000,
52
+ kether: 1_000_000_000_000_000_000_000,
53
+ grand: 1_000_000_000_000_000_000_000,
54
+ einstein: 1_000_000_000_000_000_000_000,
55
+ mether: 1_000_000_000_000_000_000_000_000,
56
+ gether: 1_000_000_000_000_000_000_000_000_000,
57
+ tether: 1_000_000_000_000_000_000_000_000_000_000
58
+ }
59
+
60
+ ```
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bayevels/ethereum_unit_converter.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ethereum_unit_converter"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EthereumUnitConverter
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ethereum_unit_converter/version'
4
+
5
+ module EthereumUnitConverter
6
+ UNITS = {
7
+ wei: 1,
8
+ kwei: 1000,
9
+ ada: 1000,
10
+ femtoether: 1000,
11
+ mwei: 1_000_000,
12
+ babbage: 1_000_000,
13
+ picoether: 1_000_000,
14
+ gwei: 1_000_000_000,
15
+ shannon: 1_000_000_000,
16
+ nanoether: 1_000_000_000,
17
+ nano: 1_000_000_000,
18
+ szabo: 1_000_000_000_000,
19
+ microether: 1_000_000_000_000,
20
+ micro: 1_000_000_000_000,
21
+ finney: 1_000_000_000_000_000,
22
+ milliether: 1_000_000_000_000_000,
23
+ milli: 1_000_000_000_000_000,
24
+ ether: 1_000_000_000_000_000_000,
25
+ eth: 1_000_000_000_000_000_000,
26
+ kether: 1_000_000_000_000_000_000_000,
27
+ grand: 1_000_000_000_000_000_000_000,
28
+ einstein: 1_000_000_000_000_000_000_000,
29
+ mether: 1_000_000_000_000_000_000_000_000,
30
+ gether: 1_000_000_000_000_000_000_000_000_000,
31
+ tether: 1_000_000_000_000_000_000_000_000_000_000
32
+ }.freeze
33
+
34
+ class << self
35
+ def convert(amount, unit = 'wei', to_unit = 'ether')
36
+ return nil if amount.nil?
37
+
38
+ return from_wei(amount, to_unit) if unit == 'wei'
39
+
40
+ from_wei(to_wei(amount, unit), to_unit)
41
+ end
42
+
43
+ def to_wei(amount, unit = 'ether')
44
+ return nil if amount.nil?
45
+
46
+ begin
47
+ BigDecimal(UNITS[unit.to_sym] * amount, 16).to_s.to_i
48
+ rescue StandardError => e
49
+ raise e.class
50
+ end
51
+ end
52
+
53
+ def from_wei(amount, unit = 'ether')
54
+ return nil if amount.nil?
55
+
56
+ begin
57
+ (BigDecimal(amount, 16) / BigDecimal(UNITS[unit.to_sym], 16)).to_s
58
+ rescue StandardError => e
59
+ raise e.class
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,7 @@
1
+ module EthereumUnitConverter
2
+ VERSION: String
3
+ UNITS: String
4
+ def self.convert(Integer, String, String) -> String
5
+ def self.to_wei(Integer, String) -> Integer
6
+ def self.from_wei(Integer, String) -> String
7
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ethereum_unit_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Serigne Mouhamadou Bassirou Diaby
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bigdecimal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description:
28
+ email:
29
+ - bayevels@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - bin/console
40
+ - bin/setup
41
+ - lib/ethereum_unit_converter.rb
42
+ - lib/ethereum_unit_converter/version.rb
43
+ - sig/ethereum_unit_converter.rbs
44
+ homepage: https://github.com/bayevels/ethereum_unit_converter
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ homepage_uri: https://github.com/bayevels/ethereum_unit_converter
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.5.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.2.3
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Ethereum unit converter in Ruby
68
+ test_files: []