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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e12314597d854f9d264641830082a829f3f99f40a49cbfa1283cac848527416
4
- data.tar.gz: 825813db2b4c6debd2cf9c96a59ebbe8f5aacf13cdb84f5cbd9ecd85f44fd814
3
+ metadata.gz: 7e554929b14bae7f3a3f2c5da47aa57775a4e1088dd8f108cfe84f2c857ae088
4
+ data.tar.gz: 833280f97f3d0649c0f12be779b93d0da8ee347681d22f96942b7b040486fb9d
5
5
  SHA512:
6
- metadata.gz: 3ddbff16ed0c4d471b68bdccd621b1bb6c0f7a70209e93aa5d340f131f0f2e194cb58410b8cb2e50106f91f5a8b68ea75e104f1981a4ef49f53ec1d39a627acc
7
- data.tar.gz: 368ab98f97fff3c59808fe6433029bc41b2dd59e60fb0776cfc8d8b863c5461bbec194040371ca9b4f584fcdb249b755903bf48163dc1527c5eb74ab6dda5e0d
6
+ metadata.gz: 7cb3a7981cf01a151b2e2ea262810f81096dc9ee3a7634b806118bbc947f628ddbab97446d474a7c1093b4f43f3b940f9958a847cd42178d85317c9ec80ffff4
7
+ data.tar.gz: 755c15c09278bd308ecd07c7359bed0677eea3d333b817fa2666e41788d9ce6e88c58446abeb0d4ffc81f478eafedfa1cbcf1f07f84563aba83515ffa8d5d33d
data/README.md CHANGED
@@ -6,7 +6,7 @@ Access to the API of etherscan.io and the compatible APIs.
6
6
  ## Installation
7
7
 
8
8
  ```bash
9
- gem 'etherscan', '~> 0.2.0'
9
+ gem 'etherscan', '~> 0.2.3'
10
10
  ```
11
11
 
12
12
  ```bash
data/lib/etherscan/api.rb CHANGED
@@ -33,7 +33,7 @@ module Etherscan
33
33
 
34
34
  def method_missing(method, *args)
35
35
  module_name, action = method.to_s.split('_')
36
- request(module_name, action, args[0])
36
+ request(module_name, action, args[0] || {})
37
37
  end
38
38
 
39
39
  #########################################
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Etherscan
4
- VERSION = "0.2.3"
4
+ VERSION = '0.2.4'
5
5
  end
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
- Etherscan::Api.new(url, api_key)
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')
@@ -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.3
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