elrond-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/addresses +24 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/elrond-api.gemspec +34 -0
- data/lib/elrond/api.rb +39 -0
- data/lib/elrond/api/configuration.rb +29 -0
- data/lib/elrond/api/node/client.rb +110 -0
- data/lib/elrond/api/node/endpoints/address.rb +19 -0
- data/lib/elrond/api/node/endpoints/nodes.rb +41 -0
- data/lib/elrond/api/version.rb +5 -0
- data/lib/elrond/api/wallet/client.rb +103 -0
- data/lib/elrond/api/wallet/endpoints/address.rb +31 -0
- data/lib/elrond/api/wallet/endpoints/transactions.rb +15 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f1cac7303b047b3d73d0557081185a43a0996513b07c958b198fe71ae158d54
|
4
|
+
data.tar.gz: c44bc63fa04a38374c9398a49121e1dd016162d2b68f682927005b03b2393ce5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c79d7e1a0ca12359f8f6a4f5e4cd3dbd2ea230826a65a4d56295f47f81dc269b6d3e0006ac11e04d70dd606aa39c1d7d0f43b958b522cb015aa26370ea01dd9
|
7
|
+
data.tar.gz: 1e147588274045a042c604f5a3ff6f41a2620153784a92c7bc4c8aa86403dff457c6ebd63eb1d096dd90467c4b79cd721e7f30ae4726e96f352dc5b69bb97a5a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
elrond-api (0.1.1)
|
5
|
+
faraday (~> 1.0, >= 1.0.1)
|
6
|
+
faraday_middleware (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
faraday (1.0.1)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
faraday_middleware (1.0.0)
|
16
|
+
faraday (~> 1.0)
|
17
|
+
method_source (1.0.0)
|
18
|
+
multipart-post (2.1.1)
|
19
|
+
pry (0.13.1)
|
20
|
+
coderay (~> 1.1)
|
21
|
+
method_source (~> 1.0)
|
22
|
+
rake (13.0.1)
|
23
|
+
rspec (3.9.0)
|
24
|
+
rspec-core (~> 3.9.0)
|
25
|
+
rspec-expectations (~> 3.9.0)
|
26
|
+
rspec-mocks (~> 3.9.0)
|
27
|
+
rspec-core (3.9.2)
|
28
|
+
rspec-support (~> 3.9.3)
|
29
|
+
rspec-expectations (3.9.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-mocks (3.9.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-support (3.9.3)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler (~> 2.1, >= 2.1.4)
|
42
|
+
elrond-api!
|
43
|
+
pry (~> 0.13.1)
|
44
|
+
rake (~> 13.0, >= 13.0.1)
|
45
|
+
rspec (~> 3.9)
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 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,41 @@
|
|
1
|
+
# Elrond::Api
|
2
|
+
|
3
|
+
Ruby client to interact with Elrond's node REST API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'elrond-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install elrond-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
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.
|
28
|
+
|
29
|
+
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).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SebastianJ/elrond-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the Elrond::Api project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SebastianJ/elrond-api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/addresses
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "elrond/api"
|
5
|
+
|
6
|
+
addresses = File.readlines(File.join(File.dirname(__FILE__), "../data/addresses.txt")).collect(&:strip).uniq
|
7
|
+
|
8
|
+
client = Elrond::Api::Wallet::Client.new
|
9
|
+
data = {}
|
10
|
+
sum = 0
|
11
|
+
|
12
|
+
addresses.each do |address|
|
13
|
+
result = client.address(address)
|
14
|
+
sum += result[:balance]
|
15
|
+
data[result[:address]] = result[:balance]
|
16
|
+
|
17
|
+
puts "Address #{result[:address]} has a balance of #{result[:balance]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "\nTotal balance in all wallets: #{sum}"
|
21
|
+
|
22
|
+
data.each do |address, balance|
|
23
|
+
puts "Address #{address} has a balance of #{balance}"
|
24
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "elrond/api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.config.history.file = File.join(__FILE__, "../.pry_history")
|
12
|
+
Pry.start
|
13
|
+
|
14
|
+
#require "irb"
|
15
|
+
#IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/elrond-api.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "elrond/api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "elrond-api"
|
8
|
+
spec.version = Elrond::Api::VERSION
|
9
|
+
spec.authors = ["Sebastian Johnsson"]
|
10
|
+
spec.email = ["sebastian.johnsson@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby client to interact with Elrond's REST API.}
|
13
|
+
spec.description = %q{Ruby client to interact with Elrond's REST API.}
|
14
|
+
spec.homepage = "https://github.com/SebastianJ/elrond-api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency 'faraday', '~> 1.0', '>= 1.0.1'
|
27
|
+
spec.add_dependency 'faraday_middleware', '~> 1.0'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'pry', '~> 0.13.1'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
|
32
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
34
|
+
end
|
data/lib/elrond/api.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
require "elrond/api/version"
|
7
|
+
require "elrond/api/configuration"
|
8
|
+
|
9
|
+
require "elrond/api/node/endpoints/nodes"
|
10
|
+
require "elrond/api/node/endpoints/address"
|
11
|
+
|
12
|
+
require "elrond/api/node/client"
|
13
|
+
|
14
|
+
require "elrond/api/wallet/endpoints/address"
|
15
|
+
require "elrond/api/wallet/endpoints/transactions"
|
16
|
+
require "elrond/api/wallet/client"
|
17
|
+
|
18
|
+
module Elrond
|
19
|
+
module Api
|
20
|
+
|
21
|
+
class << self
|
22
|
+
attr_writer :configuration
|
23
|
+
|
24
|
+
def configuration
|
25
|
+
@configuration ||= ::Elrond::Api::Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset
|
29
|
+
@configuration = ::Elrond::Api::Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure
|
33
|
+
yield(configuration)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Error < StandardError; end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Elrond
|
2
|
+
module Api
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :faraday, :verbose, :endpoints
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.endpoints = {
|
8
|
+
wallet: {
|
9
|
+
host: "https://api.elrond.com",
|
10
|
+
headers: {
|
11
|
+
"Host" => "wallet-api.elrond.com",
|
12
|
+
"origin" => "https://explorer.elrond.com",
|
13
|
+
"referer" => "https://explorer.elrond.com/"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
self.faraday = {
|
19
|
+
adapter: :net_http,
|
20
|
+
timeout: 120,
|
21
|
+
open_timeout: 60
|
22
|
+
}
|
23
|
+
|
24
|
+
self.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Elrond
|
2
|
+
module Api
|
3
|
+
module Node
|
4
|
+
|
5
|
+
class Client
|
6
|
+
attr_accessor :host, :port, :proxy, :user_agent, :configuration, :connection, :headers
|
7
|
+
|
8
|
+
def initialize(host:, port: 8080, proxy: nil, user_agent: "curl/7.58.0", configuration: ::Elrond::Api.configuration, options: {})
|
9
|
+
self.host = host
|
10
|
+
self.port = port
|
11
|
+
self.proxy = proxy
|
12
|
+
self.user_agent = user_agent
|
13
|
+
self.configuration = configuration
|
14
|
+
|
15
|
+
set_headers
|
16
|
+
set_connection
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_connection
|
20
|
+
self.connection = ::Faraday.new(url) do |builder|
|
21
|
+
builder.options[:timeout] = self.configuration.faraday.fetch(:timeout, nil) if self.configuration.faraday.fetch(:timeout, nil)
|
22
|
+
builder.options[:open_timeout] = self.configuration.faraday.fetch(:open_timeout, nil) if self.configuration.faraday.fetch(:open_timeout, nil)
|
23
|
+
|
24
|
+
builder.headers = self.headers if self.headers && !self.headers.empty?
|
25
|
+
|
26
|
+
builder.request :json
|
27
|
+
|
28
|
+
builder.response :logger, ::Logger.new(STDOUT), bodies: true if self.configuration.verbose
|
29
|
+
builder.response :json, content_type: /\bjson$/
|
30
|
+
|
31
|
+
builder.use ::FaradayMiddleware::FollowRedirects, limit: 10
|
32
|
+
|
33
|
+
if self.proxy
|
34
|
+
builder.proxy = self.proxy
|
35
|
+
log("Will use proxy: #{builder.proxy.inspect}")
|
36
|
+
end
|
37
|
+
|
38
|
+
builder.adapter self.configuration.faraday.fetch(:adapter, ::Faraday.default_adapter)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def url
|
43
|
+
"http://#{self.host}:#{self.port}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def get(path, parameters: {}, headers: {}, options: {})
|
47
|
+
request path, method: :get, parameters: parameters, headers: headers, options: options
|
48
|
+
end
|
49
|
+
|
50
|
+
def post(path, parameters: {}, data: {}, headers: {}, options: {})
|
51
|
+
request path, method: :post, parameters: parameters, data: data, headers: headers, options: options
|
52
|
+
end
|
53
|
+
|
54
|
+
def put(path, parameters: {}, data: {}, headers: {}, options: {})
|
55
|
+
request path, method: :put, parameters: parameters, data: data, headers: headers, options: options
|
56
|
+
end
|
57
|
+
|
58
|
+
def patch(path, parameters: {}, data: {}, headers: {}, options: {})
|
59
|
+
request path, method: :patch, parameters: parameters, data: data, headers: headers, options: options
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete(path, parameters: {}, data: {}, headers: {}, options: {})
|
63
|
+
request path, method: :delete, parameters: parameters, data: data, headers: headers, options: options
|
64
|
+
end
|
65
|
+
|
66
|
+
def request(path, method: :get, parameters: {}, data: {}, headers: {}, options: {}, retries: 3)
|
67
|
+
response = nil
|
68
|
+
|
69
|
+
response = case method
|
70
|
+
when :get
|
71
|
+
self.connection.get do |request|
|
72
|
+
request.url path
|
73
|
+
request.headers = self.connection.headers.merge(headers)
|
74
|
+
request.params = parameters if parameters && !parameters.empty?
|
75
|
+
end
|
76
|
+
when :head
|
77
|
+
self.connection.head do |request|
|
78
|
+
request.url path
|
79
|
+
request.headers = self.connection.headers.merge(headers)
|
80
|
+
request.params = parameters if parameters && !parameters.empty?
|
81
|
+
end
|
82
|
+
when :post, :put, :patch, :delete
|
83
|
+
self.connection.send(method) do |request|
|
84
|
+
request.url path
|
85
|
+
request.headers = self.connection.headers.merge(headers)
|
86
|
+
request.body = data if data && !data.empty?
|
87
|
+
request.params = parameters if parameters && !parameters.empty?
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
return response
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_headers
|
95
|
+
self.headers = {}
|
96
|
+
self.headers["User-Agent"] = self.user_agent unless self.user_agent.to_s.empty?
|
97
|
+
end
|
98
|
+
|
99
|
+
def log(tag = self.class.name, message)
|
100
|
+
puts "[#{tag}] - #{Time.now}: #{message}" if self.configuration.verbose
|
101
|
+
end
|
102
|
+
|
103
|
+
include ::Elrond::Api::Node::Endpoints::Nodes
|
104
|
+
include ::Elrond::Api::Node::Endpoints::Address
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Elrond
|
2
|
+
module Api
|
3
|
+
module Node
|
4
|
+
module Endpoints
|
5
|
+
module Address
|
6
|
+
|
7
|
+
def account(address, options: {})
|
8
|
+
get("/address/#{address}", options: options)&.body&.fetch("account", {})
|
9
|
+
end
|
10
|
+
|
11
|
+
def balance(address, options: {})
|
12
|
+
get("/address/#{address}/balance", options: options)&.body
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Elrond
|
2
|
+
module Api
|
3
|
+
module Node
|
4
|
+
module Endpoints
|
5
|
+
module Nodes
|
6
|
+
|
7
|
+
def address(options: {})
|
8
|
+
response = get("/node/address", options: options)&.body
|
9
|
+
response = response.fetch("address", nil) if response && response.is_a?(Hash)
|
10
|
+
end
|
11
|
+
|
12
|
+
def heartbeat(options: {})
|
13
|
+
response = get("/node/heartbeatstatus", options: options)&.body
|
14
|
+
response = response.fetch("message", []) if response && response.is_a?(Hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
def start(options: {})
|
18
|
+
response = get("/node/start", options: options)&.body
|
19
|
+
response = response.fetch("message", nil) if response && response.is_a?(Hash)
|
20
|
+
end
|
21
|
+
|
22
|
+
def statistics(options: {})
|
23
|
+
response = get("/node/statistics", options: options)&.body
|
24
|
+
response = response.fetch("statistics", {}) if response && response.is_a?(Hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
def status(options: {})
|
28
|
+
response = get("/node/status", options: options)&.body
|
29
|
+
response = response.fetch("details", {}) if response && response.is_a?(Hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stop(options: {})
|
33
|
+
response = get("/node/stop", options: options)&.body
|
34
|
+
response = response.fetch("message", nil) if response && response.is_a?(Hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Elrond
|
2
|
+
module Api
|
3
|
+
module Wallet
|
4
|
+
|
5
|
+
class Client
|
6
|
+
attr_accessor :proxy, :user_agent, :configuration, :connection, :headers
|
7
|
+
|
8
|
+
def initialize(proxy: nil, user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36", configuration: ::Elrond::Api.configuration, options: {})
|
9
|
+
self.proxy = proxy
|
10
|
+
self.user_agent = user_agent
|
11
|
+
self.configuration = configuration
|
12
|
+
|
13
|
+
set_headers
|
14
|
+
set_connection
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_connection
|
18
|
+
self.connection = ::Faraday.new(self.configuration.endpoints.dig(:wallet, :host)) do |builder|
|
19
|
+
builder.options[:timeout] = self.configuration.faraday.fetch(:timeout, nil) if self.configuration.faraday.fetch(:timeout, nil)
|
20
|
+
builder.options[:open_timeout] = self.configuration.faraday.fetch(:open_timeout, nil) if self.configuration.faraday.fetch(:open_timeout, nil)
|
21
|
+
|
22
|
+
builder.headers = self.headers if self.headers && !self.headers.empty?
|
23
|
+
|
24
|
+
builder.request :json
|
25
|
+
|
26
|
+
builder.response :logger, ::Logger.new(STDOUT), bodies: true if self.configuration.verbose
|
27
|
+
builder.response :json, content_type: /\bjson$/
|
28
|
+
|
29
|
+
builder.use ::FaradayMiddleware::FollowRedirects, limit: 10
|
30
|
+
|
31
|
+
if self.proxy
|
32
|
+
builder.proxy = self.proxy
|
33
|
+
log("Will use proxy: #{builder.proxy.inspect}")
|
34
|
+
end
|
35
|
+
|
36
|
+
builder.adapter self.configuration.faraday.fetch(:adapter, ::Faraday.default_adapter)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def get(path, parameters: {}, headers: {}, options: {})
|
41
|
+
request path, method: :get, parameters: parameters, headers: headers, options: options
|
42
|
+
end
|
43
|
+
|
44
|
+
def post(path, parameters: {}, data: {}, headers: {}, options: {})
|
45
|
+
request path, method: :post, parameters: parameters, data: data, headers: headers, options: options
|
46
|
+
end
|
47
|
+
|
48
|
+
def put(path, parameters: {}, data: {}, headers: {}, options: {})
|
49
|
+
request path, method: :put, parameters: parameters, data: data, headers: headers, options: options
|
50
|
+
end
|
51
|
+
|
52
|
+
def patch(path, parameters: {}, data: {}, headers: {}, options: {})
|
53
|
+
request path, method: :patch, parameters: parameters, data: data, headers: headers, options: options
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete(path, parameters: {}, data: {}, headers: {}, options: {})
|
57
|
+
request path, method: :delete, parameters: parameters, data: data, headers: headers, options: options
|
58
|
+
end
|
59
|
+
|
60
|
+
def request(path, method: :get, parameters: {}, data: {}, headers: {}, options: {}, retries: 3)
|
61
|
+
response = nil
|
62
|
+
|
63
|
+
response = case method
|
64
|
+
when :get
|
65
|
+
self.connection.get do |request|
|
66
|
+
request.url path
|
67
|
+
request.headers = self.connection.headers.merge(headers)
|
68
|
+
request.params = parameters if parameters && !parameters.empty?
|
69
|
+
end
|
70
|
+
when :head
|
71
|
+
self.connection.head do |request|
|
72
|
+
request.url path
|
73
|
+
request.headers = self.connection.headers.merge(headers)
|
74
|
+
request.params = parameters if parameters && !parameters.empty?
|
75
|
+
end
|
76
|
+
when :post, :put, :patch, :delete
|
77
|
+
self.connection.send(method) do |request|
|
78
|
+
request.url path
|
79
|
+
request.headers = self.connection.headers.merge(headers)
|
80
|
+
request.body = data if data && !data.empty?
|
81
|
+
request.params = parameters if parameters && !parameters.empty?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
return response
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_headers
|
89
|
+
self.headers = self.configuration.endpoints.dig(:wallet, :headers)
|
90
|
+
self.headers["User-Agent"] = self.user_agent unless self.user_agent.to_s.empty?
|
91
|
+
end
|
92
|
+
|
93
|
+
def log(tag = self.class.name, message)
|
94
|
+
puts "[#{tag}] - #{Time.now}: #{message}" if self.configuration.verbose
|
95
|
+
end
|
96
|
+
|
97
|
+
include ::Elrond::Api::Wallet::Endpoints::Address
|
98
|
+
include ::Elrond::Api::Wallet::Endpoints::Transactions
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Elrond
|
2
|
+
module Api
|
3
|
+
module Wallet
|
4
|
+
module Endpoints
|
5
|
+
module Address
|
6
|
+
|
7
|
+
def address(address, options: {})
|
8
|
+
data = nil
|
9
|
+
response = get("/address/#{address}", options: options)&.body
|
10
|
+
|
11
|
+
if response && response.is_a?(Hash)
|
12
|
+
response = response&.fetch("account", {})
|
13
|
+
nonce = response.fetch("nonce", nil)
|
14
|
+
balance = response.fetch("balance", nil)
|
15
|
+
balance = !balance.to_s.empty? ? (balance.to_f / 10_000.0) : nil
|
16
|
+
|
17
|
+
data = {
|
18
|
+
address: address,
|
19
|
+
nonce: nonce,
|
20
|
+
balance: balance
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
return data
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Elrond
|
2
|
+
module Api
|
3
|
+
module Wallet
|
4
|
+
module Endpoints
|
5
|
+
module Transactions
|
6
|
+
|
7
|
+
def request_tokens(address, options: {})
|
8
|
+
response = post("/transaction/send-user-funds", data: {receiver: address}, options: options)&.body
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elrond-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-07-12 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: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday_middleware
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.13.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.13.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.1'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.1.4
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.1'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.1.4
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rake
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '13.0'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 13.0.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '13.0'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 13.0.1
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: rspec
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '3.9'
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '3.9'
|
115
|
+
description: Ruby client to interact with Elrond's REST API.
|
116
|
+
email:
|
117
|
+
- sebastian.johnsson@gmail.com
|
118
|
+
executables: []
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- ".gitignore"
|
123
|
+
- ".rspec"
|
124
|
+
- ".travis.yml"
|
125
|
+
- CODE_OF_CONDUCT.md
|
126
|
+
- Gemfile
|
127
|
+
- Gemfile.lock
|
128
|
+
- LICENSE.txt
|
129
|
+
- README.md
|
130
|
+
- Rakefile
|
131
|
+
- bin/addresses
|
132
|
+
- bin/console
|
133
|
+
- bin/setup
|
134
|
+
- elrond-api.gemspec
|
135
|
+
- lib/elrond/api.rb
|
136
|
+
- lib/elrond/api/configuration.rb
|
137
|
+
- lib/elrond/api/node/client.rb
|
138
|
+
- lib/elrond/api/node/endpoints/address.rb
|
139
|
+
- lib/elrond/api/node/endpoints/nodes.rb
|
140
|
+
- lib/elrond/api/version.rb
|
141
|
+
- lib/elrond/api/wallet/client.rb
|
142
|
+
- lib/elrond/api/wallet/endpoints/address.rb
|
143
|
+
- lib/elrond/api/wallet/endpoints/transactions.rb
|
144
|
+
homepage: https://github.com/SebastianJ/elrond-api
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubygems_version: 3.1.2
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Ruby client to interact with Elrond's REST API.
|
167
|
+
test_files: []
|