etherscanio 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +90 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/Guardfile +51 -0
- data/README.md +5 -0
- data/Rakefile +7 -0
- data/etherscanio.gemspec +30 -0
- data/lib/etherscanio/api.rb +70 -0
- data/lib/etherscanio/call.rb +56 -0
- data/spec/api/account/balance_spec.rb +15 -0
- data/spec/api/account/balancemulti_spec.rb +21 -0
- data/spec/api/account/getminedblocks_spec.rb +24 -0
- data/spec/api/account/txlist_internal_spec.rb +28 -0
- data/spec/api/account/txlist_spec.rb +27 -0
- data/spec/api/block_getblockreward_spec.rb +13 -0
- data/spec/api/contract_spec.rb +13 -0
- data/spec/api/transaction_getstatus_spec.rb +13 -0
- data/spec/etehrscanio_call_api_key_spec.rb +14 -0
- data/spec/etherscan_call_params_spec.rb +94 -0
- data/spec/etherscanio_call_spec.rb +31 -0
- data/spec/etherscanio_spec.rb +12 -0
- data/spec/fixtures/account/balance.json +1 -0
- data/spec/fixtures/account/balance_multiple.json +1 -0
- data/spec/fixtures/account/getminedblocks.json +1 -0
- data/spec/fixtures/account/txlist.json +1 -0
- data/spec/fixtures/account/txlist_internal.json +1 -0
- data/spec/fixtures/block_getblockreward.json +1 -0
- data/spec/fixtures/contract_getabi.json +1 -0
- data/spec/fixtures/transaction_getstatus.json +1 -0
- data/spec/spec_helper.rb +80 -0
- metadata +222 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75235b7097173271620ff5b1c5934c3b0925e984
|
4
|
+
data.tar.gz: e3931309dbcb07e4cbf8bb11cf1f183f3c65e9ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8dae5cd73b1dca8178eeb9b908310a08cd8283a3a89c1bf147f05c55b21f647f96d13bfadaeb8b157e39989869bd95746953f811aa3261264b1ddc84e7128966
|
7
|
+
data.tar.gz: b8fd18b33f4049886995373bbf2c8f9cde3bac51d6d5c3c5b0e6afbafab912b97123a48c1d0c678d12a0b56a5f4f8efb130014372d9f60276c6abd5d33e4dbf7
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
Metrics/BlockLength:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
# Disable global vars
|
5
|
+
Style/SpecialGlobalVars:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
# Disable class length restriction
|
9
|
+
Metrics/ClassLength:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
# Disable module length restriction
|
13
|
+
Metrics/ModuleLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
# Disable method length restriction
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
# Disable checking of ABC metrics (assignment, branch, condition)
|
21
|
+
Metrics/AbcSize:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
# Disable method perceived complexity (how it is hard to read a method)
|
25
|
+
Metrics/PerceivedComplexity:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
# Disable cyclomatic complexity which is a number of paths through a method
|
29
|
+
Metrics/CyclomaticComplexity:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
# Block nesting is 5
|
33
|
+
Metrics/BlockNesting:
|
34
|
+
Max: 5
|
35
|
+
|
36
|
+
# Set max line length to 120
|
37
|
+
Metrics/LineLength:
|
38
|
+
Max: 120
|
39
|
+
|
40
|
+
# Set max line length to 120
|
41
|
+
Metrics/ParameterLists:
|
42
|
+
Max: 6
|
43
|
+
|
44
|
+
Style/Documentation:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# Trailing comma helps not to forget to put it
|
48
|
+
# if you want to add new value below
|
49
|
+
Style/TrailingCommaInLiteral:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
# It is totally ok to use block chain by my preference
|
53
|
+
# It promotes functional programming style
|
54
|
+
Style/MultilineBlockChain:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
# Empty lines are enabled to simplify vim paragraph selection
|
58
|
+
Style/EmptyLinesAroundBlockBody:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Style/EmptyLinesAroundClassBody:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Style/EmptyLinesAroundMethodBody:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
# Disable multiline method indentation, not comfortable with it
|
68
|
+
Style/MultilineMethodCallIndentation:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
# extend self uses ruby inheritance instead of copying methods
|
72
|
+
Style/ModuleFunction:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Style/Lambda:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
AllCops:
|
79
|
+
DisplayCopNames: true
|
80
|
+
Exclude:
|
81
|
+
- db/**/*
|
82
|
+
- bin/**
|
83
|
+
- config/**/**
|
84
|
+
- spec/dummy/bin/**
|
85
|
+
- spec/dummy/db/**
|
86
|
+
- Guardfile
|
87
|
+
|
88
|
+
Rails:
|
89
|
+
Enabled: false
|
90
|
+
Exclude:
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
4
|
+
require "guard/rspec/dsl"
|
5
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
6
|
+
|
7
|
+
# Feel free to open issues for suggestions and improvements
|
8
|
+
|
9
|
+
# RSpec files
|
10
|
+
rspec = dsl.rspec
|
11
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
12
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_files)
|
14
|
+
|
15
|
+
# Ruby files
|
16
|
+
ruby = dsl.ruby
|
17
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
18
|
+
|
19
|
+
# Rails files
|
20
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
21
|
+
dsl.watch_spec_files_for(rails.app_files)
|
22
|
+
dsl.watch_spec_files_for(rails.views)
|
23
|
+
|
24
|
+
watch(rails.controllers) do |m|
|
25
|
+
[
|
26
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
27
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
28
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Rails config changes
|
33
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
34
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
35
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
36
|
+
|
37
|
+
# Capybara features specs
|
38
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
39
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
40
|
+
|
41
|
+
# Turnip features and steps
|
42
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
43
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
44
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
guard :rubocop do
|
49
|
+
watch(%r{.+\.rb$})
|
50
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
51
|
+
end
|
data/README.md
ADDED
data/Rakefile
ADDED
data/etherscanio.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'etherscanio'
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ['Sebastian Schürmann']
|
9
|
+
spec.email = ['sebs@2xs.org']
|
10
|
+
spec.description = '3rd party uinding to the ethereumblockchain API at etherscan.io'
|
11
|
+
spec.summary = ''
|
12
|
+
spec.homepage = 'https://github.com/sebs/etherscanio-rb'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'rest-client'
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'guard'
|
25
|
+
spec.add_development_dependency 'guard-rspec'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
27
|
+
spec.add_development_dependency 'guard-rubocop'
|
28
|
+
spec.add_development_dependency 'webmock'
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Etherscanio
|
2
|
+
class Api
|
3
|
+
def initialize(_key)
|
4
|
+
nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def account_txlist(address, startblock, endblock, sort = 'desc', page = nil, offset = nil)
|
8
|
+
call = Etherscanio::Call.new('account', 'txlist')
|
9
|
+
call.address = address
|
10
|
+
call.startblock = startblock
|
11
|
+
call.endblock = endblock
|
12
|
+
call.page = page
|
13
|
+
call.offset = offset
|
14
|
+
call.sort = sort
|
15
|
+
call.fetch
|
16
|
+
end
|
17
|
+
|
18
|
+
def account_txlistinternal(address, startblock, endblock, sort = 'desc', page = nil, offset = nil)
|
19
|
+
call = Etherscanio::Call.new('account', 'txlistinternal')
|
20
|
+
call.address = address
|
21
|
+
call.startblock = startblock
|
22
|
+
call.endblock = endblock
|
23
|
+
call.page = page
|
24
|
+
call.offset = offset
|
25
|
+
call.sort = sort
|
26
|
+
call.fetch
|
27
|
+
end
|
28
|
+
|
29
|
+
def account_balance(address, tag)
|
30
|
+
call = Etherscanio::Call.new('account', 'balance')
|
31
|
+
call.address = address
|
32
|
+
call.tag = tag
|
33
|
+
call.fetch
|
34
|
+
end
|
35
|
+
|
36
|
+
def getminedblocks(address, blocktype, page = nil, offset = nil)
|
37
|
+
call = Etherscanio::Call.new('account', 'getminedblocks')
|
38
|
+
call.page = page
|
39
|
+
call.offset = offset
|
40
|
+
call.address = address
|
41
|
+
call.blocktype = blocktype
|
42
|
+
call.fetch
|
43
|
+
end
|
44
|
+
|
45
|
+
def account_balancemulti(address, tag)
|
46
|
+
call = Etherscanio::Call.new('account', 'balancemulti')
|
47
|
+
call.address = address
|
48
|
+
call.tag = tag
|
49
|
+
call.fetch
|
50
|
+
end
|
51
|
+
|
52
|
+
def contract_getabi(address)
|
53
|
+
call = Etherscanio::Call.new('contract', 'getabi')
|
54
|
+
call.address = address
|
55
|
+
call.fetch
|
56
|
+
end
|
57
|
+
|
58
|
+
def transaction_getstatus(txhash)
|
59
|
+
call = Etherscanio::Call.new('transaction', 'getstatus')
|
60
|
+
call.txhash = txhash
|
61
|
+
call.fetch
|
62
|
+
end
|
63
|
+
|
64
|
+
def block_getblockreward(blockno)
|
65
|
+
call = Etherscanio::Call.new('block', 'getblockreward')
|
66
|
+
call.blockno = blockno
|
67
|
+
call.fetch
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
module Etherscanio
|
3
|
+
class Call
|
4
|
+
attr_accessor :mod,
|
5
|
+
:action,
|
6
|
+
:api_key,
|
7
|
+
:address,
|
8
|
+
:tag,
|
9
|
+
:startblock,
|
10
|
+
:endblock,
|
11
|
+
:sort,
|
12
|
+
:page,
|
13
|
+
:offset,
|
14
|
+
:sort,
|
15
|
+
:blocktype,
|
16
|
+
:txhash,
|
17
|
+
:blockno
|
18
|
+
def initialize(mod, action)
|
19
|
+
@base = 'http://api.etherscan.io/api?'
|
20
|
+
@mod = mod
|
21
|
+
@action = action
|
22
|
+
@api_key = false
|
23
|
+
end
|
24
|
+
|
25
|
+
def fetch
|
26
|
+
res = RestClient.get(to_s, {}).body
|
27
|
+
parsed = JSON.parse(res)
|
28
|
+
JSON.generate(parsed)
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
uri = 'module=' + mod + '&action=' + action
|
33
|
+
uri += '&apikey=' + api_key if api_key
|
34
|
+
uri += address_fragment
|
35
|
+
uri += '&startblock=' + startblock.to_s if startblock
|
36
|
+
uri += '&endblock=' + endblock.to_s if endblock
|
37
|
+
uri += '&blocktype=' + blocktype if blocktype
|
38
|
+
uri += '&txhash=' + txhash if txhash
|
39
|
+
uri += '&blockno=' + blockno.to_s if blockno
|
40
|
+
uri += '&offset=' + offset.to_s if offset
|
41
|
+
uri += '&sort=' + sort if sort
|
42
|
+
uri += '&page=' + page.to_s if page
|
43
|
+
uri += '&tag=' + tag if tag
|
44
|
+
@base + uri
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def address_fragment
|
50
|
+
res = ''
|
51
|
+
res += '&address=' + address if address && !address.is_a?(Array)
|
52
|
+
res += '&address=' + address.join(',') if address && address.is_a?(Array)
|
53
|
+
res
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Etherscanio::Api do
|
4
|
+
describe 'account_balance' do
|
5
|
+
subject { Etherscanio::Api.new(apikey).account_balance(address, tag) }
|
6
|
+
|
7
|
+
context 'one address' do
|
8
|
+
subject { Etherscanio::Api.new(apikey).account_balance(address, tag) }
|
9
|
+
let(:apikey) { 'YourApiKeyToken' }
|
10
|
+
let(:address) { '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' }
|
11
|
+
let(:tag) { 'latest' }
|
12
|
+
it { is_expected.to be_a(Object) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Etherscanio::Api do
|
4
|
+
describe 'account_balancemulti' do
|
5
|
+
|
6
|
+
context 'multiple address' do
|
7
|
+
subject { Etherscanio::Api.new(apikey).account_balancemulti(address, tag) }
|
8
|
+
let(:apikey) { 'YourApiKeyToken' }
|
9
|
+
let(:address) do
|
10
|
+
%w(
|
11
|
+
0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a
|
12
|
+
0x63a9975ba31b0b9626b34300f7f627147df1f526
|
13
|
+
0x198ef1ec325a96cc354c7266a038be8b5c558f67
|
14
|
+
)
|
15
|
+
end
|
16
|
+
let(:tag) { 'latest' }
|
17
|
+
it { is_expected.to be_a(Object) }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Etherscanio::Api do
|
4
|
+
describe 'account_balance' do
|
5
|
+
subject { Etherscanio::Api.new(apikey).getminedblocks(address, blocktype) }
|
6
|
+
|
7
|
+
context 'no paging' do
|
8
|
+
let(:apikey) { 'YourApiKeyToken' }
|
9
|
+
let(:address) { '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' }
|
10
|
+
let(:blocktype) { 'block' }
|
11
|
+
it { is_expected.to be_a(Object) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'paging' do
|
15
|
+
subject { Etherscanio::Api.new(apikey).getminedblocks(address, blocktype, page, offset) }
|
16
|
+
let(:apikey) { 'YourApiKeyToken' }
|
17
|
+
let(:address) { '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' }
|
18
|
+
let(:page) { 1 }
|
19
|
+
let(:offset) { 10 }
|
20
|
+
let(:blocktype) { 'block' }
|
21
|
+
it { is_expected.to be_a(Object) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Etherscanio::Api do
|
4
|
+
describe 'account_txlistinternal' do
|
5
|
+
subject { Etherscanio::Api.new(apikey).account_txlistinternal(address, startblock, endblock, sort) }
|
6
|
+
|
7
|
+
context 'no paging' do
|
8
|
+
let(:apikey) { 'YourApiKeyToken' }
|
9
|
+
let(:address) { '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' }
|
10
|
+
let(:startblock) { 0 }
|
11
|
+
let(:endblock) { 99_999_999 }
|
12
|
+
let(:sort) { 'desc' }
|
13
|
+
it { is_expected.to be_a(Object) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'paging' do
|
17
|
+
subject { Etherscanio::Api.new(apikey).account_txlistinternal(address, startblock, endblock, sort, page, offset) }
|
18
|
+
let(:apikey) { 'YourApiKeyToken' }
|
19
|
+
let(:address) { '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' }
|
20
|
+
let(:startblock) { 0 }
|
21
|
+
let(:endblock) { 99_999_999 }
|
22
|
+
let(:sort) { 'desc' }
|
23
|
+
let(:page) { 1 }
|
24
|
+
let(:offset) { 10 }
|
25
|
+
it { is_expected.to be_a(Object) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|