etherscan 0.1.4 → 0.2.0

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.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. metadata +14 -243
  3. data/.gitignore +0 -13
  4. data/Gemfile +0 -5
  5. data/README.md +0 -17
  6. data/Rakefile +0 -10
  7. data/etherscan.gemspec +0 -33
  8. data/lib/etherscan/api.rb +0 -225
  9. data/lib/etherscan/call.rb +0 -102
  10. data/lib/etherscan.rb +0 -11
  11. data/spec/api/account/balance_spec.rb +0 -15
  12. data/spec/api/account/balancemulti_spec.rb +0 -21
  13. data/spec/api/account/getminedblocks_spec.rb +0 -24
  14. data/spec/api/account/txlist_internal_spec.rb +0 -28
  15. data/spec/api/account/txlist_spec.rb +0 -27
  16. data/spec/api/block_getblockreward_spec.rb +0 -13
  17. data/spec/api/contract_spec.rb +0 -13
  18. data/spec/api/transaction_getstatus_spec.rb +0 -13
  19. data/spec/etehrscanio_call_api_key_spec.rb +0 -14
  20. data/spec/etherscan_call_params_spec.rb +0 -94
  21. data/spec/etherscanio_call_spec.rb +0 -31
  22. data/spec/etherscanio_spec.rb +0 -12
  23. data/spec/fixtures/account/balance.json +0 -1
  24. data/spec/fixtures/account/balance_multiple.json +0 -1
  25. data/spec/fixtures/account/getminedblocks.json +0 -1
  26. data/spec/fixtures/account/txlist.json +0 -1
  27. data/spec/fixtures/account/txlist_internal.json +0 -1
  28. data/spec/fixtures/block_getblockreward.json +0 -1
  29. data/spec/fixtures/contract_getabi.json +0 -1
  30. data/spec/fixtures/proxy/eth_blocknumber.json +0 -1
  31. data/spec/fixtures/proxy/eth_call.json +0 -1
  32. data/spec/fixtures/proxy/eth_estimategas.json +0 -1
  33. data/spec/fixtures/proxy/eth_gasprice.json +0 -1
  34. data/spec/fixtures/proxy/eth_getblockbynumber.json +0 -1
  35. data/spec/fixtures/proxy/eth_getblocktransactioncountbynumber.json +0 -1
  36. data/spec/fixtures/proxy/eth_getcode.json +0 -1
  37. data/spec/fixtures/proxy/eth_getstorageat.json +0 -1
  38. data/spec/fixtures/proxy/eth_gettransactionbyhash.json +0 -1
  39. data/spec/fixtures/proxy/eth_gettransactionbynumberandindex.json +0 -1
  40. data/spec/fixtures/proxy/eth_gettransactioncount.json +0 -1
  41. data/spec/fixtures/proxy/eth_gettransactionreceipt.json +0 -1
  42. data/spec/fixtures/proxy/eth_getunclebyblockbynumberandindex.json +0 -1
  43. data/spec/fixtures/proxy/eth_sendrawtransaction.json +0 -1
  44. data/spec/fixtures/stats/ethprice.json +0 -1
  45. data/spec/fixtures/stats/ethsupply.json +0 -1
  46. data/spec/fixtures/stats/tokensupply.json +0 -1
  47. data/spec/fixtures/token/tokensupply.json +0 -1
  48. data/spec/fixtures/transaction_getstatus.json +0 -1
  49. data/spec/spec_helper.rb +0 -80
@@ -1,102 +0,0 @@
1
- module Etherscan
2
- class ReturnError < RuntimeError; end
3
-
4
- class Call
5
- attr_accessor :chain,
6
- :mod,
7
- :action,
8
- :api_key,
9
- :address,
10
- :tag,
11
- :startblock,
12
- :endblock,
13
- :sort,
14
- :page,
15
- :offset,
16
- :sort,
17
- :blocktype,
18
- :txhash,
19
- :blockno,
20
- :hex,
21
- :boolean,
22
- :data,
23
- :to,
24
- :index,
25
- :position,
26
- :gasPrice,
27
- :gas,
28
- :fromBlock,
29
- :toBlock,
30
- :address,
31
- :topics
32
-
33
- CHAINS = {
34
- mainnet: 'http://api.etherscan.io/api?',
35
- ropsten: 'https://ropsten.etherscan.io/api?',
36
- kovan: 'https://kovan.etherscan.io/api?',
37
- rinkeby: 'https://rinkeby.etherscan.io/api?'
38
- }
39
-
40
- def initialize(chain, mod, action)
41
- @chain = chain.to_sym
42
- @base = CHAINS[chain.to_sym]
43
- @mod = mod
44
- @action = action
45
- @api_key = false
46
- end
47
-
48
- def fetch
49
- query_url = to_s
50
- Etherscan.logger.debug query_url
51
- res = Faraday.get(query_url).body
52
- Etherscan.logger.debug res
53
- data = JSON.parse(res)
54
- return [:error, data['error']] if data['error']
55
- return [:error, data['message']] if (data['status'] && data['status'] != '1')
56
- return [:ok, data['result']]
57
- rescue => e
58
- Etherscan.logger.error "Error: #{e}"
59
- Etherscan.logger.error e.backtrace[0, 20].join("\n")
60
- return [:error, e.message]
61
- end
62
-
63
- def to_s
64
- uri = 'module=' + mod + '&action=' + action
65
- uri += '&apikey=' + api_key if api_key
66
- uri += address_fragment
67
- uri += '&startblock=' + startblock.to_s if startblock
68
- uri += '&endblock=' + endblock.to_s if endblock
69
- uri += '&blocktype=' + blocktype if blocktype
70
- uri += '&txhash=' + txhash if txhash
71
- uri += '&blockno=' + blockno.to_s if blockno
72
- uri += '&offset=' + offset.to_s if offset
73
- uri += '&sort=' + sort if sort
74
- uri += '&page=' + page.to_s if page
75
- uri += '&tag=' + tag if tag
76
- uri += '&hex=' + hex if hex
77
- uri += '&boolean=' + boolean if boolean
78
- uri += '&data=' + data if data
79
- uri += '&to=' + to if to
80
- uri += '&index=' + index if index
81
- uri += '&position=' + position if position
82
- uri += '&gasPrice=' + gasPrice if gasPrice
83
- uri += '&fromBlock=' + fromBlock if fromBlock
84
- uri += '&toBlock=' + toBlock if toBlock
85
- if topics
86
- topics.each do |topic|
87
- uri += "&#{topic['name']}=" + topic['value']
88
- end
89
- end
90
- @base + uri
91
- end
92
-
93
- private
94
-
95
- def address_fragment
96
- res = ''
97
- res += '&address=' + address if (address && !address.is_a?(Array))
98
- res += '&address=' + address.join(',') if (address && address.is_a?(Array))
99
- res
100
- end
101
- end
102
- end
data/lib/etherscan.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'json'
2
- require 'faraday'
3
- require 'logger'
4
- require 'etherscan/call'
5
- require 'etherscan/api'
6
-
7
- module Etherscan
8
- class << self
9
- attr_accessor :logger
10
- end
11
- end
@@ -1,15 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Api do
4
- describe 'account_getminedblocks' do
5
- subject { Etherscanio::Api.new(apikey).account_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).account_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
@@ -1,28 +0,0 @@
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
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Api do
4
- describe 'account_txlist' do
5
- subject { Etherscanio::Api.new(apikey).account_txlist(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
- context 'paging' do
16
- # subject { Etherscanio::Api.new(apikey).account_txlist(address, startblock, endblock, sort, page, offset) }
17
- let(:apikey) { 'YourApiKeyToken' }
18
- let(:address) { '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' }
19
- let(:startblock) { 0 }
20
- let(:endblock) { 99_999_999 }
21
- let(:sort) { 'desc' }
22
- let(:page) { 1 }
23
- let(:offset) { 10 }
24
- it { is_expected.to be_a(Object) }
25
- end
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Api do
4
- describe 'block_getblockreward' do
5
- subject { Etherscanio::Api.new(apikey).block_getblockreward(blockno) }
6
-
7
- context 'simple status error' do
8
- let(:apikey) { 'YourApiKeyToken' }
9
- let(:blockno) { '2165403' }
10
- it { is_expected.to be_a(Object) }
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Api do
4
- describe 'contract_getabi' do
5
- subject { Etherscanio::Api.new(apikey).contract_getabi(address) }
6
-
7
- context 'one address' do
8
- let(:apikey) { 'YourApiKeyToken' }
9
- let(:address) { '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' }
10
- it { is_expected.to be_a(Object) }
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Api do
4
- describe 'transaction_getstatus' do
5
- subject { Etherscanio::Api.new(apikey).transaction_getstatus(txhash) }
6
-
7
- context 'simple status error' do
8
- let(:apikey) { 'YourApiKeyToken' }
9
- let(:txhash) { '0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a' }
10
- it { is_expected.to be_a(Object) }
11
- end
12
- end
13
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Call do
4
- let(:uri) { 'http://api.etherscan.io/api?' }
5
- subject do
6
- call = Etherscanio::Call.new('foo', 'bar')
7
- call.api_key = api_key
8
- call.to_s
9
- end
10
- context 'with api_key' do
11
- let(:api_key) { '123' }
12
- it { is_expected.to eq(uri + 'module=foo&action=bar&apikey=123') }
13
- end
14
- end
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Call do
4
- let(:uri) { 'http://api.etherscan.io/api?' }
5
- describe '.address' do
6
- subject do
7
- call = Etherscanio::Call.new('foo', 'bar')
8
- call.address = address
9
- call.to_s
10
- end
11
- context '123' do
12
- let(:address) { '123' }
13
- it { is_expected.to eq(uri + 'module=foo&action=bar&address=123') }
14
- end
15
- end
16
-
17
- describe '.tag' do
18
- subject do
19
- call = Etherscanio::Call.new('foo', 'bar')
20
- call.tag = tag
21
- call.to_s
22
- end
23
- context 'house' do
24
- let(:tag) { 'house' }
25
- it { is_expected.to eq(uri + 'module=foo&action=bar&tag=house') }
26
- end
27
- end
28
- describe '.startblock' do
29
- subject do
30
- call = Etherscanio::Call.new('foo', 'bar')
31
- call.startblock = startblock
32
- call.to_s
33
- end
34
- context '1' do
35
- let(:startblock) { 1 }
36
- it { is_expected.to eq(uri + 'module=foo&action=bar&startblock=1') }
37
- end
38
- end
39
- describe '.endblock' do
40
- subject do
41
- call = Etherscanio::Call.new('foo', 'bar')
42
- call.endblock = endblock
43
- call.to_s
44
- end
45
- context '1' do
46
- let(:endblock) { 1 }
47
- it { is_expected.to eq(uri + 'module=foo&action=bar&endblock=1') }
48
- end
49
- end
50
- describe '.sort' do
51
- subject do
52
- call = Etherscanio::Call.new('foo', 'bar')
53
- call.sort = sort
54
- call.to_s
55
- end
56
- context 'desc' do
57
- let(:sort) { 'desc' }
58
- it { is_expected.to eq(uri + 'module=foo&action=bar&sort=desc') }
59
- end
60
- end
61
- describe '.page' do
62
- subject do
63
- call = Etherscanio::Call.new('foo', 'bar')
64
- call.page = page
65
- call.to_s
66
- end
67
- context '1' do
68
- let(:page) { 1 }
69
- it { is_expected.to eq(uri + 'module=foo&action=bar&page=1') }
70
- end
71
- end
72
- describe '.txhash' do
73
- subject do
74
- call = Etherscanio::Call.new('foo', 'bar')
75
- call.txhash = txhash
76
- call.to_s
77
- end
78
- context 'a' do
79
- let(:txhash) { 'a' }
80
- it { is_expected.to eq(uri + 'module=foo&action=bar&txhash=a') }
81
- end
82
- end
83
- describe '.blockno' do
84
- subject do
85
- call = Etherscanio::Call.new('foo', 'bar')
86
- call.blockno = blockno
87
- call.to_s
88
- end
89
- context 'a' do
90
- let(:blockno) { 100 }
91
- it { is_expected.to eq(uri + 'module=foo&action=bar&blockno=100') }
92
- end
93
- end
94
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Call do
4
- describe 'initialize' do
5
- subject { Etherscanio::Call.new(mod, action) }
6
- context 'is a object' do
7
- let(:mod) { 'foo' }
8
- let(:action) { 'bar' }
9
- it { is_expected.to be_a(Object) }
10
- end
11
- context '.mod' do
12
- subject { Etherscanio::Call.new(mod, action).mod }
13
- let(:mod) { 'foo' }
14
- let(:action) { 'bar' }
15
- it { is_expected.to be_a(String) }
16
- end
17
- context '.action' do
18
- subject { Etherscanio::Call.new(mod, action).action }
19
- let(:mod) { 'foo' }
20
- let(:action) { 'bar' }
21
- it { is_expected.to be_a(String) }
22
- end
23
- context 'to_s' do
24
- subject { Etherscanio::Call.new(mod, action).to_s }
25
- let(:mod) { 'foo' }
26
- let(:action) { 'bar' }
27
- let(:uri) { 'http://api.etherscan.io/api?' }
28
- it { is_expected.to eq(uri + 'module=foo&action=bar') }
29
- end
30
- end
31
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Etherscanio::Api do
4
- describe 'initialize' do
5
- subject { Etherscanio::Api.new(context) }
6
-
7
- context 'is a object' do
8
- let(:context) { 'foo' }
9
- it { is_expected.to be_a(Object) }
10
- end
11
- end
12
- end
@@ -1 +0,0 @@
1
- {"status":"1","message":"OK","result":"981678563608465139479303"}
@@ -1 +0,0 @@
1
- {"status":"1","message":"OK","result":[{"account":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","balance":"40807168564070000000000"},{"account":"0x63a9975ba31b0b9626b34300f7f627147df1f526","balance":"332567136222827062478"},{"account":"0x198ef1ec325a96cc354c7266a038be8b5c558f67","balance":"8593837860677995368724"}]}