atm-eth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ee3c37e6159c054c53402da9fb646c8222df93694aa62389eebd14cf9949b83
4
+ data.tar.gz: 12b97a508a668896438147e0c9aef84b8423ef8fcd6b3acf1db03b1cc5f3e5ec
5
+ SHA512:
6
+ metadata.gz: 044e4e3f22b9a7997a9408ec18735c0066a819cf3c83e5a99928d298d5902dc605f55a5704b12d2b420476665114670e52a50155843cdeb8a3138fff9e99f15a
7
+ data.tar.gz: 33cda4d1fc84d32c22fc3ef932f370100dc3f76e7c6c8710642b336cae7cfdd56dcd3ffed958eae43137ad0176df7aae11544c4d840370180ef6b4a0e2337739
data/.DS_Store ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-08-11
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at kenzo.tominaga@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 @kentomi
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Kenzo
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,58 @@
1
+ # Atm::Eth
2
+
3
+ ATM-Eth is a Ruby gem that provides a simplified interface for interacting with the Ethereum blockchain. With ATM-Eth, you can easily generate wallets, send transactions, check balances, and monitor transaction statuses on the Ethereum network. This gem abstracts complex Ethereum operations, allowing you to focus on building Ethereum-powered applications without the hassle of low-level details.
4
+
5
+ ## Installation
6
+
7
+ If bundler is not being used to manage dependencies, install the gem by executing:
8
+
9
+ $ gem install atm-eth-0.1.0.gem
10
+
11
+ ## Usage
12
+
13
+ $ bundle exec rails console
14
+
15
+ require 'atm/eth'
16
+
17
+ # Initialize the Ethereum instance
18
+ ethereum = AtmEth::Ethereum.new('https://your-ethereum-provider-url.com')
19
+
20
+ # Generate a new wallet
21
+ wallet = ethereum.generate_wallet
22
+ puts "Generated Wallet:"
23
+ puts "Address: #{wallet[:address]}"
24
+ puts "Private Key: #{wallet[:private_key]}"
25
+
26
+ # Get balance of an Ethereum address
27
+ address = '0xYourEthereumAddress'
28
+ balance = ethereum.get_balance(address)
29
+ puts "Balance of #{address}: #{balance} ETH"
30
+
31
+ # Send transaction from wallet
32
+ sender_wallet = ethereum.generate_wallet
33
+ receiver_address = '0xReceiverAddress'
34
+ value_in_wei = 10000000000000000 # Value in wei (0.01 ETH)
35
+ transaction_hash = ethereum.send_transaction_from_wallet(sender_wallet, receiver_address, value_in_wei)
36
+ puts "Transaction Hash: #{transaction_hash}"
37
+
38
+ # Get transaction status
39
+ status = ethereum.get_transaction_status(transaction_hash)
40
+ puts "Transaction Status: #{status}"
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ 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).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/atm-eth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/atm-eth/blob/master/CODE_OF_CONDUCT.md).
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
55
+
56
+ ## Code of Conduct
57
+
58
+ Everyone interacting in the Atm::Eth project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tominugen/atm-eth/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/atm-eth.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # atm-eth.gemspec
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "lib/atm/eth/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "atm-eth"
8
+ spec.version = Atm::Eth::VERSION
9
+ spec.authors = ["Kenzo"]
10
+ spec.email = ["kenzo.tominaga@gmail.com"]
11
+
12
+ spec.summary = "Ruby gem for interacting with Ethereum blockchain."
13
+ spec.description = "Simplify Ethereum interactions with this gem."
14
+ spec.homepage = "https://github.com/tominugen/atm-eth"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 3.1.4"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/tominugen/atm-eth"
20
+ spec.metadata["changelog_uri"] = "https://github.com/tominugen/atm-eth/blob/main/CHANGELOG.md"
21
+
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
26
+ end
27
+ end
28
+
29
+ spec.files += Dir.glob("lib/**/*.rb")
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_runtime_dependency 'rails', '~> 7.0.5'
35
+ spec.add_runtime_dependency "json", "~> 2.5"
36
+ spec.add_runtime_dependency "openssl", "3.1.0"
37
+ spec.add_runtime_dependency "digest", "~> 1.0"
38
+ spec.add_runtime_dependency 'digest-keccak'
39
+ spec.add_runtime_dependency "rubygems"
40
+ end
@@ -0,0 +1,101 @@
1
+ # lib/atm/eth/ethereum.rb
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'openssl'
5
+ require 'digest'
6
+ require 'digest/keccak'
7
+
8
+ module AtmEth
9
+ class Ethereum
10
+ def initialize(provider_url)
11
+ @provider_url = provider_url
12
+ end
13
+
14
+ def generate_wallet
15
+ key = SecureRandom.hex(32)
16
+ private_key = "0x#{key}"
17
+ address = generate_address_from_private_key(private_key)
18
+
19
+ { address: address, private_key: private_key }
20
+ end
21
+
22
+ def send_transaction_from_wallet(wallet, to, value_in_wei)
23
+ nonce = get_nonce(wallet[:address])
24
+ gas_price = estimate_gas_price
25
+
26
+ transaction_data = {
27
+ nonce: nonce,
28
+ gasPrice: gas_price,
29
+ gasLimit: '0x5208',
30
+ to: to,
31
+ value: value_in_wei,
32
+ data: ''
33
+ }
34
+
35
+ signed_transaction = sign_transaction(transaction_data, wallet[:private_key])
36
+
37
+ send_raw_transaction(signed_transaction)
38
+ end
39
+
40
+ def get_balance(address)
41
+ uri = URI("#{@provider_url}?module=account&action=balance&address=#{address}&tag=latest")
42
+ response = Net::HTTP.get(uri)
43
+ balance_wei = JSON.parse(response)['result']
44
+ wei_to_ether(balance_wei)
45
+ end
46
+
47
+ def get_transaction_status(tx_hash)
48
+ uri = URI("#{@provider_url}?module=proxy&action=eth_getTransactionReceipt&txhash=#{tx_hash}")
49
+ response = Net::HTTP.get(uri)
50
+ receipt = JSON.parse(response)['result']
51
+
52
+ if receipt.nil?
53
+ 'Pending'
54
+ else
55
+ receipt['status'] == '0x1' ? 'Successful' : 'Failed'
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def generate_address_from_private_key(private_key)
62
+ require 'openssl'
63
+ private_key = private_key.sub(/^0x/, '') # remove "0x"
64
+ private_key_bn = OpenSSL::BN.new(private_key, 16)
65
+
66
+ group = OpenSSL::PKey::EC::Group.new('secp256k1')
67
+ point = group.generator.mul(private_key_bn)
68
+ x_bn = point.to_bn
69
+ y_bn = point.to_bn
70
+
71
+ public_key_hex = '04' + x_bn.to_s(16) + y_bn.to_s(16)
72
+
73
+ keccak_hash = Digest::Keccak.new
74
+ keccak_hash.update([public_key_hex].pack('H*'))
75
+ hashed_public_key = keccak_hash.hexdigest[24..-1]
76
+
77
+ '0x' + hashed_public_key
78
+ end
79
+
80
+ def wei_to_ether(wei)
81
+ wei.to_f / 1_000_000_000_000_000_000
82
+ end
83
+
84
+ def sign_transaction(transaction_data, private_key)
85
+ key = OpenSSL::PKey::EC.new('secp256k1')
86
+ key.private_key = OpenSSL::BN.new(private_key, 16)
87
+ signature = key.dsa_sign_asn1(Digest::SHA3.hexdigest(transaction_data.to_json))
88
+
89
+ r, s = signature.unpack('H64H64')
90
+ v = key.dsa_verify_asn1(Digest::SHA3.hexdigest(transaction_data.to_json), signature) + 27
91
+
92
+ {
93
+ r: "0x#{r}",
94
+ s: "0x#{s}",
95
+ v: v
96
+ }
97
+ end
98
+
99
+ end
100
+ end
101
+
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Atm
4
+ module Eth
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/atm/eth.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "eth/version"
4
+ require_relative "eth/ethereum"
5
+
6
+ module Atm
7
+ module Eth
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
11
+ end
data/sig/atm/eth.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module Atm
2
+ module Eth
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atm-eth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenzo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: openssl
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: digest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: digest-keccak
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubygems
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Simplify Ethereum interactions with this gem.
98
+ email:
99
+ - kenzo.tominaga@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".DS_Store"
105
+ - CHANGELOG.md
106
+ - CODE_OF_CONDUCT.md
107
+ - LICENSE
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - atm-eth.gemspec
112
+ - lib/atm/eth.rb
113
+ - lib/atm/eth/ethereum.rb
114
+ - lib/atm/eth/version.rb
115
+ - sig/atm/eth.rbs
116
+ homepage: https://github.com/tominugen/atm-eth
117
+ licenses:
118
+ - MIT
119
+ metadata:
120
+ homepage_uri: https://github.com/tominugen/atm-eth
121
+ source_code_uri: https://github.com/tominugen/atm-eth
122
+ changelog_uri: https://github.com/tominugen/atm-eth/blob/main/CHANGELOG.md
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 3.1.4
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.0.3.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Ruby gem for interacting with Ethereum blockchain.
142
+ test_files: []