cns 0.1.3 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cns might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 201bcdd4553aed2ac96634df1b878a188a618e40ee407be8cb62f233e2056b6c
4
- data.tar.gz: 43b51397a37f3c1f1573387a6dcabb5233801c4e65892adb4aa2b8e2021a7e89
3
+ metadata.gz: 8e61b3461245de25a2e73914ac9e8afcfff01bc0598c679a41e4d4654f0a9ba9
4
+ data.tar.gz: e5265de933fd944aef41c0a30e00c53a761b543d6f262c1e19dbf0a7fc0983da
5
5
  SHA512:
6
- metadata.gz: 2154d5c336b50962e257a949aca642a495fe855e78ee6a75934a9357d532d37d93078bc703fb0fd4d2bf69b359756c674825893802ff1545cf2b9ec84cf70088
7
- data.tar.gz: f5ac977a8673340502ca590ca644d3fc8e9ae47e1ab5286b8916180d4b9a5ed021df387c2da17600027b6299799d5723a88de3fa908e6e03433a72c1977316ab
6
+ metadata.gz: c7327a29d73c059f50591553f942eaab9de060fe48d693c4e1623dab3c2886b785c5200d23f5b22ab1e55946e95a230abc968c00a917effb17af1de0b81a75d9
7
+ data.tar.gz: f4ae7e7b6be23c67ebe65a653a36af33154ad232e27d4358dced5638b2898b0e0bf2f122026d7f36445fdb48a469fbce4f495c98fdba7414b9490608ccfebdc7
@@ -0,0 +1,74 @@
1
+ ---
2
+ detectors:
3
+ TooManyStatements:
4
+ exclude:
5
+ - initialize
6
+ max_statements: 10
7
+ RepeatedConditional:
8
+ exclude:
9
+ - "Cns::Apice"
10
+ FeatureEnvy:
11
+ exclude:
12
+ - "Cns::Apice#deposit_unif"
13
+ - "Cns::Apice#withdrawal_unif"
14
+ - "Cns::Bigquery#etht_1val"
15
+ - "Cns::Bigquery#etht_2val"
16
+ - "Cns::Bigquery#etht_3val"
17
+ - "Cns::Bigquery#ethk_1val"
18
+ - "Cns::Bigquery#ethk_2val"
19
+ - "Cns::Bigquery#ethk_3val"
20
+ - "Cns::Bigquery#eost_1val"
21
+ - "Cns::Bigquery#eost_2val"
22
+ - "Cns::Bigquery#det_1val"
23
+ - "Cns::Bigquery#det_2val"
24
+ - "Cns::Bigquery#mtl_1val"
25
+ - "Cns::Bigquery#ust_1val"
26
+ - "Cns::Bigquery#frl_val"
27
+ - "Cns::Bigquery#usl_val"
28
+ - "Cns::Bitcoinde#formata_ledger"
29
+ - "Cns::Bitcoinde#formata_trades"
30
+ - "Cns::Etherscan#bq_bc"
31
+ - "Cns::Etherscan#formata_valores"
32
+ - "Cns::Etherscan#formata_endereco"
33
+ - "Cns::Etherscan#formata_transacao_norml"
34
+ - "Cns::Etherscan#formata_transacao_token"
35
+ - "Cns::Greymass#bq_bc"
36
+ - "Cns::Greymass#greymass_sl"
37
+ - "Cns::Greymass#formata_carteira"
38
+ - "Cns::Greymass#formata_ledger"
39
+ - "Cns::Greymass#filtrar_tx"
40
+ - "Cns::Beaconchain#base_bc"
41
+ - "Cns::Beaconchain#bq_bc"
42
+ - "Cns::Kraken#formata_ledger"
43
+ - "Cns::Kraken#formata_trades"
44
+ - "Cns::Paymium#formata_ledger"
45
+ - "Cns::Paymium#formata_uuid"
46
+ - "Cns::TheRock#formata_ledger"
47
+ - "Cns::TheRock#formata_saldos"
48
+ - "Cns::Beaconchain#formata_saldos"
49
+ - "Cns::Beaconchain#formata_endereco"
50
+ - "Cns::Beaconchain#formata_valores"
51
+ UtilityFunction:
52
+ exclude:
53
+ - "Cns::Apice#hus"
54
+ - "Cns::Bigquery#del_val"
55
+ - "Cns::Etherscan#ok?"
56
+ - "Cns::Greymass#ok?"
57
+ - "Cns::Beaconchain#itx"
58
+ - "Cns::Beaconchain#ok?"
59
+ NestedIterators:
60
+ exclude:
61
+ - "Cns::Etherscan#idk"
62
+ - "Cns::Etherscan#idt"
63
+ - "Cns::Etherscan#novtx"
64
+ - "Cns::Etherscan#novkx"
65
+ - "Cns::Etherscan#dados"
66
+ - "Cns::Etherscan#filtrar_tx"
67
+ - "Cns::Greymass#novax"
68
+ - "Cns::Greymass#idt"
69
+ - "Cns::Greymass#dados"
70
+ - "Cns::Paymium#kyl"
71
+ - "Cns::Paymium#ledger"
72
+ - "Cns::Beaconchain#dados"
73
+ - "Cns::Beaconchain#idb"
74
+ - "Cns::Beaconchain#nov"
@@ -1,12 +1,13 @@
1
+ ---
1
2
  AllCops:
2
3
  TargetRubyVersion: 2.7
3
4
  EnabledByDefault: true
4
5
 
5
6
  Style/Copyright:
6
- Enabled: false
7
+ Enabled: false
7
8
 
8
9
  Lint/ConstantResolution:
9
- Enabled: false
10
+ Enabled: false
10
11
 
11
12
  Style/ConstantVisibility:
12
- Enabled: false
13
+ Enabled: false
@@ -1,25 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.1.3)
4
+ cns (0.1.9)
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.1)
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.3.0)
24
+ faraday-net_http (~> 1.0)
21
25
  multipart-post (>= 1.2, < 3)
22
- google-api-client (0.45.0)
26
+ ruby2_keywords
27
+ faraday-net_http (1.0.0)
28
+ google-api-client (0.52.0)
23
29
  addressable (~> 2.5, >= 2.5.1)
24
30
  googleauth (~> 0.9)
25
31
  httpclient (>= 2.8.1, < 3.0)
@@ -28,19 +34,19 @@ GEM
28
34
  retriable (>= 2.0, < 4.0)
29
35
  rexml
30
36
  signet (~> 0.12)
31
- google-cloud-bigquery (1.23.0)
37
+ google-cloud-bigquery (1.25.0)
32
38
  concurrent-ruby (~> 1.0)
33
- google-api-client (~> 0.33)
39
+ google-api-client (~> 0.47)
34
40
  google-cloud-core (~> 1.2)
35
41
  googleauth (~> 0.9)
36
42
  mini_mime (~> 1.0)
37
43
  google-cloud-core (1.5.0)
38
44
  google-cloud-env (~> 1.0)
39
45
  google-cloud-errors (~> 1.0)
40
- google-cloud-env (1.3.3)
46
+ google-cloud-env (1.4.0)
41
47
  faraday (>= 0.17.3, < 2.0)
42
48
  google-cloud-errors (1.0.1)
43
- googleauth (0.13.1)
49
+ googleauth (0.14.0)
44
50
  faraday (>= 0.17.3, < 2.0)
45
51
  jwt (>= 1.4, < 3.0)
46
52
  memoist (~> 0.16)
@@ -48,28 +54,83 @@ GEM
48
54
  os (>= 0.9, < 2.0)
49
55
  signet (~> 0.14)
50
56
  httpclient (2.8.3)
57
+ jaro_winkler (1.5.4)
51
58
  jwt (2.2.2)
59
+ kramdown (2.3.0)
60
+ rexml
61
+ kramdown-parser-gfm (1.1.0)
62
+ kramdown (~> 2.0)
63
+ kwalify (0.7.2)
52
64
  memoist (0.16.2)
53
65
  mini_mime (1.0.2)
66
+ mini_portile2 (2.5.0)
54
67
  multi_json (1.15.0)
55
68
  multipart-post (2.1.1)
69
+ nokogiri (1.11.1)
70
+ mini_portile2 (~> 2.5.0)
71
+ racc (~> 1.4)
56
72
  os (1.1.1)
73
+ parallel (1.20.1)
74
+ parser (2.7.2.0)
75
+ ast (~> 2.4.1)
76
+ psych (3.3.0)
57
77
  public_suffix (4.0.6)
78
+ racc (1.5.2)
79
+ rainbow (3.0.0)
58
80
  rake (12.3.3)
81
+ reek (6.0.2)
82
+ kwalify (~> 0.7.0)
83
+ parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
84
+ psych (~> 3.1)
85
+ rainbow (>= 2.0, < 4.0)
86
+ regexp_parser (2.0.3)
59
87
  representable (3.0.4)
60
88
  declarative (< 0.1.0)
61
89
  declarative-option (< 0.2.0)
62
90
  uber (< 0.2.0)
63
91
  retriable (3.1.2)
92
+ reverse_markdown (2.0.0)
93
+ nokogiri
64
94
  rexml (3.2.4)
95
+ rubocop (1.7.0)
96
+ parallel (~> 1.10)
97
+ parser (>= 2.7.1.5)
98
+ rainbow (>= 2.2.2, < 4.0)
99
+ regexp_parser (>= 1.8, < 3.0)
100
+ rexml
101
+ rubocop-ast (>= 1.2.0, < 2.0)
102
+ ruby-progressbar (~> 1.7)
103
+ unicode-display_width (>= 1.4.0, < 2.0)
104
+ rubocop-ast (1.4.0)
105
+ parser (>= 2.7.1.5)
106
+ rubocop-rake (0.5.1)
107
+ rubocop
108
+ ruby-progressbar (1.11.0)
109
+ ruby2_keywords (0.0.2)
65
110
  signet (0.14.0)
66
111
  addressable (~> 2.3)
67
112
  faraday (>= 0.17.3, < 2.0)
68
113
  jwt (>= 1.5, < 3.0)
69
114
  multi_json (~> 1.10)
115
+ solargraph (0.40.1)
116
+ backport (~> 1.1)
117
+ benchmark
118
+ bundler (>= 1.17.2)
119
+ e2mmap
120
+ jaro_winkler (~> 1.5)
121
+ kramdown (~> 2.3)
122
+ kramdown-parser-gfm (~> 1.1)
123
+ parser (~> 2.3)
124
+ reverse_markdown (>= 1.0.5, < 3)
125
+ rubocop (>= 0.52)
126
+ thor (~> 1.0)
127
+ tilt (~> 2.0)
128
+ yard (~> 0.9, >= 0.9.24)
70
129
  thor (1.0.1)
130
+ tilt (2.0.10)
71
131
  uber (0.1.0)
72
- yard (0.9.25)
132
+ unicode-display_width (1.7.0)
133
+ yard (0.9.26)
73
134
 
74
135
  PLATFORMS
75
136
  ruby
@@ -78,6 +139,11 @@ DEPENDENCIES
78
139
  bundler
79
140
  cns!
80
141
  rake (~> 12.0)
142
+ reek
143
+ rubocop
144
+ rubocop-rake
145
+ solargraph
146
+ yard
81
147
 
82
148
  BUNDLED WITH
83
149
  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,14 @@ 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('rubocop-rake')
34
+ spec.add_development_dependency('solargraph')
35
+ spec.add_development_dependency('yard')
32
36
 
33
37
  spec.add_dependency('curb')
34
38
  spec.add_dependency('faraday')
35
39
  spec.add_dependency('google-cloud-bigquery')
36
40
  spec.add_dependency('thor')
37
- spec.add_dependency('yard')
38
41
  end
data/lib/cns.rb CHANGED
@@ -12,6 +12,8 @@ require('cns/etherscan1')
12
12
  require('cns/etherscan2')
13
13
  require('cns/greymass1')
14
14
  require('cns/greymass2')
15
+ require('cns/beaconchain1')
16
+ require('cns/beaconchain2')
15
17
  require('cns/bitcoinde')
16
18
  require('cns/kraken')
17
19
  require('cns/paymium')
@@ -36,13 +38,6 @@ module Cns
36
38
  Bigquery.new(options).mostra_tudo
37
39
  end
38
40
 
39
- desc 'nn', 'mostra resumo transacoes'
40
- # mostra resumo transacoes
41
- def nn
42
- c = Apice.new.ledger_fr
43
- p(c)
44
- end
45
-
46
41
  default_task :show
47
42
  end
48
43
  end
@@ -7,6 +7,17 @@ require('json')
7
7
  module Cns
8
8
  # classe para acesso dados blockchains
9
9
  class Apibc
10
+ # @param [String] uri ETH2 API
11
+ # @return [Array<Hash>] lista dados beaconchain
12
+ def data_bc(uri)
13
+ res = JSON.parse(conn_bc.get(uri).body, symbolize_names: true)[:data] || []
14
+ # calls are rate limited to 10 requests/minute/IP
15
+ sleep(3)
16
+ res.is_a?(Array) ? res : [res]
17
+ rescue StandardError
18
+ []
19
+ end
20
+
10
21
  # @example account_es
11
22
  # {
12
23
  # status: '1',
@@ -17,20 +28,17 @@ module Cns
17
28
  # ]
18
29
  # }
19
30
  # @param [String] ads lista enderecos ETH (max 20)
20
- # @param [Hash] par parametros base do pedido HTTP
21
31
  # @return [Array<Hash>] lista enderecos e seus saldos
22
- def account_es(ads, par = { module: 'account', action: 'balancemulti', tag: 'latest' })
32
+ def account_es(ads)
23
33
  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,
34
+ conn_es.get('/api', action: 'balancemulti', tag: 'latest', address: ads.join(',')).body,
28
35
  symbolize_names: true
29
36
  )[:result]
30
37
  rescue StandardError
31
38
  []
32
39
  end
33
40
 
41
+ # @example account_gm
34
42
  # @example account_gm
35
43
  # {
36
44
  # account_name: '...',
@@ -82,15 +90,9 @@ module Cns
82
90
  # rex_info: nil
83
91
  # }
84
92
  # @param [String] add endereco EOS
85
- # @param [String] uri Uniform Resource Identifier do pedido HTTP
86
93
  # @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
+ def account_gm(add)
95
+ JSON.parse(conn_gm.post('/v1/chain/get_account', { account_name: add }.to_json).body, symbolize_names: true)
94
96
  rescue StandardError
95
97
  { core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } }
96
98
  end
@@ -125,20 +127,17 @@ module Cns
125
127
  # }
126
128
  # @param [String] add endereco ETH
127
129
  # @param [Integer] pag pagina transacoes
128
- # @param [Array<Hash>] ary acumulador transacoes
129
- # @param par (see account_es)
130
+ # @param [Array<Hash>] aes acumulador transacoes
130
131
  # @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,
132
+ def norml_es(add, pag = 0, aes = [])
133
+ res = JSON.parse(
134
+ conn_es.get('/api', action: 'txlist', offset: 10_000, address: add, page: pag += 1).body,
137
135
  symbolize_names: true
138
136
  )[:result]
139
- r.count < 10_000 ? ary + r : norml_es(add, pag + 1, ary + r)
137
+ aes += res
138
+ res.count < 10_000 ? aes : norml_es(add, pag, aes)
140
139
  rescue StandardError
141
- ary
140
+ aes
142
141
  end
143
142
 
144
143
  # @example token_es
@@ -172,20 +171,18 @@ module Cns
172
171
  # }
173
172
  # @param (see norml_es)
174
173
  # @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 })
174
+ def token_es(add, pag = 0, aes = [])
176
175
  # registos duplicados aparecem em token events (ver exemplo acima)
177
176
  # -quando ha erros na blockchain (acho)
178
177
  # -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,
178
+ res = JSON.parse(
179
+ conn_es.get('/api', action: 'tokentx', offset: 10_000, address: add, page: pag += 1).body,
184
180
  symbolize_names: true
185
181
  )[:result]
186
- r.count < 10_000 ? ary + r : token_es(add, pag + 1, ary + r)
182
+ aes += res
183
+ res.count < 10_000 ? aes : token_es(add, pag, aes)
187
184
  rescue StandardError
188
- ary
185
+ aes
189
186
  end
190
187
 
191
188
  # @example ledger_gm
@@ -236,20 +233,17 @@ module Cns
236
233
  # last_irreversible_block: 141_721_371
237
234
  # }
238
235
  # @param add (see account_gm)
239
- # @param [Integer] pos posicao transacoes
240
- # @param [Array<Hash>] ary acumulador transacoes
241
- # @param uri (see account_gm)
236
+ # @param [Array<Hash>] agm acumulador transacoes
242
237
  # @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,
238
+ def ledger_gm(add, agm = [])
239
+ res = JSON.parse(
240
+ conn_gm.post('/v1/history/get_actions', { account_name: add, pos: agm.count, offset: 100 }.to_json).body,
248
241
  symbolize_names: true
249
242
  )[:actions]
250
- r.count < 100 ? ary + r : ledger_gm(add, pos + r.count, ary + r)
243
+ agm += res
244
+ res.count < 100 ? agm : ledger_gm(add, agm)
251
245
  rescue StandardError
252
- ary
246
+ agm
253
247
  end
254
248
 
255
249
  private
@@ -262,18 +256,31 @@ module Cns
262
256
  # @return [<Faraday::Connection>] connection object for etherscan
263
257
  def conn_es
264
258
  @conn_es ||=
265
- Faraday.new(url: 'https://api.etherscan.io/') do |c|
266
- c.request(:url_encoded)
267
- c.adapter(adapter)
259
+ Faraday.new(
260
+ url: 'https://api.etherscan.io',
261
+ params: { module: 'account', apikey: ENV['ETHERSCAN_API_KEY'] },
262
+ headers: { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
263
+ ) do |con|
264
+ con.request(:url_encoded)
265
+ con.adapter(adapter)
268
266
  end
269
267
  end
270
268
 
271
269
  # @return [<Faraday::Connection>] connection object for greymass
272
270
  def conn_gm
273
271
  @conn_gm ||=
274
- Faraday.new(url: 'https://eos.greymass.com') do |c|
275
- c.request(:url_encoded)
276
- c.adapter(adapter)
272
+ Faraday.new(url: 'https://eos.greymass.com', headers: { content_type: 'application/json' }) do |con|
273
+ con.request(:url_encoded)
274
+ con.adapter(adapter)
275
+ end
276
+ end
277
+
278
+ # @return [<Faraday::Connection>] connection object for beaconchain
279
+ def conn_bc
280
+ @conn_bc ||=
281
+ Faraday.new(url: 'https://beaconcha.in', headers: { accept: 'application/json' }) do |con|
282
+ con.request(:url_encoded)
283
+ con.adapter(adapter)
277
284
  end
278
285
  end
279
286
  end