etherscan 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/etherscan/api.rb +1 -1
- data/lib/etherscan/version.rb +1 -1
- data/lib/etherscan.rb +13 -2
- data/lib/tronscan/api.rb +56 -0
- 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: 7e554929b14bae7f3a3f2c5da47aa57775a4e1088dd8f108cfe84f2c857ae088
|
4
|
+
data.tar.gz: 833280f97f3d0649c0f12be779b93d0da8ee347681d22f96942b7b040486fb9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb3a7981cf01a151b2e2ea262810f81096dc9ee3a7634b806118bbc947f628ddbab97446d474a7c1093b4f43f3b940f9958a847cd42178d85317c9ec80ffff4
|
7
|
+
data.tar.gz: 755c15c09278bd308ecd07c7359bed0677eea3d333b817fa2666e41788d9ce6e88c58446abeb0d4ffc81f478eafedfa1cbcf1f07f84563aba83515ffa8d5d33d
|
data/README.md
CHANGED
data/lib/etherscan/api.rb
CHANGED
data/lib/etherscan/version.rb
CHANGED
data/lib/etherscan.rb
CHANGED
@@ -2,6 +2,7 @@ require 'json'
|
|
2
2
|
require 'logger'
|
3
3
|
require 'net/http'
|
4
4
|
require 'etherscan/api'
|
5
|
+
require 'tronscan/api'
|
5
6
|
|
6
7
|
require 'active_support'
|
7
8
|
require 'active_support/core_ext/string'
|
@@ -46,15 +47,25 @@ module Etherscan
|
|
46
47
|
'obnb' => 'https://api-opbnb.bscscan.com/api'
|
47
48
|
}
|
48
49
|
|
50
|
+
# https://tronscan.org/#/developer/api
|
51
|
+
TRON_CHAINS = {
|
52
|
+
'tron' => 'https://apilist.tronscanapi.com/api',
|
53
|
+
}
|
54
|
+
|
49
55
|
class << self
|
50
56
|
attr_accessor :logger
|
51
57
|
|
52
58
|
def api(chain_short_name, api_key = nil)
|
53
59
|
url = CHAINS[chain_short_name]
|
54
60
|
url = CHAINS[chain_short_name.underscore] if url.nil?
|
55
|
-
raise "Chain `#{chain_short_name}` is not supported. Only #{CHAINS.keys} are supported." if url.nil?
|
56
61
|
|
57
|
-
|
62
|
+
tron_url = TRON_CHAINS[chain_short_name]
|
63
|
+
tron_url = TRON_CHAINS[chain_short_name.underscore] if url.nil?
|
64
|
+
|
65
|
+
raise "Chain `#{chain_short_name}` is not supported. Only Etherscan [#{CHAINS.keys}] & Tronscan [#{TRON_CHAINS.keys}] are supported." if url.nil? && tron_url.nil?
|
66
|
+
|
67
|
+
return Etherscan::Api.new(url, api_key) if url
|
68
|
+
return Tronscan::Api.new(tron_url, api_key) if tron_url
|
58
69
|
end
|
59
70
|
|
60
71
|
# for example: Etherscan.eth('your_api_key')
|
data/lib/tronscan/api.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Tronscan
|
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 = nil, params = {})
|
9
|
+
action_path = action.nil? ? '' : "/#{action}"
|
10
|
+
|
11
|
+
params = params.reject { |_k, v| v.nil? } # filter out nil values
|
12
|
+
params_query = params.keys.map { |key| "#{key}=#{params[key]}" }.join('&').strip
|
13
|
+
params_query = '' if params_query.empty?
|
14
|
+
|
15
|
+
uri = URI "#{@url}/#{module_name}#{action_path}?#{params_query}"
|
16
|
+
Etherscan.logger.debug "Req: #{uri}"
|
17
|
+
|
18
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
19
|
+
http.use_ssl = (uri.scheme == 'https')
|
20
|
+
|
21
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
22
|
+
request['TRON-PRO-API-KEY'] = @api_key unless @api_key.nil?
|
23
|
+
|
24
|
+
resp = http.request(request).body
|
25
|
+
# Etherscan.logger.debug "Rsp: #{resp}"
|
26
|
+
resp = JSON.parse(resp)
|
27
|
+
|
28
|
+
# raise resp['result'] if resp['status'] == '0'
|
29
|
+
|
30
|
+
resp
|
31
|
+
rescue StandardError => e
|
32
|
+
puts e.message
|
33
|
+
puts e.backtrace.inspect
|
34
|
+
end
|
35
|
+
|
36
|
+
def respond_to_missing?(*_args)
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def method_missing(method, *args)
|
41
|
+
module_name, action = method.to_s.split('_')
|
42
|
+
request(module_name, action, args[0] || {})
|
43
|
+
end
|
44
|
+
|
45
|
+
# def contract_getcontractcreation(contractaddresses:)
|
46
|
+
# if contractaddresses.is_a? Array
|
47
|
+
# request('contract', 'getcontractcreation', contractaddresses: contractaddresses.join(','))
|
48
|
+
# elsif contractaddresses.is_a? String
|
49
|
+
# request('contract', 'getcontractcreation', contractaddresses: contractaddresses)
|
50
|
+
# else
|
51
|
+
# raise 'contractaddresses must be an array or a string'
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
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.2.
|
4
|
+
version: 0.2.4
|
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/tronscan/api.rb
|
40
41
|
homepage: https://github.com/wuminzhe/etherscan
|
41
42
|
licenses:
|
42
43
|
- MIT
|