etherscan_api 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01707c5cfea737a769f02e8ee5ce2ce0f6291f053fbab8ec1f5299bd63e55ee2
4
+ data.tar.gz: 91f81cb30c5e90359999e5b037283f4e046aa9669b7dfdab18b79df746b792ad
5
+ SHA512:
6
+ metadata.gz: 7b8b1679a83c5c4d82cc2571bf9a18421be9d1414ccc0858e2d5142539f2807a8bff5e5ef8cd5835d4f6b752d38136f65681759b4014f28310c3a2dbf6bdaf13
7
+ data.tar.gz: 310532f8c725bfa4fe53e80c79e3d0f38f48301046af59e78fef8d9b887c8bfebcbdcf2a2f540160abbdd7f48dcb91c248d2115463314d51f3602e134d69ea3e
@@ -0,0 +1,14 @@
1
+ ---
2
+ engines:
3
+ bundler-audit:
4
+ enabled: true
5
+ fixme:
6
+ enabled: true
7
+ rubocop:
8
+ enabled: true
9
+ ratings:
10
+ paths:
11
+ - Gemfile.lock
12
+ - "**.rb"
13
+ exclude_paths:
14
+ - spec/**/*
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ - 2.5.0
5
+
6
+ before_script:
7
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
8
+ - chmod +x ./cc-test-reporter
9
+ - ./cc-test-reporter before-build
10
+ script:
11
+ - bundle exec rspec spec
12
+ after_script:
13
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # gem 'faraday', '~> 0.15'
4
+
5
+ group :development do
6
+ gem 'json', '~> 2.1'
7
+ gem 'rspec', '~> 3.0'
8
+ gem 'shoulda', '>= 0'
9
+ gem 'rdoc', '~> 6.0.3'
10
+ gem 'bundler', '~> 1.0'
11
+ gem 'juwelier', '~> 2.1'
12
+ gem 'simplecov', '~> 0.16'
13
+ gem 'pry-byebug'
14
+ gem 'webmock'
15
+ end
@@ -0,0 +1,125 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (5.2.0)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 0.7, < 2)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ builder (3.2.3)
12
+ byebug (10.0.2)
13
+ coderay (1.1.2)
14
+ concurrent-ruby (1.0.5)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ descendants_tracker (0.0.4)
18
+ thread_safe (~> 0.3, >= 0.3.1)
19
+ diff-lcs (1.3)
20
+ docile (1.3.0)
21
+ faraday (0.12.2)
22
+ multipart-post (>= 1.2, < 3)
23
+ git (1.3.0)
24
+ github_api (0.18.2)
25
+ addressable (~> 2.4)
26
+ descendants_tracker (~> 0.0.4)
27
+ faraday (~> 0.8)
28
+ hashie (~> 3.5, >= 3.5.2)
29
+ oauth2 (~> 1.0)
30
+ hashdiff (0.3.7)
31
+ hashie (3.5.7)
32
+ highline (1.7.10)
33
+ i18n (1.0.1)
34
+ concurrent-ruby (~> 1.0)
35
+ json (2.1.0)
36
+ juwelier (2.4.9)
37
+ builder
38
+ bundler
39
+ git
40
+ github_api
41
+ highline
42
+ kamelcase (~> 0)
43
+ nokogiri
44
+ psych
45
+ rake
46
+ rdoc
47
+ semver2
48
+ jwt (1.5.6)
49
+ kamelcase (0.0.2)
50
+ semver2 (~> 3)
51
+ method_source (0.9.0)
52
+ mini_portile2 (2.3.0)
53
+ minitest (5.11.3)
54
+ multi_json (1.13.1)
55
+ multi_xml (0.6.0)
56
+ multipart-post (2.0.0)
57
+ nokogiri (1.8.2)
58
+ mini_portile2 (~> 2.3.0)
59
+ oauth2 (1.4.0)
60
+ faraday (>= 0.8, < 0.13)
61
+ jwt (~> 1.0)
62
+ multi_json (~> 1.3)
63
+ multi_xml (~> 0.5)
64
+ rack (>= 1.2, < 3)
65
+ pry (0.11.3)
66
+ coderay (~> 1.1.0)
67
+ method_source (~> 0.9.0)
68
+ pry-byebug (3.6.0)
69
+ byebug (~> 10.0)
70
+ pry (~> 0.10)
71
+ psych (3.0.2)
72
+ public_suffix (3.0.2)
73
+ rack (2.0.5)
74
+ rake (12.3.1)
75
+ rdoc (6.0.3)
76
+ rspec (3.7.0)
77
+ rspec-core (~> 3.7.0)
78
+ rspec-expectations (~> 3.7.0)
79
+ rspec-mocks (~> 3.7.0)
80
+ rspec-core (3.7.1)
81
+ rspec-support (~> 3.7.0)
82
+ rspec-expectations (3.7.0)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.7.0)
85
+ rspec-mocks (3.7.0)
86
+ diff-lcs (>= 1.2.0, < 2.0)
87
+ rspec-support (~> 3.7.0)
88
+ rspec-support (3.7.1)
89
+ safe_yaml (1.0.4)
90
+ semver2 (3.4.2)
91
+ shoulda (3.5.0)
92
+ shoulda-context (~> 1.0, >= 1.0.1)
93
+ shoulda-matchers (>= 1.4.1, < 3.0)
94
+ shoulda-context (1.2.2)
95
+ shoulda-matchers (2.8.0)
96
+ activesupport (>= 3.0.0)
97
+ simplecov (0.16.1)
98
+ docile (~> 1.1)
99
+ json (>= 1.8, < 3)
100
+ simplecov-html (~> 0.10.0)
101
+ simplecov-html (0.10.2)
102
+ thread_safe (0.3.6)
103
+ tzinfo (1.2.5)
104
+ thread_safe (~> 0.1)
105
+ webmock (3.3.0)
106
+ addressable (>= 2.3.6)
107
+ crack (>= 0.3.2)
108
+ hashdiff
109
+
110
+ PLATFORMS
111
+ ruby
112
+
113
+ DEPENDENCIES
114
+ bundler (~> 1.0)
115
+ json (~> 2.1)
116
+ juwelier (~> 2.1)
117
+ pry-byebug
118
+ rdoc (~> 6.0.3)
119
+ rspec (~> 3.0)
120
+ shoulda
121
+ simplecov (~> 0.16)
122
+ webmock
123
+
124
+ BUNDLED WITH
125
+ 1.16.1
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 David Paluy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # EtherScan API gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ehterscan.png)](http://badge.fury.io/rb/ehterscan)
4
+ [![Build Status](https://travis-ci.org/dpaluy/etherscan.svg?branch=master)](https://travis-ci.org/dpaluy/etherscan)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/75848a6693e61972e5f3/maintainability)](https://codeclimate.com/github/dpaluy/etherscan/maintainability)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/dpaluy/etherscan.svg)](https://gemnasium.com/github.com/dpaluy/etherscan)
7
+
8
+ Ruby Gem for the EtherScan API https://etherscan.io/apis
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ `gem 'etherscan_api', require: 'etherscan'`
15
+
16
+ And then execute:
17
+
18
+ `$ bundle`
19
+
20
+ Or install it yourself using:
21
+
22
+ `$ gem install etherscan_api`
23
+
24
+ ## Usage
25
+
26
+ Get your api key: https://etherscan.io/myapikey
27
+
28
+ ```
29
+ # config/initializers/etherscan.rb
30
+ EtherScan.configure do |config|
31
+ config.key = 'my_api_key'
32
+ end
33
+ ```
34
+
35
+ ```
36
+ etherscan = Etherscan::Tokens.new
37
+
38
+ # Get ERC20-Token TotalSupply by ContractAddress
39
+ contract_address = '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
40
+ etherscan.total_supply(contract_address)
41
+
42
+ # Get ERC20-Token Account Balance for TokenContractAddress
43
+ contract_address = '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
44
+ address = '0xb36efd48c9912bd9fd58b67b65f7438f6364a256'
45
+ etherscan.balance(address, contract_address)
46
+ ```
47
+
48
+ == Contributing to etherscan
49
+
50
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
51
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
52
+ * Fork the project.
53
+ * Start a feature/bugfix branch.
54
+ * Commit and push until you are happy with your contribution.
55
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
56
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
57
+
58
+ == Copyright
59
+
60
+ Copyright (c) 2018 David Paluy. See LICENSE.txt for
61
+ further details.
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'juwelier'
15
+ Juwelier::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = 'etherscan_api'
18
+ gem.homepage = 'http://github.com/dpaluy/etherscan'
19
+ gem.license = 'MIT'
20
+ gem.summary = %Q{Ruby Gem for the Etherscan API https://etherscan.io/apis }
21
+ gem.description = %Q{This Gem allows you to send Etherscan get requests using native Ruby}
22
+ gem.email = 'dpaluy@gmail.com'
23
+ gem.authors = ['David Paluy']
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Juwelier::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+
35
+ desc 'Code coverage detail'
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = 'true'
38
+ Rake::Task['spec'].execute
39
+ end
40
+
41
+ task default: :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "etherscan #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,14 @@
1
+ require_relative 'etherscan/config'
2
+ require_relative 'etherscan/exceptions'
3
+ require_relative 'etherscan/client'
4
+ require_relative 'etherscan/accounts'
5
+ require_relative 'etherscan/tokens'
6
+ require_relative 'etherscan/engine' if defined?(Rails)
7
+
8
+ module Etherscan
9
+ VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip.freeze
10
+
11
+ def self.logger
12
+ config.logger
13
+ end
14
+ end
@@ -0,0 +1,87 @@
1
+ require_relative 'api'
2
+
3
+ module Etherscan
4
+ class Accounts < Etherscan::Api
5
+ def address_balance(address)
6
+ params = {
7
+ module: 'account', action: 'balance',
8
+ address: address, tag: 'latest'
9
+ }
10
+ get(params)
11
+ end
12
+
13
+ def multi_address_balance(addresses)
14
+ fail Etherscan::Exception, 'up to 20 accounts in a single batch' if addresses.size > 20
15
+ params = {
16
+ module: 'account', action: 'balancemulti',
17
+ address: addresses.join(','), tag: 'latest'
18
+ }
19
+ get(params)
20
+ end
21
+
22
+ # Get a list of 'Normal' Transactions By Address
23
+ # if page is not defined Returns up to 10000 last transactions
24
+ # @param sort 'asc' -> ascending order, 'des' -> descending order
25
+ # @param start_block starting blockNo to retrieve results
26
+ # @param end_block ending blockNo to retrieve results
27
+ # @param page Paginated result <page number>
28
+ # @param offset max records to return
29
+ def normal_transactions(address, sort='asc', page=nil, offset=nil, start_block=nil, end_block=nil)
30
+ action = 'txlist'
31
+ contract_address = nil
32
+ transcations(action, address, contract_address, start_block, end_block, sort, page, offset)
33
+ end
34
+
35
+ # Get a list of 'Internal' Transactions By Address
36
+ def internal_transactions(address, sort='asc', page=nil, offset=nil, start_block=nil, end_block=nil)
37
+ action = 'txlistinternal'
38
+ contract_address = nil
39
+ transcations(action, address, contract_address, start_block, end_block, sort, page, offset)
40
+ end
41
+
42
+ # Get a list of "ERC20 - Token Transfer Events"
43
+ # @param contract_address Token address (set nil to get a list of all ERC20 transactions)
44
+ # @param address Address for ERC20 transactions (optional)
45
+ def token_transactions(contract_address, address=nil, sort='asc',
46
+ page=nil, offset=nil, start_block=nil, end_block=nil)
47
+ fail Etherscan::Exception, 'contract or address must be defined' if (contract_address || address).nil?
48
+ action = 'tokentx'
49
+ transcations(action, address, contract_address, start_block, end_block, sort, page, offset)
50
+ end
51
+
52
+ private
53
+
54
+ def transcations(action, address, contract_address, start_block, end_block, sort, page, offset)
55
+ params = {
56
+ module: 'account', action: action,
57
+ address: address, contractaddress: contract_address, sort: sort,
58
+ startblock: start_block, endblock: end_block,
59
+ page: page, offset: offset
60
+ }.select {|_, v| !v.nil? }
61
+ get(params)
62
+ end
63
+ end
64
+ end
65
+
66
+ __END__
67
+
68
+ Transaction returns the following parameters:
69
+
70
+ nonce
71
+ hash
72
+ cumulativeGasUsed
73
+ gasUsed
74
+ timeStamp
75
+ blockHash
76
+ value (in wei)
77
+ input
78
+ gas
79
+ isInternalTx
80
+ contractAddress
81
+ confirmations
82
+ gasPrice
83
+ transactionIncex
84
+ to
85
+ from
86
+ isError
87
+ blockNumber
@@ -0,0 +1,14 @@
1
+ module Etherscan
2
+ class Api
3
+ attr_reader :connection
4
+
5
+ def initialize(params = {})
6
+ @connection = Etherscan::Client.new(params)
7
+ end
8
+
9
+ def get(params)
10
+ response = connection.get(params)
11
+ response['result']
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ require 'faraday'
2
+
3
+ module Etherscan
4
+ class Client
5
+ URL = 'https://api.etherscan.io/'.freeze
6
+ HEADERS = {'Content-Type' => 'application/json', 'Accept' => 'application/json'}.freeze
7
+
8
+ attr_reader :key, :url, :user_agent, :headers, :raise_exceptions
9
+ attr_writer :adapter, :conn
10
+
11
+ def initialize( params = {} )
12
+ @key = params.fetch(:key, Etherscan.config.key)
13
+ @url = params.fetch(:url, Etherscan.config.url || URL)
14
+ @adapter = params.fetch(:adapter, adapter)
15
+ @conn = params.fetch(:conn, conn)
16
+ @user_agent = params.fetch(:user_agent, "etherscan/#{Etherscan::VERSION};ruby")
17
+ @headers = HEADERS.merge('User-Agent' => @user_agent)
18
+ @raise_exceptions = params.fetch(:raise_exceptions, Etherscan.config.raise_exceptions || true)
19
+ yield self if block_given?
20
+ end
21
+
22
+ def get(params = {})
23
+ endpoint = 'api'
24
+ merged_params = params.merge({apikey: key})
25
+ response = conn.get(url) do |req|
26
+ req.headers = headers
27
+ req.params = merged_params
28
+ end
29
+ fail Etherscan::Exception, response if raise_exceptions? && response.status != 200
30
+
31
+ response
32
+ end
33
+
34
+ def conn
35
+ @conn ||= Faraday.new(url: @url) do |conn|
36
+ conn.request :url_encoded
37
+ conn.adapter adapter
38
+ end
39
+ end
40
+
41
+ def adapter
42
+ @adapter ||= Faraday.default_adapter
43
+ end
44
+
45
+ def raise_exceptions?
46
+ @raise_exceptions
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ require 'logger'
2
+
3
+ module Etherscan
4
+
5
+ class Config
6
+ attr_accessor :key, :secret, :url, :logger, :raise_exceptions
7
+
8
+ def logger
9
+ @logger ||= Logger.new(STDERR)
10
+ end
11
+ end
12
+
13
+ def self.configure
14
+ yield config
15
+ end
16
+
17
+ def self.config
18
+ @config ||= Config.new
19
+ end
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ module Etherscan
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Etherscan
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Etherscan
2
+ class Exception < StandardError
3
+ def initialize(message)
4
+ super(message)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'api'
2
+
3
+ module Etherscan
4
+ class Tokens < Etherscan::Api
5
+ def total_supply(contract_address)
6
+ params = {
7
+ module: 'stats', action: 'tokensupply',
8
+ contractaddress: contract_address
9
+ }
10
+ get(params)
11
+ end
12
+
13
+ def balance(address, contract_address)
14
+ params = {
15
+ module: 'account', action: 'tokenbalance',
16
+ address: address, contractaddress: contract_address
17
+ }
18
+ get(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Etherscan::Accounts do
4
+ let(:connection_mock) { instance_double('Client') }
5
+ let(:connection_params) do
6
+ { key: 'foobar' }
7
+ end
8
+ let(:address) { 'address' }
9
+
10
+ subject { Etherscan::Accounts.new(connection_params) }
11
+
12
+ before do
13
+ allow(Etherscan::Client).to receive(:new).with(connection_params).and_return(connection_mock)
14
+ end
15
+
16
+ it '#address_balance' do
17
+ response = { 'status' => '1', 'message' => 'OK', 'result' => '8750143304924187001472' }
18
+ params = { module: 'account', action: 'balance', address: address, tag: 'latest' }
19
+ expect(connection_mock).to receive(:get).with(params).and_return(response)
20
+ expected_response = subject.address_balance(address)
21
+ expect(expected_response).to eq(response['result'])
22
+ end
23
+
24
+ it '#multi_address_balance' do
25
+ balances = [
26
+ {'account' => '0x564286362092d8e7936f0549571a803b203aaced','balance' => '6074517158469187001472'},
27
+ {'account' => '0x198ef1ec325a96cc354c7266a038be8b5c558f67','balance' => '0'}
28
+ ]
29
+ addresses = balances.map {|e| e['account']}
30
+ response = { 'status' => '1', 'message' => 'OK', 'result' => balances }
31
+ params = { module: 'account', action: 'balancemulti', address: addresses.join(','), tag: 'latest' }
32
+ expect(connection_mock).to receive(:get).with(params).and_return(response)
33
+ expected_response = subject.multi_address_balance(addresses)
34
+ expect(expected_response).to eq(response['result'])
35
+ end
36
+
37
+ it '#normal_transactions' do
38
+ transactions = [
39
+ {
40
+ 'blockNumber' => '4868696', 'timeStamp' => '1515324074', 'hash' => '0x324af15afa',
41
+ 'nonce' => '119', 'blockHash' => '0x908fa99defef9', 'transactionIndex' => '242',
42
+ 'from' => '0xfe9e8709d3215310075d67e3ed32a380ccf451c8',
43
+ 'to' => '0x564286362092d8e7936f0549571a803b203aaced',
44
+ 'value' => '100000000', 'gas' => '21000', 'gasPrice' => '50000000000',
45
+ 'isError' => '0', 'txreceipt_status' => '1',
46
+ 'input' => '0x', 'contractAddress' => '', 'cumulativeGasUsed' => '7983481',
47
+ 'gasUsed' => '21000', 'confirmations' => '634499'
48
+ }
49
+ ]
50
+ response = { 'status' => '1', 'message' => 'OK', 'result' => transactions }
51
+ params = { module: 'account', action: 'txlist', address: address, sort: 'asc' }
52
+ expect(connection_mock).to receive(:get).with(params).and_return(response)
53
+ expected_response = subject.normal_transactions(address)
54
+ expect(expected_response).to eq(response['result'])
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Etherscan::Api do
4
+ let(:connection_mock) { instance_double('Api') }
5
+ let(:connection_params) do
6
+ { key: 'foobar' }
7
+ end
8
+
9
+ it 'initializes a valid connection' do
10
+ expect(Etherscan::Client).to receive(:new).with(connection_params).and_return(connection_mock)
11
+ Etherscan::Api.new(connection_params)
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Etherscan::Tokens do
4
+ let(:connection_mock) { instance_double('Client') }
5
+ let(:connection_params) do
6
+ { key: 'foobar' }
7
+ end
8
+ let(:contract) { 'contract' }
9
+ let(:address) { 'address' }
10
+
11
+ subject { Etherscan::Tokens.new(connection_params) }
12
+
13
+ before do
14
+ allow(Etherscan::Client).to receive(:new).with(connection_params).and_return(connection_mock)
15
+ end
16
+
17
+ it '#total_supply' do
18
+ response = { 'status' => '1', 'message' => 'OK', 'result' => '75974982082112433807172752' }
19
+ params = { module: 'stats', action: 'tokensupply', contractaddress: contract }
20
+ expect(connection_mock).to receive(:get).with(params).and_return(response)
21
+ expected_response = subject.total_supply(contract)
22
+ expect(expected_response).to eq(response['result'])
23
+ end
24
+
25
+ it '#balance' do
26
+ response = { 'status' => '1', 'message' => 'OK', 'result' => '34080719924110000000000' }
27
+ params = { module: 'account', action: 'tokenbalance', address: address, contractaddress: contract }
28
+ expect(connection_mock).to receive(:get).with(params).and_return(response)
29
+ expected_response = subject.balance(address, contract)
30
+ expect(expected_response).to eq(response['result'])
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Etherscan" do
4
+ it "has a version" do
5
+ expect(Etherscan::VERSION).not_to be_nil
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ require 'webmock/rspec'
2
+
3
+ if ENV['COVERAGE']
4
+ require 'simplecov'
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter
7
+ ]
8
+ SimpleCov.start
9
+ end
10
+
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+
14
+ require 'etherscan'
15
+ require 'byebug'
16
+ require 'active_support/all'
17
+ require 'rspec'
18
+
19
+ # Requires supporting files with custom matchers and macros, etc,
20
+ # in ./support/ and its subdirectories.
21
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
22
+
23
+ RSpec.configure do |config|
24
+ config.order = 'random'
25
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etherscan_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - David Paluy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: shoulda
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: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.0.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.0.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: juwelier
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: This Gem allows you to send Etherscan get requests using native Ruby
140
+ email: dpaluy@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files:
144
+ - LICENSE.txt
145
+ - README.md
146
+ files:
147
+ - ".codeclimate.yml"
148
+ - ".document"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - VERSION
156
+ - lib/etherscan.rb
157
+ - lib/etherscan/accounts.rb
158
+ - lib/etherscan/api.rb
159
+ - lib/etherscan/client.rb
160
+ - lib/etherscan/config.rb
161
+ - lib/etherscan/engine.rb
162
+ - lib/etherscan/exceptions.rb
163
+ - lib/etherscan/tokens.rb
164
+ - spec/etherscan/accounts_spec.rb
165
+ - spec/etherscan/api_spec.rb
166
+ - spec/etherscan/tokens_spec.rb
167
+ - spec/etherscan_spec.rb
168
+ - spec/spec_helper.rb
169
+ homepage: http://github.com/dpaluy/etherscan
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.7.3
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Ruby Gem for the Etherscan API https://etherscan.io/apis
193
+ test_files: []