harmony-api 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: 9f802fc746ca9e06a454516cfb0de620e31ea2fc7b368a1d144878a60999b3cb
4
+ data.tar.gz: 2fe419ae08fbd042cd60c85a11516e4cb6ab0ff1caf86b828a270e0b7713452c
5
+ SHA512:
6
+ metadata.gz: 0337d77e4937b5e604d773cc6c8a87f523cf8144101350d273be96802da9812b319a8a49507813a1ef84cf6bd5627d048050b428b3e40bd47aa47fdb5aa06046
7
+ data.tar.gz: e2bd366424b7050130c8c6036a0cb104026a07f12b741dcbf6609c9a51d3bb0b25139645466da48a86d0a13559f8f0e0c41e04c7c4a4162a2c637b5795739182
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.1
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,7 @@
1
+ {
2
+ "recommendations": [
3
+ "kaiwood.endwise",
4
+ "ninoseki.vscode-gem-lens",
5
+ "castwide.solargraph"
6
+ ]
7
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "files.associations": {
3
+ "*.html.erb": "html"
4
+ },
5
+ "[html]": {
6
+ "editor.defaultFormatter": "vscode.html-language-features"
7
+ },
8
+ "editor.formatOnSave": true,
9
+ "solargraph.autoformat": true,
10
+ "solargraph.diagnostics": true,
11
+ "solargraph.formatting": true,
12
+ "editor.tabSize": 2
13
+ }
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sebastian.johnsson@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in harmony-api.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ harmony-api (0.1.0)
5
+ faraday
6
+ faraday_middleware
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.0)
12
+ backport (1.1.2)
13
+ benchmark (0.1.0)
14
+ coderay (1.1.2)
15
+ diff-lcs (1.3)
16
+ e2mmap (0.1.0)
17
+ faraday (1.0.1)
18
+ multipart-post (>= 1.2, < 3)
19
+ faraday_middleware (1.0.0)
20
+ faraday (~> 1.0)
21
+ jaro_winkler (1.5.4)
22
+ maruku (0.7.3)
23
+ method_source (1.0.0)
24
+ mini_portile2 (2.4.0)
25
+ multipart-post (2.1.1)
26
+ nokogiri (1.10.9)
27
+ mini_portile2 (~> 2.4.0)
28
+ parallel (1.19.1)
29
+ parser (2.7.1.2)
30
+ ast (~> 2.4.0)
31
+ pry (0.13.1)
32
+ coderay (~> 1.1)
33
+ method_source (~> 1.0)
34
+ rainbow (3.0.0)
35
+ rake (12.3.3)
36
+ reverse_markdown (1.4.0)
37
+ nokogiri
38
+ rexml (3.2.4)
39
+ rspec (3.9.0)
40
+ rspec-core (~> 3.9.0)
41
+ rspec-expectations (~> 3.9.0)
42
+ rspec-mocks (~> 3.9.0)
43
+ rspec-core (3.9.2)
44
+ rspec-support (~> 3.9.3)
45
+ rspec-expectations (3.9.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.9.0)
48
+ rspec-mocks (3.9.1)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.9.0)
51
+ rspec-support (3.9.3)
52
+ rubocop (0.82.0)
53
+ jaro_winkler (~> 1.5.1)
54
+ parallel (~> 1.10)
55
+ parser (>= 2.7.0.1)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ rexml
58
+ ruby-progressbar (~> 1.7)
59
+ unicode-display_width (>= 1.4.0, < 2.0)
60
+ ruby-progressbar (1.10.1)
61
+ solargraph (0.39.7)
62
+ backport (~> 1.1)
63
+ benchmark
64
+ bundler (>= 1.17.2)
65
+ e2mmap
66
+ jaro_winkler (~> 1.5)
67
+ maruku (~> 0.7, >= 0.7.3)
68
+ nokogiri (~> 1.9, >= 1.9.1)
69
+ parser (~> 2.3)
70
+ reverse_markdown (~> 1.0, >= 1.0.5)
71
+ rubocop (~> 0.52)
72
+ thor (~> 1.0)
73
+ tilt (~> 2.0)
74
+ yard (~> 0.9, >= 0.9.24)
75
+ thor (1.0.1)
76
+ tilt (2.0.10)
77
+ unicode-display_width (1.7.0)
78
+ yard (0.9.25)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ harmony-api!
85
+ pry
86
+ rake (~> 12.0)
87
+ rspec (~> 3.0)
88
+ solargraph
89
+
90
+ BUNDLED WITH
91
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Sebastian Johnsson
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,45 @@
1
+ # Harmony::Api
2
+
3
+ A Ruby client for interacting with [Harmony's](https://harmony.one) blockchain.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'harmony-api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install harmony-api
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ client = Harmony::Api::V1::Client.new(network: :os, shard: 0)
25
+ client.get_all_validator_information
26
+ ```
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SebastianJ/harmony-api. 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/SebastianJ/harmony-api/blob/master/CODE_OF_CONDUCT.md).
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the Harmony::Api project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SebastianJ/harmony-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
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 'harmony/api'
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,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/harmony/api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'harmony-api'
7
+ spec.version = Harmony::Api::VERSION
8
+ spec.authors = ['Sebastian Johnsson']
9
+ spec.email = ['sebastian.johnsson@gmail.com']
10
+
11
+ spec.summary = 'Harmony Ruby API Client'
12
+ spec.description = 'Harmony Ruby API Client'
13
+ spec.homepage = 'https://github.com/SebastianJ/harmony-ruby-api'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/SebastianJ/harmony-ruby-api'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/SebastianJ/harmony-ruby-api/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'faraday'
31
+ spec.add_dependency 'faraday_middleware'
32
+
33
+ spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'solargraph'
35
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+
6
+ require 'harmony/api/version'
7
+ require 'harmony/api/configuration'
8
+
9
+ require 'harmony/api/utilities'
10
+
11
+ require 'harmony/api/client'
12
+
13
+ require 'harmony/api/v1/blockchain/protocol'
14
+ require 'harmony/api/v1/blockchain/block'
15
+ require 'harmony/api/v1/accounts/account'
16
+ require 'harmony/api/v1/misc/utility'
17
+ require 'harmony/api/v1/transactions/transaction'
18
+ require 'harmony/api/v1/transactions/error'
19
+ require 'harmony/api/v1/staking/validator'
20
+ require 'harmony/api/v1/staking/delegator'
21
+ require 'harmony/api/v1/staking/utility'
22
+ require 'harmony/api/v1/staking/error'
23
+ require 'harmony/api/v1/contracts/contract'
24
+ require 'harmony/api/v1/filters/filter'
25
+ require 'harmony/api/v1/logs/log'
26
+ require 'harmony/api/v1/client'
27
+
28
+ module Harmony
29
+ module Api
30
+ class << self
31
+ attr_writer :configuration
32
+
33
+ def configuration
34
+ @configuration ||= ::Harmony::Api::Configuration.new
35
+ end
36
+
37
+ def reset
38
+ @configuration = ::Harmony::Api::Configuration.new
39
+ end
40
+
41
+ def configure
42
+ yield(configuration)
43
+ end
44
+ end
45
+
46
+ class Error < StandardError; end
47
+ end
48
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ class Client
6
+ attr_accessor :url, :payload, :configuration, :connection, :headers, :api_version
7
+
8
+ def initialize(network: :os, shard: 0, configuration: ::Harmony::Api.configuration, options: {})
9
+ self.configuration = configuration
10
+
11
+ set_url(network, shard)
12
+ set_defaults
13
+ set_connection
14
+ end
15
+
16
+ def set_url(network, shard)
17
+ self.url = configuration.networks[network][:url] % shard
18
+ end
19
+
20
+ def set_defaults
21
+ self.payload = {
22
+ jsonrpc: '2.0',
23
+ id: 1
24
+ }
25
+ end
26
+
27
+ def set_connection
28
+ self.connection = ::Faraday.new(url) do |builder|
29
+ if configuration.faraday.fetch(:timeout, nil)
30
+ builder.options[:timeout] = configuration.faraday.fetch(:timeout, nil)
31
+ end
32
+ if configuration.faraday.fetch(:open_timeout, nil)
33
+ builder.options[:open_timeout] = configuration.faraday.fetch(:open_timeout, nil)
34
+ end
35
+
36
+ builder.headers = headers if headers && !headers.empty?
37
+
38
+ builder.request :json
39
+
40
+ if configuration.verbose
41
+ builder.response :logger, ::Logger.new(STDOUT), bodies: true
42
+ end
43
+ builder.response :json, content_type: /\bjson$/
44
+
45
+ builder.use ::FaradayMiddleware::FollowRedirects, limit: 10
46
+
47
+ builder.adapter configuration.faraday.fetch(:adapter, ::Faraday.default_adapter)
48
+ end
49
+ end
50
+
51
+ def post(method, params: [])
52
+ versioned_method = api_version.eql?(1) ? "hmy_#{method}" : "hmyv#{version}_#{method}"
53
+
54
+ data = payload.merge(
55
+ method: versioned_method,
56
+ params: params
57
+ )
58
+
59
+ response = connection.post do |request|
60
+ if headers && !headers.empty?
61
+ request.headers = connection.headers.merge(headers)
62
+ end
63
+ request.body = data if data && !data.empty?
64
+ end
65
+ end
66
+
67
+ def response(resp)
68
+ resp = resp&.body
69
+
70
+ error = resp&.fetch('error', {})
71
+ unless error.empty?
72
+ raise ::Harmony::Api::Error, "#{error.fetch('message', '')} (#{error.fetch('code', -1)})"
73
+ end
74
+
75
+ resp&.fetch('result')
76
+ end
77
+
78
+ def log(tag = self.class.name, message)
79
+ puts "[#{tag}] - #{Time.now}: #{message}" if configuration.verbose
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ class Configuration
6
+ attr_accessor :networks, :faraday, :verbose
7
+
8
+ def initialize
9
+ self.networks = {
10
+ mainnet: {
11
+ shards: 4,
12
+ url: 'https://api.s%d.t.hmny.io'
13
+ },
14
+ testnet: {
15
+ shards: 3,
16
+ url: 'https://api.s%d.lrtn.hmny.io'
17
+ },
18
+ tnet: {
19
+ shards: 2,
20
+ url: 'https://api.s%d.tn.hmny.io'
21
+ },
22
+ os: {
23
+ shards: 4,
24
+ url: 'https://api.s%d.os.hmny.io'
25
+ },
26
+ ps: {
27
+ shards: 2,
28
+ url: 'https://api.s%d.ps.hmny.io'
29
+ },
30
+ stn: {
31
+ shards: 2,
32
+ url: 'https://api.s%d.stn.hmny.io'
33
+ },
34
+ pga: {
35
+ shards: 2,
36
+ url: 'https://api.s%d.pga.hmny.io'
37
+ }
38
+ }
39
+
40
+ self.faraday = {
41
+ adapter: :net_http,
42
+ timeout: 120,
43
+ open_timeout: 60
44
+ }
45
+
46
+ self.verbose = false
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ class Utilities
6
+ class << self
7
+ def hex_to_int(string)
8
+ string.to_i(16)
9
+ end
10
+
11
+ def int_to_hex(int)
12
+ "0x#{int.to_s(16)}"
13
+ end
14
+
15
+ def wei_to_ether(wei)
16
+ 1.0 * wei / 10**18
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Accounts
7
+ module Account
8
+ def get_balance(address)
9
+ params = [address, 'latest']
10
+ wei = response(post('getBalance', params: params))&.to_i(16)
11
+ Harmony::Api::Utilities.wei_to_ether(wei)
12
+ end
13
+
14
+ def get_balance_by_block_number(address, block_number)
15
+ params = [address, Harmony::Api::Utilities.int_to_hex(block_number)]
16
+ wei = response(post('getBalanceByBlockNumber', params: params))&.to_i(16)
17
+ Harmony::Api::Utilities.wei_to_ether(wei)
18
+ end
19
+
20
+ def get_transaction_count(address)
21
+ params = [address, 'latest']
22
+ response(post('getTransactionCount', params: params))&.to_i(16)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Blockchain
7
+ module Block
8
+ def get_block_by_number(block_number, full_txs: false)
9
+ params = [Harmony::Api::Utilities.int_to_hex(block_number), full_txs]
10
+ response(post('getBlockByNumber', params: params))
11
+ end
12
+
13
+ def get_block_by_hash(block_hash, full_txs: false)
14
+ params = [block_hash, full_txs]
15
+ response(post('getBlockByHash', params: params))
16
+ end
17
+
18
+ def get_blocks(start_block, end_block, with_signers: true, full_txs: false)
19
+ params = [
20
+ Harmony::Api::Utilities.int_to_hex(start_block),
21
+ Harmony::Api::Utilities.int_to_hex(end_block),
22
+ {
23
+ 'withSigners' => with_signers,
24
+ 'fullTx' => full_txs
25
+ }
26
+ ]
27
+
28
+ response(post('getBlocks', params: params))
29
+ end
30
+
31
+ def get_block_transaction_count_by_hash(block_hash)
32
+ response(post('getBlockTransactionCountByHash', params: [block_hash]))&.to_i(16)
33
+ end
34
+
35
+ def get_block_transaction_count_by_number(block_number)
36
+ params = [Harmony::Api::Utilities.int_to_hex(block_number)]
37
+ response(post('getBlockTransactionCountByNumber', params: params))&.to_i(16)
38
+ end
39
+
40
+ def latest_header
41
+ response(post('latestHeader'))
42
+ end
43
+
44
+ def block_number
45
+ response(post('blockNumber'))&.to_i(16)
46
+ end
47
+
48
+ def get_block_signers(block_number:)
49
+ params = [Harmony::Api::Utilities.int_to_hex(block_number)]
50
+ response(post('getBlockSigners', params: params))
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Blockchain
7
+ module Protocol
8
+ def protocol_version
9
+ response(post('protocolVersion'))&.to_i(16)
10
+ end
11
+
12
+ def get_sharding_structure
13
+ response(post('getShardingStructure'))
14
+ end
15
+
16
+ def get_leader
17
+ response(post('getLeader'))
18
+ end
19
+
20
+ def get_epoch
21
+ response(post('getEpoch'))&.to_i(16)
22
+ end
23
+
24
+ def gas_price
25
+ response(post('gasPrice'))&.to_i(16)
26
+ end
27
+
28
+ def get_node_metadata
29
+ response(post('getNodeMetadata'))
30
+ end
31
+
32
+ def syncing
33
+ response(post('syncing'))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ class Client < ::Harmony::Api::Client
7
+ def initialize(network: :os, shard: 0, configuration: ::Harmony::Api.configuration, options: {})
8
+ self.api_version = 1
9
+ super
10
+ end
11
+
12
+ include ::Harmony::Api::V1::Blockchain::Protocol
13
+ include ::Harmony::Api::V1::Blockchain::Block
14
+ include ::Harmony::Api::V1::Accounts::Account
15
+ include ::Harmony::Api::V1::Misc::Utility
16
+ include ::Harmony::Api::V1::Transactions::Transaction
17
+ include ::Harmony::Api::V1::Transactions::Error
18
+ include ::Harmony::Api::V1::Staking::Validator
19
+ include ::Harmony::Api::V1::Staking::Delegator
20
+ include ::Harmony::Api::V1::Staking::Utility
21
+ include ::Harmony::Api::V1::Staking::Error
22
+ include ::Harmony::Api::V1::Contracts::Contract
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Contracts
7
+ module Contract
8
+ def estimate_gas
9
+ response(post('estimateGas'))
10
+ end
11
+
12
+ # get storage position at a given address
13
+ def get_storage_at(address, key, block_number)
14
+ params = [address, key, Harmony::Api::Utilities.int_to_hex(block_number)]
15
+ response(post('getStorageAt', params: params))
16
+ end
17
+
18
+ # call contract method
19
+ def call(address)
20
+ params = [{ to: address }, 'latest']
21
+ response(post('hmy_call', params: params))
22
+ end
23
+
24
+ # get deployed contract's byte code
25
+ def get_code(address)
26
+ params = [address, 'latest']
27
+ response(post('hmy_getCode', params: params))
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module CrossSharding
7
+ module CrossShard
8
+ def get_cross_shard_transactions_history(address, page_index: 0, page_size: 1000, full_txs: false, tx_type: :all, order: :asc)
9
+ params = [
10
+ {
11
+ 'address' => address,
12
+ 'pageIndex' => page_index,
13
+ 'pageIndex' => page_size,
14
+ 'fullTx' => full_txs,
15
+ 'txType' => tx_type.to_s.upcase,
16
+ 'order' => order.to_s.upcase
17
+ }
18
+ ]
19
+ response(post('getCrossShardTransactionsHistory', params: params))
20
+ end
21
+
22
+ def get_pending_cx_receipts
23
+ response(post('hmy_getPendingCXReceipts'))
24
+ end
25
+
26
+ def get_cx_receipt_by_hash(hash)
27
+ response(post('hmy_getCXReceiptByHash', params: [hash]))
28
+ end
29
+
30
+ def resend_cx(hash)
31
+ response(post('hmy_resendCx', params: [hash]))
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Filters
7
+ module Filter
8
+ # get_filter_logs returns the logs for the filter with the given id.
9
+ # If the filter could not be found an empty array of logs is returned.
10
+ def get_filter_logs(filter_id)
11
+ params = [Harmony::Api::Utilities.int_to_hex(filter_id)]
12
+ response(post('hmy_getFilterLogs', params: params))
13
+ end
14
+
15
+ def get_filter_changes(filter_id)
16
+ params = [Harmony::Api::Utilities.int_to_hex(filter_id)]
17
+ response(post('hmy_getFilterChanges', params: params))
18
+ end
19
+
20
+ def new_filter(block_hash)
21
+ response(post('hmy_newFilter', params: [block_hash]))
22
+ end
23
+
24
+ def new_pending_transaction_filter(topics: [])
25
+ params = [{ topics: topics }]
26
+ response(post('hmy_newPendingTransactionFilter', params: params))
27
+ end
28
+
29
+ def new_block_filter(_block_hash)
30
+ response(post('hmy_newBlockFilter'))
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Logs
7
+ module Log
8
+ def get_logs(block_hash)
9
+ params = [{"BlockHash" => block_hash}]
10
+ response(post('hmy_getLogs', params: params))
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Misc
7
+ module Utility
8
+ def get_circulating_supply
9
+ response(post('getCirculatingSupply'))&.to_f
10
+ end
11
+
12
+ def get_total_supply
13
+ response(post('getTotalSupply'))&.to_f
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Staking
7
+ module Delegator
8
+ def get_delegations_by_delegator(address)
9
+ response(post('getDelegationsByDelegator', params: [address]))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Staking
7
+ module Error
8
+ def get_current_staking_error_sink
9
+ response(post('getCurrentStakingErrorSink'))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Staking
7
+ module Transaction
8
+ def send_raw_staking_transaction(hash)
9
+ response(post('sendRawStakingTransaction', params: [hash]))
10
+ end
11
+
12
+ def send_raw_staking_transaction(hash)
13
+ response(post('getStakingTransactionByHash', params: [hash]))
14
+ end
15
+
16
+ def get_staking_transaction_by_block_number_and_index(block_number, index)
17
+ params = [Harmony::Api::Utilities.int_to_hex(block_number), Harmony::Api::Utilities.int_to_hex(index)]
18
+ response(post('hmy_getStakingTransactionByBlockNumberAndIndex', params: params))
19
+ end
20
+
21
+ def get_staking_transaction_by_block_hash_and_index(hash, index)
22
+ params = [hash, Harmony::Api::Utilities.int_to_hex(index)]
23
+ response(post('getStakingTransactionByBlockHashAndIndex', params: params))
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Staking
7
+ module Utility
8
+ def get_current_utility_metrics
9
+ response(post('getCurrentUtilityMetrics'))
10
+ end
11
+
12
+ def get_super_committees
13
+ response(post('getSuperCommittees'))
14
+ end
15
+
16
+ def get_staking_network_info
17
+ response(post('hmy_getStakingNetworkInfo'))
18
+ end
19
+
20
+ def get_median_raw_stake_snapshot
21
+ response(post('getMedianRawStakeSnapshot'))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Staking
7
+ module Validator
8
+ def get_validators(epoch)
9
+ response(post('getValidators', params: [epoch]))
10
+ end
11
+
12
+ def get_all_validator_addresses
13
+ response(post('getAllValidatorAddresses'))
14
+ end
15
+
16
+ def get_elected_validator_addresses
17
+ response(post('getElectedValidatorAddresses'))
18
+ end
19
+
20
+ def get_validator_information(address)
21
+ response(post('getValidatorInformation', params: [address]))
22
+ end
23
+
24
+ def get_all_validator_information(page: -1)
25
+ response(post('getAllValidatorInformation', params: [page]))
26
+ end
27
+
28
+ def get_all_validator_information_by_block_number(page: -1, block_number: 0)
29
+ params = [page, Harmony::Api::Utilities.int_to_hex(block_number)]
30
+ response(post('getAllValidatorInformationByBlockNumber', params: params))
31
+ end
32
+
33
+ def is_block_signer(address, block_number: 0)
34
+ params = [Harmony::Api::Utilities.int_to_hex(block_number), address]
35
+ response(post('isBlockSigner', params: params))
36
+ end
37
+
38
+ def get_delegations_by_validator(address)
39
+ response(post('getDelegationsByValidator', params: [address]))
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Transactions
7
+ module Error
8
+ def getCurrentTransactionErrorSink
9
+ response(post('hmy_getCurrentTransactionErrorSink'))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harmony
4
+ module Api
5
+ module V1
6
+ module Transactions
7
+ module Transaction
8
+ def get_send_raw_transaction(hash)
9
+ response(post('getBalance', params: [hash]))
10
+ end
11
+
12
+ def get_transaction_by_hash(hash)
13
+ response(post('getTransactionByHash', params: [hash]))
14
+ end
15
+
16
+ def get_transaction_receipt(hash)
17
+ response(post('getTransactionReceipt', params: [hash]))
18
+ end
19
+
20
+ def get_transaction_by_block_number_and_index(block_number, index)
21
+ params = [Harmony::Api::Utilities.int_to_hex(block_number), Harmony::Api::Utilities.int_to_hex(index)]
22
+ response(post('getTransactionByBlockNumberAndIndex', params: params))
23
+ end
24
+
25
+ def get_transaction_by_block_hash_and_index(hash, index)
26
+ params = [hash, Harmony::Api::Utilities.int_to_hex(index)]
27
+ response(post('getTransactionByBlockHashAndIndex', params: params))
28
+ end
29
+
30
+ def pending_transactions
31
+ response(post('getTransactionByBlockHashAndIndex'))
32
+ end
33
+
34
+ def get_transactions_history(address, page_index: 0, page_size: 1000, full_txs: false, tx_type: :all, order: :asc)
35
+ params = [
36
+ {
37
+ 'address' => address,
38
+ 'pageIndex' => page_index,
39
+ 'pageIndex' => page_size,
40
+ 'fullTx' => full_txs,
41
+ 'txType' => tx_type.to_s.upcase,
42
+ 'order' => order.to_s.upcase
43
+ }
44
+ ]
45
+ response(post('getTransactionsHistory', params: params))
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module Harmony
2
+ module Api
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harmony-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Johnsson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: solargraph
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Harmony Ruby API Client
70
+ email:
71
+ - sebastian.johnsson@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-version"
79
+ - ".travis.yml"
80
+ - ".vscode/extensions.json"
81
+ - ".vscode/settings.json"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - harmony-api.gemspec
91
+ - lib/harmony/api.rb
92
+ - lib/harmony/api/client.rb
93
+ - lib/harmony/api/configuration.rb
94
+ - lib/harmony/api/utilities.rb
95
+ - lib/harmony/api/v1/accounts/account.rb
96
+ - lib/harmony/api/v1/blockchain/block.rb
97
+ - lib/harmony/api/v1/blockchain/protocol.rb
98
+ - lib/harmony/api/v1/client.rb
99
+ - lib/harmony/api/v1/contracts/contract.rb
100
+ - lib/harmony/api/v1/cross_sharding/cross_shard.rb
101
+ - lib/harmony/api/v1/filters/filter.rb
102
+ - lib/harmony/api/v1/logs/log.rb
103
+ - lib/harmony/api/v1/misc/utility.rb
104
+ - lib/harmony/api/v1/staking/delegator.rb
105
+ - lib/harmony/api/v1/staking/error.rb
106
+ - lib/harmony/api/v1/staking/transaction.rb
107
+ - lib/harmony/api/v1/staking/utility.rb
108
+ - lib/harmony/api/v1/staking/validator.rb
109
+ - lib/harmony/api/v1/transactions/error.rb
110
+ - lib/harmony/api/v1/transactions/transaction.rb
111
+ - lib/harmony/api/version.rb
112
+ homepage: https://github.com/SebastianJ/harmony-ruby-api
113
+ licenses:
114
+ - MIT
115
+ metadata:
116
+ homepage_uri: https://github.com/SebastianJ/harmony-ruby-api
117
+ source_code_uri: https://github.com/SebastianJ/harmony-ruby-api
118
+ changelog_uri: https://github.com/SebastianJ/harmony-ruby-api/CHANGELOG.md
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 2.3.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubygems_version: 3.1.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Harmony Ruby API Client
138
+ test_files: []