etht 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd40aa4cd395e43e84e1e966de134790d849c95dd9ce5aae4214a88b8dca9d57
4
- data.tar.gz: 435af034f97a849f667635b38fc1fff7fb8cad63fe9bfd84ecce6d0a55a773a2
3
+ metadata.gz: 9ca8ae2c29d35644a3d72e1ed819048020838736539e71023d5b81a0808875a5
4
+ data.tar.gz: c40d028004ed756b4805eed8e89a71e0a7efc35de52bee891ebe7c00bc358abd
5
5
  SHA512:
6
- metadata.gz: 11fcca99b528324db5782efc2ad69c46cb4b3d458e746113ed76182bd48d7dac186675b8b5c7be26590a2feeaaa4c6aae164ccf1d8492a94ae5dc6557a52187c
7
- data.tar.gz: d0bf1915245f76f7a1c147789d7efea25fb3e98593892fe776044880e0c9849b3ee3b0a6c8830bb25fe0c7822d7c1f78aee28d65c53990852813373ba364b547
6
+ metadata.gz: 005a56ce7e56e95fa9bcff843e9077a129f3492e5aa149a78d7f184307a88bc68e058004159fddeabd04c5b41eacec5eae405445a8d091b41dcdf9e5dd81f761
7
+ data.tar.gz: 5707e919d084a23f8115b3516db8a3979555decb1b682245fba6249f31a46166ee8047687eeb3390eec0a9c59f8f8c4aa7e75d4ed09acff2d2f4a9b936b1bae0
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- etht (0.1.3)
5
- etherscan_api
4
+ etht (0.1.4)
5
+ faraday
6
6
  google-cloud-bigquery
7
+ json
7
8
  thor
8
9
  yard
9
10
 
@@ -15,9 +16,6 @@ GEM
15
16
  concurrent-ruby (1.1.7)
16
17
  declarative (0.0.20)
17
18
  declarative-option (0.1.0)
18
- etherscan_api (0.4.0)
19
- faraday
20
- json (~> 2.1)
21
19
  faraday (1.0.1)
22
20
  multipart-post (>= 1.2, < 3)
23
21
  google-api-client (0.43.0)
@@ -30,8 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'bundler'
31
31
  spec.add_development_dependency 'rake'
32
32
 
33
- spec.add_dependency 'etherscan_api'
33
+ spec.add_dependency 'faraday'
34
34
  spec.add_dependency 'google-cloud-bigquery'
35
+ spec.add_dependency 'json'
35
36
  spec.add_dependency 'thor'
36
37
  spec.add_dependency 'yard'
37
38
  end
data/exe/etht CHANGED
@@ -1,3 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "etht"
4
+ require 'etht'
5
+
6
+ Etht::CLI.start(ARGV)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'thor'
4
4
  require 'etht/bigquery'
5
+ require 'etht/etherscan'
5
6
  require 'etht/version'
6
7
 
7
8
  # @author Hernani Rodrigues Vaz
@@ -9,6 +10,12 @@ module Etht
9
10
  ID = `whoami`.chomp
10
11
 
11
12
  class Error < StandardError; end
13
+ # class Exception < StandardError
14
+ class Exception < StandardError
15
+ def initialize(message)
16
+ super(message)
17
+ end
18
+ end
12
19
 
13
20
  # CLI para carregar etherscan comuns no bigquery
14
21
  class CLI < Thor
@@ -17,13 +24,13 @@ module Etht
17
24
  option :m, type: :boolean, default: false, desc: 'apaga linhas existencia multipla'
18
25
  # processa etherscan
19
26
  def work
20
- Bigquery.new({ e: options[:e], m: options[:m], i: true }).processa_etherscan
27
+ Bigquery.new({ e: options[:e], m: options[:m], i: true }).processa_eth
21
28
  end
22
29
 
23
30
  desc 'show', 'mostra dados do etherscan'
24
31
  # show etherscan
25
32
  def show
26
- Bigquery.new.processa_etherscan
33
+ Bigquery.new.processa_eth
27
34
  end
28
35
 
29
36
  default_task :show
@@ -1,13 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'etherscan'
4
3
  require 'google/cloud/bigquery'
5
4
 
6
- # config/initializers/etherscan.rb
7
- Etherscan.configure do |config|
8
- config.key = 'QA14GAMNM3AJIX8IEGA8MHEHBHJDTDSBPX'
9
- end
10
-
5
+ # @author Hernani Rodrigues Vaz
11
6
  module Etht
12
7
  DF = '%Y-%m-%d'
13
8
  DI = '%Y-%m-%d %H:%M:%S'
@@ -16,10 +11,8 @@ module Etht
16
11
  class Bigquery
17
12
  # @return [Google::Cloud::Bigquery] API bigquery
18
13
  attr_reader :apibq
19
- # @return [Roo::CSV] folha calculo a processar
20
- attr_reader :folha
21
- # @return [Hash<Symbol, Boolean>] opcoes trabalho com linhas
22
- attr_reader :linha
14
+ # @return [Etherscan::Api] API etherscan
15
+ attr_reader :apies
23
16
 
24
17
  # @return [Array] row folha calculo em processamento
25
18
  attr_reader :row
@@ -34,14 +27,19 @@ module Etht
34
27
  # @option ops [Boolean] :m (false) apaga linhas existencia multipla?
35
28
  # @option ops [Boolean] :i (false) insere linha nova?
36
29
  # @return [Bigquery] acesso folhas calculo bloks.io & correspondente bigquery dataset
37
- def initialize(csv = '', ops = { e: false, m: false, i: false })
30
+ def initialize(ops = { e: false, m: false, i: false })
38
31
  # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
39
32
  # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
40
33
  @apibq = Google::Cloud::Bigquery.new
41
- @folha = Roo::CSV.new(csv) if csv.size.positive?
34
+ @apies = Etht::Accounts.new
42
35
  @linha = ops
43
36
  end
44
37
 
38
+ def processa_eth
39
+ contract_address = '0xfc325129a11fab241287e42a9f04a74f14077b77'
40
+ p apies.normal_transactions(contract_address)
41
+ end
42
+
45
43
  # cria job bigquery & verifica execucao
46
44
  #
47
45
  # @param [String] sql a executar
@@ -0,0 +1,177 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ # @author Hernani Rodrigues Vaz
7
+ module Etht
8
+ # class Config
9
+ class Config
10
+ attr_accessor :key, :secret, :url, :raise_exceptions
11
+ attr_writer :logger
12
+
13
+ def logger
14
+ @logger ||= Logger.new(STDERR)
15
+ end
16
+ end
17
+
18
+ # class Api
19
+ class Api
20
+ attr_reader :connection
21
+
22
+ def initialize(params = {})
23
+ @connection = Etht::Client.new(params)
24
+ end
25
+
26
+ def get(params)
27
+ response = connection.get(params)
28
+ response['result']
29
+ end
30
+ end
31
+
32
+ # class Client
33
+ class Client
34
+ URL = 'https://api.etherscan.io/'
35
+ HEADERS = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }.freeze
36
+
37
+ attr_reader :key, :url, :user_agent, :headers, :raise_exceptions
38
+ attr_writer :adapter, :conn
39
+
40
+ def initialize(params = {})
41
+ @key = params.fetch(:key, Etht.config.key)
42
+ @url = params.fetch(:url, Etht.config.url || URL)
43
+ @adapter = params.fetch(:adapter, adapter)
44
+ @conn = params.fetch(:conn, conn)
45
+ @user_agent = params.fetch(:user_agent, "etherscan/#{Etht::VERSION};ruby")
46
+ @headers = HEADERS.merge('User-Agent' => @user_agent)
47
+ @raise_exceptions = params.fetch(:raise_exceptions, Etht.config.raise_exceptions || true)
48
+ yield self if block_given?
49
+ end
50
+
51
+ def get(params = {})
52
+ endpoint = 'api'
53
+ merged_params = params.merge({ apikey: key })
54
+ response = conn.get(endpoint) do |req|
55
+ req.headers = headers
56
+ req.params = merged_params
57
+ end
58
+ raise Etht::Exception, response if raise_exceptions? && response.status != 200
59
+
60
+ JSON(response.body)
61
+ end
62
+
63
+ def conn
64
+ @conn ||= Faraday.new(url: @url) do |conn|
65
+ conn.request :url_encoded
66
+ conn.adapter adapter
67
+ end
68
+ end
69
+
70
+ def adapter
71
+ @adapter ||= Faraday.default_adapter
72
+ end
73
+
74
+ def raise_exceptions?
75
+ @raise_exceptions
76
+ end
77
+ end
78
+
79
+ # class Accounts < Etht::Api
80
+ class Accounts < Api
81
+ def address_balance(address)
82
+ params = {
83
+ module: 'account', action: 'balance',
84
+ address: address, tag: 'latest'
85
+ }
86
+ get(params)
87
+ end
88
+
89
+ def multi_address_balance(addresses)
90
+ raise Etht::Exception, 'up to 20 accounts in a single batch' if addresses.size > 20
91
+
92
+ params = {
93
+ module: 'account', action: 'balancemulti',
94
+ address: addresses.join(','), tag: 'latest'
95
+ }
96
+ get(params)
97
+ end
98
+
99
+ # Get a list of 'Normal' Transactions By Address
100
+ # if page is not defined Returns up to 10000 last transactions
101
+ # Available args: start_block, end_block, sort, page, offset
102
+ # @param sort 'asc' -> ascending order, 'des' -> descending order
103
+ # @param start_block starting blockNo to retrieve results
104
+ # @param end_block ending blockNo to retrieve results
105
+ # @param page Paginated result <page number>
106
+ # @param offset max records to return
107
+ def normal_transactions(address, args = {})
108
+ action = 'txlist'
109
+ transcations(action, address, nil, args)
110
+ end
111
+
112
+ # Get a list of 'Internal' Transactions By Address
113
+ # Available args: start_block, end_block, sort, page, offset
114
+ def internal_transactions(address, args = {})
115
+ action = 'txlistinternal'
116
+ transcations(action, address, nil, args)
117
+ end
118
+
119
+ # Get a list of "ERC20 - Token Transfer Events"
120
+ # @param contract_address Token address (set nil to get a list of all ERC20 transactions)
121
+ # @param address Address for ERC20 transactions (optional)
122
+ # Available args: start_block, end_block, sort, page, offset
123
+ def token_transactions(contract_address, address = nil, args = {})
124
+ raise Etht::Exception, 'contract or address must be defined' if (contract_address || address).nil?
125
+
126
+ action = 'tokentx'
127
+ transcations(action, address, contract_address, args)
128
+ end
129
+
130
+ private
131
+
132
+ def transcations(action, address, contract_address, args)
133
+ params = {
134
+ module: 'account', action: action,
135
+ address: address, contractaddress: contract_address,
136
+ startblock: args[:start_block], endblock: args[:end_block],
137
+ page: args[:page], offset: args[:offset], sort: args[:sort]
138
+ }.reject { |_, v| v.nil? }
139
+ get(params)
140
+ end
141
+ end
142
+
143
+ # class Tokens < Etht::Api
144
+ class Tokens < Api
145
+ def total_supply(contract_address)
146
+ params = {
147
+ module: 'stats', action: 'tokensupply',
148
+ contractaddress: contract_address
149
+ }
150
+ get(params)
151
+ end
152
+
153
+ def balance(address, contract_address)
154
+ params = {
155
+ module: 'account', action: 'tokenbalance',
156
+ address: address, contractaddress: contract_address
157
+ }
158
+ get(params)
159
+ end
160
+ end
161
+
162
+ def self.configure
163
+ yield config
164
+ end
165
+
166
+ def self.config
167
+ @config ||= Config.new
168
+ end
169
+
170
+ def self.logger
171
+ config.logger
172
+ end
173
+
174
+ configure do |config|
175
+ config.key = ENV['ETHERSCAN_API_KEY']
176
+ end
177
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Etht
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etht
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: etherscan_api
42
+ name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: thor
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +130,7 @@ files:
116
130
  - exe/etht
117
131
  - lib/etht.rb
118
132
  - lib/etht/bigquery.rb
133
+ - lib/etht/etherscan.rb
119
134
  - lib/etht/version.rb
120
135
  homepage: https://github.com/hernanirvaz/etht
121
136
  licenses: