cns 0.1.0 → 0.1.5

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: a3567b16b6d9cf9dac846e37b985b35c92566980b0f6a30e9e1a0ce54a70172f
4
- data.tar.gz: 9f8b82cbb5b7da80a3272cbaba1bd705e32067c11611e9d0ecfcf239749a1fb0
3
+ metadata.gz: f9a77dc1d55c2f8f3cef855ed3c4d4c112329fc826e974b5dc978cd611d2861c
4
+ data.tar.gz: 7b9d18ba3237d293d35477a3eecd9d1d6a5c73e24ac622a4e6700e99840c4075
5
5
  SHA512:
6
- metadata.gz: 00c63ac5f9dab19932c42c201eb2a4d6504e0cf4e58094cf10be206f00d1af8f49a630adfd89c11cd6b24acc3de03814fbd1927fc82d9d0060cc60648b01754c
7
- data.tar.gz: 32fcc4a3703e86a6c00d936cbd10f7dc0bf39be48962867ea7786320189e74a862b3d78ed08a964f13134ab3206920ff5f901741b5b0f26c33cde41406b601fe
6
+ metadata.gz: ca5de038a0c25c62ae35ced9a7b369d08669fa0c6314decaeb2b827464e39aa56ac962aed851dc12ab9f2e067c10778d065c1cd7ef7c4016214d60142a0db5e1
7
+ data.tar.gz: e94f7cd2908da735457bdf86da6e83e216ed0f9a78d6f49abe054ac72b641d2563cf4c27797a2cb04ee871cbe177e2b25a7a1d4524e61cb7e36c0ee1e1b50c02
@@ -1,25 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.1.0)
4
+ cns (0.1.5)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
8
8
  thor
9
- yard
10
9
 
11
10
  GEM
12
11
  remote: https://rubygems.org/
13
12
  specs:
14
13
  addressable (2.7.0)
15
14
  public_suffix (>= 2.0.2, < 5.0)
15
+ ast (2.4.1)
16
+ backport (1.1.2)
17
+ benchmark (0.1.0)
16
18
  concurrent-ruby (1.1.7)
17
- curb (0.9.10)
19
+ curb (0.9.11)
18
20
  declarative (0.0.20)
19
21
  declarative-option (0.1.0)
20
- faraday (1.0.1)
22
+ e2mmap (0.1.0)
23
+ faraday (1.1.0)
21
24
  multipart-post (>= 1.2, < 3)
22
- google-api-client (0.44.2)
25
+ ruby2_keywords
26
+ google-api-client (0.50.0)
23
27
  addressable (~> 2.5, >= 2.5.1)
24
28
  googleauth (~> 0.9)
25
29
  httpclient (>= 2.8.1, < 3.0)
@@ -28,19 +32,19 @@ GEM
28
32
  retriable (>= 2.0, < 4.0)
29
33
  rexml
30
34
  signet (~> 0.12)
31
- google-cloud-bigquery (1.22.0)
35
+ google-cloud-bigquery (1.25.0)
32
36
  concurrent-ruby (~> 1.0)
33
- google-api-client (~> 0.33)
37
+ google-api-client (~> 0.47)
34
38
  google-cloud-core (~> 1.2)
35
39
  googleauth (~> 0.9)
36
40
  mini_mime (~> 1.0)
37
41
  google-cloud-core (1.5.0)
38
42
  google-cloud-env (~> 1.0)
39
43
  google-cloud-errors (~> 1.0)
40
- google-cloud-env (1.3.3)
44
+ google-cloud-env (1.4.0)
41
45
  faraday (>= 0.17.3, < 2.0)
42
46
  google-cloud-errors (1.0.1)
43
- googleauth (0.13.1)
47
+ googleauth (0.14.0)
44
48
  faraday (>= 0.17.3, < 2.0)
45
49
  jwt (>= 1.4, < 3.0)
46
50
  memoist (~> 0.16)
@@ -48,27 +52,75 @@ GEM
48
52
  os (>= 0.9, < 2.0)
49
53
  signet (~> 0.14)
50
54
  httpclient (2.8.3)
55
+ jaro_winkler (1.5.4)
51
56
  jwt (2.2.2)
57
+ kwalify (0.7.2)
58
+ maruku (0.7.3)
52
59
  memoist (0.16.2)
53
60
  mini_mime (1.0.2)
61
+ mini_portile2 (2.4.0)
54
62
  multi_json (1.15.0)
55
63
  multipart-post (2.1.1)
64
+ nokogiri (1.10.10)
65
+ mini_portile2 (~> 2.4.0)
56
66
  os (1.1.1)
67
+ parallel (1.20.1)
68
+ parser (2.7.2.0)
69
+ ast (~> 2.4.1)
70
+ psych (3.2.0)
57
71
  public_suffix (4.0.6)
72
+ rainbow (3.0.0)
58
73
  rake (12.3.3)
74
+ reek (6.0.2)
75
+ kwalify (~> 0.7.0)
76
+ parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
77
+ psych (~> 3.1)
78
+ rainbow (>= 2.0, < 4.0)
79
+ regexp_parser (2.0.0)
59
80
  representable (3.0.4)
60
81
  declarative (< 0.1.0)
61
82
  declarative-option (< 0.2.0)
62
83
  uber (< 0.2.0)
63
84
  retriable (3.1.2)
85
+ reverse_markdown (2.0.0)
86
+ nokogiri
64
87
  rexml (3.2.4)
88
+ rubocop (0.93.1)
89
+ parallel (~> 1.10)
90
+ parser (>= 2.7.1.5)
91
+ rainbow (>= 2.2.2, < 4.0)
92
+ regexp_parser (>= 1.8)
93
+ rexml
94
+ rubocop-ast (>= 0.6.0)
95
+ ruby-progressbar (~> 1.7)
96
+ unicode-display_width (>= 1.4.0, < 2.0)
97
+ rubocop-ast (1.2.0)
98
+ parser (>= 2.7.1.5)
99
+ ruby-progressbar (1.10.1)
100
+ ruby2_keywords (0.0.2)
65
101
  signet (0.14.0)
66
102
  addressable (~> 2.3)
67
103
  faraday (>= 0.17.3, < 2.0)
68
104
  jwt (>= 1.5, < 3.0)
69
105
  multi_json (~> 1.10)
106
+ solargraph (0.39.17)
107
+ backport (~> 1.1)
108
+ benchmark
109
+ bundler (>= 1.17.2)
110
+ e2mmap
111
+ jaro_winkler (~> 1.5)
112
+ maruku (~> 0.7, >= 0.7.3)
113
+ nokogiri (~> 1.9, >= 1.9.1)
114
+ parser (~> 2.3)
115
+ reverse_markdown (>= 1.0.5, < 3)
116
+ rubocop (~> 0.52)
117
+ thor (~> 1.0)
118
+ tilt (~> 2.0)
119
+ yard (~> 0.9, >= 0.9.24)
70
120
  thor (1.0.1)
121
+ tilt (2.0.10)
71
122
  uber (0.1.0)
123
+ unicode-display_width (1.7.0)
72
124
  yard (0.9.25)
73
125
 
74
126
  PLATFORMS
@@ -78,6 +130,10 @@ DEPENDENCIES
78
130
  bundler
79
131
  cns!
80
132
  rake (~> 12.0)
133
+ reek
134
+ rubocop
135
+ solargraph
136
+ yard
81
137
 
82
138
  BUNDLED WITH
83
139
  2.1.4
@@ -7,15 +7,14 @@ Gem::Specification.new do |spec|
7
7
  spec.version = Cns::VERSION
8
8
  spec.authors = ['Hernâni Rodrigues Vaz']
9
9
  spec.email = ['hernanirvaz@gmail.com']
10
-
11
- spec.summary = 'Arquiva transactions etherscan/greymass/bitcoinde/kraken/paymium/therock no bigquery.'
12
- spec.description = "#{spec.summary} Pode ajustar dias para reposicionamento temporal."
13
10
  spec.homepage = 'https://github.com/hernanirvaz/cns'
14
11
  spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
12
+ spec.summary = 'Arquiva transactions etherscan/greymass/bitcoinde/kraken/paymium/therock no bigquery.'
13
+ spec.description = "#{spec.summary} Pode ajustar dias para reposicionamento temporal."
16
14
 
15
+ spec.required_ruby_version = Gem::Requirement.new('~> 2.7')
17
16
  spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['yard.run'] = 'yard'
17
+ spec.metadata['yard.run'] = 'yard'
19
18
 
20
19
  # Specify which files should be added to the gem when it is released.
21
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -29,10 +28,13 @@ Gem::Specification.new do |spec|
29
28
 
30
29
  spec.add_development_dependency('bundler')
31
30
  spec.add_development_dependency('rake')
31
+ spec.add_development_dependency('reek')
32
+ spec.add_development_dependency('rubocop')
33
+ spec.add_development_dependency('solargraph')
34
+ spec.add_development_dependency('yard')
32
35
 
33
36
  spec.add_dependency('curb')
34
37
  spec.add_dependency('faraday')
35
38
  spec.add_dependency('google-cloud-bigquery')
36
39
  spec.add_dependency('thor')
37
- spec.add_dependency('yard')
38
40
  end
data/lib/cns.rb CHANGED
@@ -1,24 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require('thor')
4
+ require('cns/apibc')
5
+ require('cns/apice1')
6
+ require('cns/apice2')
7
+ require('cns/bigquery1')
8
+ require('cns/bigquery2')
9
+ require('cns/bigquery3')
10
+ require('cns/bigquery4')
11
+ require('cns/etherscan1')
12
+ require('cns/etherscan2')
13
+ require('cns/greymass1')
14
+ require('cns/greymass2')
15
+ require('cns/bitcoinde')
16
+ require('cns/kraken')
17
+ require('cns/paymium')
18
+ require('cns/therock')
4
19
  require('cns/version')
5
20
 
6
21
  module Cns
7
- # classe para erros desta gem
8
- class Erro < StandardError
9
- # @return [StandardError] personalizacao dos erros
10
- def initialize(msg)
11
- super(msg)
12
- end
13
- end
14
-
15
22
  # classe para carregar/mostrar dados transacoes eth & eos no bigquery
16
23
  class CLI < Thor
17
24
  desc 'work', 'carrega transacoes novas no bigquery'
18
25
  option :h, type: :hash, default: {}, desc: 'configuracao ajuste reposicionamento temporal'
19
26
  # carrega transacoes novas no bigquery
20
27
  def work
21
- p('Bct::Bigquery.new(options).processa_tudo')
28
+ Bigquery.new(options).processa_tudo
22
29
  end
23
30
 
24
31
  desc 'show', 'mostra resumo transacoes'
@@ -26,7 +33,7 @@ module Cns
26
33
  option :t, type: :boolean, default: false, desc: 'mostra transacoes todas ou somente novas'
27
34
  # mostra resumo transacoes
28
35
  def show
29
- p('Bct::Bigquery.new(options).mostra_tudo')
36
+ Bigquery.new(options).mostra_tudo
30
37
  end
31
38
 
32
39
  default_task :show
@@ -0,0 +1,280 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('faraday')
4
+ require('json')
5
+
6
+ # @author Hernani Rodrigues Vaz
7
+ module Cns
8
+ # classe para acesso dados blockchains
9
+ class Apibc
10
+ # @example account_es
11
+ # {
12
+ # status: '1',
13
+ # message: 'OK',
14
+ # result: [
15
+ # { account: '0x...', balance: '4000000000000000000' },
16
+ # { account: '0x...', balance: '87000000000000000000' }
17
+ # ]
18
+ # }
19
+ # @param [String] ads lista enderecos ETH (max 20)
20
+ # @param [Hash] par parametros base do pedido HTTP
21
+ # @return [Array<Hash>] lista enderecos e seus saldos
22
+ def account_es(ads, par = { module: 'account', action: 'balancemulti', tag: 'latest' })
23
+ JSON.parse(
24
+ (conn_es.get('api') do |o|
25
+ o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
26
+ o.params = par.merge(address: ads.join(','), apikey: ENV['ETHERSCAN_API_KEY'])
27
+ end).body,
28
+ symbolize_names: true
29
+ )[:result]
30
+ rescue StandardError
31
+ []
32
+ end
33
+
34
+ # @example account_gm
35
+ # {
36
+ # account_name: '...',
37
+ # head_block_num: 141_391_122,
38
+ # head_block_time: '2020-09-11T16:05:51.000',
39
+ # privileged: false,
40
+ # last_code_update: '1970-01-01T00:00:00.000',
41
+ # created: '2018-06-09T13:14:37.000',
42
+ #
43
+ # core_liquid_balance: '1232.0228 EOS',
44
+ # total_resources: { owner: '...', net_weight: '1000.1142 EOS', cpu_weight: '1000.1144 EOS', ram_bytes: 8148 },
45
+ #
46
+ # ram_quota: 9548,
47
+ # net_weight: 10_001_142,
48
+ # cpu_weight: 10_001_144,
49
+ # net_limit: { used: 0, available: 1_066_648_346, max: 1_066_648_346 },
50
+ # cpu_limit: { used: 338, available: 88_498, max: 88_836 },
51
+ # ram_usage: 3574,
52
+ # permissions: [
53
+ # {
54
+ # perm_name: 'active',
55
+ # parent: 'owner',
56
+ # required_auth: {
57
+ # threshold: 1, keys: [{ key: 'EOS...', weight: 1 }], accounts: [], waits: []
58
+ # }
59
+ # },
60
+ # {
61
+ # perm_name: 'owner',
62
+ # parent: '',
63
+ # required_auth: {
64
+ # threshold: 1, keys: [{ key: 'EOS...', weight: 1 }], accounts: [], waits: []
65
+ # }
66
+ # }
67
+ # ],
68
+ # self_delegated_bandwidth: { from: '...', to: '...', net_weight: '1000.1142 EOS', cpu_weight: '1000.1144 EOS' },
69
+ # refund_request: nil,
70
+ # voter_info: {
71
+ # owner: '...',
72
+ # proxy: '...',
73
+ # producers: [],
74
+ # staked: 20_002_286,
75
+ # last_vote_weight: '17172913021904.12109375000000000',
76
+ # proxied_vote_weight: '0.00000000000000000',
77
+ # is_proxy: 0,
78
+ # flags1: 0,
79
+ # reserved2: 0,
80
+ # reserved3: '0.0000 EOS'
81
+ # },
82
+ # rex_info: nil
83
+ # }
84
+ # @param [String] add endereco EOS
85
+ # @param [String] uri Uniform Resource Identifier do pedido HTTP
86
+ # @return [Hash] endereco e seus saldo/recursos
87
+ def account_gm(add, uri = '/v1/chain/get_account')
88
+ JSON.parse(
89
+ conn_gm.post(
90
+ uri, { account_name: add }.to_json, content_type: 'application/json'
91
+ ).body,
92
+ symbolize_names: true
93
+ )
94
+ rescue StandardError
95
+ { core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } }
96
+ end
97
+
98
+ # @example norml_es
99
+ # {
100
+ # status: '1',
101
+ # message: 'OK',
102
+ # result: [
103
+ # {
104
+ # blockNumber: '4984535',
105
+ # timeStamp: '1517094794',
106
+ # hash: '0x...',
107
+ # nonce: '10',
108
+ # blockHash: '0x...',
109
+ # transactionIndex: '17',
110
+ # from: '0x...',
111
+ # to: '0x...',
112
+ # value: '52627271000000000000',
113
+ # gas: '21000',
114
+ # gasPrice: '19000000000',
115
+ # isError: '0',
116
+ # txreceipt_status: '1',
117
+ # input: '0x',
118
+ # contractAddress: '',
119
+ # gasUsed: '21000',
120
+ # cumulativeGasUsed: '566293',
121
+ # confirmations: '5848660'
122
+ # },
123
+ # {}
124
+ # ]
125
+ # }
126
+ # @param [String] add endereco ETH
127
+ # @param [Integer] pag pagina transacoes
128
+ # @param [Array<Hash>] ary acumulador transacoes
129
+ # @param par (see account_es)
130
+ # @return [Array<Hash>] lista completa transacoes etherscan
131
+ def norml_es(add, pag = 0, ary = [], par = { module: 'account', action: 'txlist', offset: 10_000 })
132
+ r = JSON.parse(
133
+ (conn_es.get('api') do |o|
134
+ o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
135
+ o.params = par.merge(address: add, page: pag + 1, apikey: ENV['ETHERSCAN_API_KEY'])
136
+ end).body,
137
+ symbolize_names: true
138
+ )[:result]
139
+ r.count < 10_000 ? ary + r : norml_es(add, pag + 1, ary + r)
140
+ rescue StandardError
141
+ ary
142
+ end
143
+
144
+ # @example token_es
145
+ # {
146
+ # status: '1',
147
+ # message: 'OK',
148
+ # result: [
149
+ # {
150
+ # blockNumber: '3967652',
151
+ # timeStamp: '1499081515',
152
+ # hash: '0x registo duplicado com todos os dados iguais',
153
+ # nonce: '3',
154
+ # blockHash: '0x00a49e999036dc13dc6c4244bb1d51d3146fe7f00bfb500a7624d82e299c7328',
155
+ # from: '0xd0a6e6c54dbc68db5db3a091b171a77407ff7ccf',
156
+ # contractAddress: '0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0',
157
+ # to: '0x...',
158
+ # value: '0',
159
+ # tokenName: 'EOS',
160
+ # tokenSymbol: 'EOS',
161
+ # tokenDecimal: '18',
162
+ # transactionIndex: '83',
163
+ # gas: '173399',
164
+ # gasPrice: '21000000000',
165
+ # gasUsed: '173398',
166
+ # input: 'deprecated',
167
+ # cumulativeGasUsed: '7484878',
168
+ # confirmations: '3442641'
169
+ # },
170
+ # {}
171
+ # ]
172
+ # }
173
+ # @param (see norml_es)
174
+ # @return [Array<Hash>] lista completa token transfer events etherscan
175
+ def token_es(add, pag = 0, ary = [], par = { module: 'account', action: 'tokentx', offset: 10_000 })
176
+ # registos duplicados aparecem em token events (ver exemplo acima)
177
+ # -quando ha erros na blockchain (acho)
178
+ # -quando ha token events identicos no mesmo block (acho)
179
+ r = JSON.parse(
180
+ (conn_es.get('api') do |o|
181
+ o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
182
+ o.params = par.merge(address: add, page: pag + 1, apikey: ENV['ETHERSCAN_API_KEY'])
183
+ end).body,
184
+ symbolize_names: true
185
+ )[:result]
186
+ r.count < 10_000 ? ary + r : token_es(add, pag + 1, ary + r)
187
+ rescue StandardError
188
+ ary
189
+ end
190
+
191
+ # @example ledger_gm
192
+ # {
193
+ # actions: [
194
+ # {
195
+ # account_action_seq: 964,
196
+ # action_trace: {
197
+ # account_ram_deltas: [],
198
+ # act: {
199
+ # account: 'voicebestapp',
200
+ # authorization: [
201
+ # { actor: 'thetruevoice', permission: 'active' },
202
+ # { actor: 'voicebestapp', permission: 'active' }
203
+ # ],
204
+ # data: { from: 'voicebestapp', memo: '...', quantity: '1.0001 MESSAGE', to: '...' },
205
+ # hex_data: '...',
206
+ # name: 'transfer'
207
+ # },
208
+ # action_ordinal: 10,
209
+ # block_num: 141_345_345,
210
+ # block_time: '2020-09-11T09:44:04.500',
211
+ # closest_unnotified_ancestor_action_ordinal: 5,
212
+ # context_free: false,
213
+ # creator_action_ordinal: 5,
214
+ # elapsed: 6,
215
+ # producer_block_id: '...',
216
+ # receipt: {
217
+ # abi_sequence: 1,
218
+ # act_digest: '...',
219
+ # auth_sequence: [['thetruevoice', 6_778_215], ['voicebestapp', 435_346]],
220
+ # code_sequence: 1,
221
+ # global_sequence: 233_283_589_258,
222
+ # receiver: '...',
223
+ # recv_sequence: 927
224
+ # },
225
+ # receiver: '...',
226
+ # trx_id: '...'
227
+ # },
228
+ # block_num: 141_345_345,
229
+ # block_time: '2020-09-11T09:44:04.500',
230
+ # global_action_seq: 233_283_589_258,
231
+ # irreversible: true
232
+ # },
233
+ # {}
234
+ # ],
235
+ # head_block_num: 141_721_698,
236
+ # last_irreversible_block: 141_721_371
237
+ # }
238
+ # @param add (see account_gm)
239
+ # @param [Integer] pos posicao transacoes
240
+ # @param [Array<Hash>] ary acumulador transacoes
241
+ # @param uri (see account_gm)
242
+ # @return [Array<Hash>] lista completa transacoes greymass
243
+ def ledger_gm(add, pos = 0, ary = [], uri = '/v1/history/get_actions')
244
+ r = JSON.parse(
245
+ conn_gm.post(
246
+ uri, { account_name: add, pos: pos, offset: 100 }.to_json, content_type: 'application/json'
247
+ ).body,
248
+ symbolize_names: true
249
+ )[:actions]
250
+ r.count < 100 ? ary + r : ledger_gm(add, pos + r.count, ary + r)
251
+ rescue StandardError
252
+ ary
253
+ end
254
+
255
+ private
256
+
257
+ # @return [<Symbol>] adapter for the connection - default :net_http
258
+ def adapter
259
+ @adapter ||= Faraday.default_adapter
260
+ end
261
+
262
+ # @return [<Faraday::Connection>] connection object for etherscan
263
+ def conn_es
264
+ @conn_es ||=
265
+ Faraday.new(url: 'https://api.etherscan.io/') do |c|
266
+ c.request(:url_encoded)
267
+ c.adapter(adapter)
268
+ end
269
+ end
270
+
271
+ # @return [<Faraday::Connection>] connection object for greymass
272
+ def conn_gm
273
+ @conn_gm ||=
274
+ Faraday.new(url: 'https://eos.greymass.com') do |c|
275
+ c.request(:url_encoded)
276
+ c.adapter(adapter)
277
+ end
278
+ end
279
+ end
280
+ end