etherscan 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etherscan/version.rb +1 -1
- data/lib/etherscan.rb +15 -1
- data/lib/subscan/api.rb +50 -0
- data/lib/tronscan/api.rb +3 -5
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0227579db92861939267b0cac5f56646f809f4a4d1db84800f77401e68404717'
|
4
|
+
data.tar.gz: f1451aa9dc8117abe7070f80908b6cc764bcba3407968b02aaa9af36f371961d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 674a4e2c6fb06d13f1a075706658014f141ca6be9ffa74cfbcfa985ce49e0a3b476086c06a3c2759f88124d38872912df7d0776a316d0e01102650d09a0f158e
|
7
|
+
data.tar.gz: 711af9556a2a5efbf870fa90168ca39f5cecafc1c918b8c45b0830a82e65bc65be389ab361c16679027695d67de8c3ea15ddd65c93bd617af7c67a3778321b53
|
data/lib/etherscan/version.rb
CHANGED
data/lib/etherscan.rb
CHANGED
@@ -3,6 +3,7 @@ require 'logger'
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'etherscan/api'
|
5
5
|
require 'tronscan/api'
|
6
|
+
require 'subscan/api'
|
6
7
|
|
7
8
|
require 'active_support'
|
8
9
|
require 'active_support/core_ext/string'
|
@@ -52,6 +53,12 @@ module Etherscan
|
|
52
53
|
'tron' => 'https://apilist.tronscanapi.com/api',
|
53
54
|
}
|
54
55
|
|
56
|
+
SUBSCAN_CHAINS = {
|
57
|
+
'pangolin' => 'https://pangolin.api.subscan.io/api',
|
58
|
+
'crab' => 'https://crab.api.subscan.io/api',
|
59
|
+
'darwinia' => 'https://darwinia.api.subscan.io/api',
|
60
|
+
}
|
61
|
+
|
55
62
|
class << self
|
56
63
|
attr_accessor :logger
|
57
64
|
|
@@ -62,10 +69,17 @@ module Etherscan
|
|
62
69
|
tron_url = TRON_CHAINS[chain_short_name]
|
63
70
|
tron_url = TRON_CHAINS[chain_short_name.underscore] if url.nil?
|
64
71
|
|
65
|
-
|
72
|
+
subscan_url = SUBSCAN_CHAINS[chain_short_name]
|
73
|
+
subscan_url = SUBSCAN_CHAINS[chain_short_name.underscore] if url.nil?
|
74
|
+
|
75
|
+
raise "Chain `#{chain_short_name}` is not supported. Only " \
|
76
|
+
"Etherscan [#{CHAINS.keys}] & " \
|
77
|
+
"Subscan [#{SUBSCAN_CHAINS.keys}] & " \
|
78
|
+
"Tronscan [#{TRON_CHAINS.keys}] are supported." if url.nil? && tron_url.nil? && subscan_url.nil?
|
66
79
|
|
67
80
|
return Etherscan::Api.new(url, api_key) if url
|
68
81
|
return Tronscan::Api.new(tron_url, api_key) if tron_url
|
82
|
+
return Subscan::Api.new(subscan_url, api_key) if subscan_url
|
69
83
|
end
|
70
84
|
|
71
85
|
# for example: Etherscan.eth('your_api_key')
|
data/lib/subscan/api.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Subscan
|
2
|
+
class Api
|
3
|
+
def initialize(url, api_key = nil)
|
4
|
+
@url = url
|
5
|
+
@api_key = api_key
|
6
|
+
end
|
7
|
+
|
8
|
+
def request(module_name, action, params = {})
|
9
|
+
params = params.reject { |_k, v| v.nil? } # filter out nil values
|
10
|
+
|
11
|
+
url = "#{@url}/scan/#{module_name}/#{action}"
|
12
|
+
uri = URI(url)
|
13
|
+
Etherscan.logger.debug "Req: #{uri}"
|
14
|
+
|
15
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
http.use_ssl = (uri.scheme == 'https')
|
17
|
+
|
18
|
+
request = Net::HTTP::Post.new(uri)
|
19
|
+
request['Content-Type'] = 'application/json'
|
20
|
+
request['X-API-Key'] = @api_key unless @api_key.nil?
|
21
|
+
request.body = params.to_json
|
22
|
+
Etherscan.logger.debug "Body: #{request.body}"
|
23
|
+
|
24
|
+
response = http.request(request)
|
25
|
+
|
26
|
+
raise response.body if response.code != '200'
|
27
|
+
|
28
|
+
json_response = JSON.parse(response.body)
|
29
|
+
|
30
|
+
if json_response.key?('status')
|
31
|
+
raise json_response['message'] if json_response['status'] != '1'
|
32
|
+
|
33
|
+
json_response['result'] || json_response['message']
|
34
|
+
elsif json_response.key?('code') # normal response
|
35
|
+
raise json_response['message'] if json_response['code'] != 0
|
36
|
+
|
37
|
+
json_response['data']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def respond_to_missing?(*_args)
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(method, *args)
|
46
|
+
module_name, action = method.to_s.split('_')
|
47
|
+
request(module_name, action, args[0] || {})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/tronscan/api.rb
CHANGED
@@ -21,13 +21,11 @@ module Tronscan
|
|
21
21
|
request = Net::HTTP::Get.new(uri.request_uri)
|
22
22
|
request['TRON-PRO-API-KEY'] = @api_key unless @api_key.nil?
|
23
23
|
|
24
|
-
|
24
|
+
response = http.request(request)
|
25
25
|
# Etherscan.logger.debug "Rsp: #{resp}"
|
26
|
-
|
26
|
+
raise response.body if response.code != '200'
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
resp
|
28
|
+
JSON.parse(response.body)
|
31
29
|
rescue StandardError => e
|
32
30
|
puts e.message
|
33
31
|
puts e.backtrace.inspect
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etherscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aki Wu
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/etherscan.rb
|
38
38
|
- lib/etherscan/api.rb
|
39
39
|
- lib/etherscan/version.rb
|
40
|
+
- lib/subscan/api.rb
|
40
41
|
- lib/tronscan/api.rb
|
41
42
|
homepage: https://github.com/wuminzhe/etherscan
|
42
43
|
licenses:
|