cns 0.3.0 → 0.3.2

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: 102edda2af2ea68bbe58ceb856e54ad0662649d59dc05768dcac0434458cbfc0
4
- data.tar.gz: dd611d1c1d5c403b0763c2f9605ac8305b707165ca996533a87956c3a84f0cfb
3
+ metadata.gz: ba2ef03e5bc93d772b32c6bbf375ae4322778e4ff00ca43fddf5c041924f4597
4
+ data.tar.gz: 63c40eebbcb8ca9425153db0a6113659b1ef7f3b16f00b3faa7153e1af04d79d
5
5
  SHA512:
6
- metadata.gz: 4da538113768e3ed1a18aea93055f33244946667ac8c8e38efacc24fc2d09d19173b61d18cc6fb7b05a494efe1dc583960bc57cc71c0b678918bfda20b0f3fba
7
- data.tar.gz: ed72048cf2b2515a5092b82a940667deb3dfea9de00805a5b399f17814576ab4d6e76be165cc2566ff36da615c63a3ba41d7345e287d33ec2a4fb8ed87bb03d4
6
+ metadata.gz: c32420b68e4ab9e8b4015b2ad2bf55d6b668da22a7ef58e71b57deb6a908961f2050057c3d7bb80b189fc13b365d239282e9aefce7beca59a7534388431cd2dd
7
+ data.tar.gz: bb370c40be2ed5ae0b3da752270ddbe44746e9f584c1a14715e23a76a5aa0b3c5431e9587504c64d074ad49c89c65b78bda6cad8580527842f1d1862e4940836
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.3.0)
4
+ cns (0.3.2)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
@@ -18,15 +18,14 @@ GEM
18
18
  concurrent-ruby (1.1.10)
19
19
  curb (1.0.1)
20
20
  declarative (0.0.20)
21
- diff-lcs (1.5.0)
22
21
  e2mmap (0.1.0)
23
22
  faraday (2.6.0)
24
23
  faraday-net_http (>= 2.0, < 3.1)
25
24
  ruby2_keywords (>= 0.0.4)
26
- faraday-net_http (3.0.1)
27
- google-apis-bigquery_v2 (0.41.0)
25
+ faraday-net_http (3.0.2)
26
+ google-apis-bigquery_v2 (0.42.0)
28
27
  google-apis-core (>= 0.9.0, < 2.a)
29
- google-apis-core (0.9.0)
28
+ google-apis-core (0.9.1)
30
29
  addressable (~> 2.5, >= 2.5.1)
31
30
  googleauth (>= 0.16.2, < 2.a)
32
31
  httpclient (>= 2.8.1, < 3.a)
@@ -47,7 +46,7 @@ GEM
47
46
  google-cloud-env (1.6.0)
48
47
  faraday (>= 0.17.3, < 3.0)
49
48
  google-cloud-errors (1.3.0)
50
- googleauth (1.2.0)
49
+ googleauth (1.3.0)
51
50
  faraday (>= 0.17.3, < 3.a)
52
51
  jwt (>= 1.4, < 3.0)
53
52
  memoist (~> 0.16)
@@ -56,7 +55,6 @@ GEM
56
55
  signet (>= 0.16, < 2.a)
57
56
  httpclient (2.8.3)
58
57
  jaro_winkler (1.5.4)
59
- json (2.6.2)
60
58
  jwt (2.5.0)
61
59
  kramdown (2.4.0)
62
60
  rexml
@@ -66,19 +64,21 @@ GEM
66
64
  memoist (0.16.2)
67
65
  mini_mime (1.1.2)
68
66
  multi_json (1.15.0)
69
- nokogiri (1.13.8-x86_64-linux)
67
+ nokogiri (1.13.9-x86_64-linux)
70
68
  racc (~> 1.4)
71
69
  os (1.1.4)
72
70
  parallel (1.22.1)
73
- parser (3.1.2.1)
71
+ parser (2.7.2.0)
74
72
  ast (~> 2.4.1)
73
+ psych (3.3.4)
75
74
  public_suffix (5.0.0)
76
75
  racc (1.6.0)
77
76
  rainbow (3.1.1)
78
77
  rake (12.3.3)
79
- reek (6.1.1)
78
+ reek (6.0.2)
80
79
  kwalify (~> 0.7.0)
81
- parser (~> 3.1.0)
80
+ parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
81
+ psych (~> 3.1)
82
82
  rainbow (>= 2.0, < 4.0)
83
83
  regexp_parser (2.6.0)
84
84
  representable (3.2.0)
@@ -89,20 +89,22 @@ GEM
89
89
  reverse_markdown (2.1.1)
90
90
  nokogiri
91
91
  rexml (3.2.5)
92
- rubocop (1.36.0)
93
- json (~> 2.3)
92
+ rubocop (1.7.0)
94
93
  parallel (~> 1.10)
95
- parser (>= 3.1.2.1)
94
+ parser (>= 2.7.1.5)
96
95
  rainbow (>= 2.2.2, < 4.0)
97
96
  regexp_parser (>= 1.8, < 3.0)
98
- rexml (>= 3.2.5, < 4.0)
99
- rubocop-ast (>= 1.20.1, < 2.0)
97
+ rexml
98
+ rubocop-ast (>= 1.2.0, < 2.0)
100
99
  ruby-progressbar (~> 1.7)
101
- unicode-display_width (>= 1.4.0, < 3.0)
102
- rubocop-ast (1.21.0)
103
- parser (>= 3.1.1.0)
100
+ unicode-display_width (>= 1.4.0, < 2.0)
101
+ rubocop-ast (1.4.1)
102
+ parser (>= 2.7.1.5)
104
103
  rubocop-rake (0.6.0)
105
104
  rubocop (~> 1.0)
105
+ ruby-lint (2.3.1)
106
+ parser (~> 2.2)
107
+ slop (~> 3.4, >= 3.4.7)
106
108
  ruby-progressbar (1.11.0)
107
109
  ruby2_keywords (0.0.5)
108
110
  signet (0.17.0)
@@ -110,16 +112,16 @@ GEM
110
112
  faraday (>= 0.17.5, < 3.a)
111
113
  jwt (>= 1.5, < 3.0)
112
114
  multi_json (~> 1.10)
113
- solargraph (0.47.2)
114
- backport (~> 1.2)
115
+ slop (3.6.0)
116
+ solargraph (0.40.1)
117
+ backport (~> 1.1)
115
118
  benchmark
116
119
  bundler (>= 1.17.2)
117
- diff-lcs (~> 1.4)
118
120
  e2mmap
119
121
  jaro_winkler (~> 1.5)
120
122
  kramdown (~> 2.3)
121
123
  kramdown-parser-gfm (~> 1.1)
122
- parser (~> 3.0)
124
+ parser (~> 2.3)
123
125
  reverse_markdown (>= 1.0.5, < 3)
124
126
  rubocop (>= 0.52)
125
127
  thor (~> 1.0)
@@ -129,7 +131,7 @@ GEM
129
131
  tilt (2.0.11)
130
132
  trailblazer-option (0.1.2)
131
133
  uber (0.1.0)
132
- unicode-display_width (2.3.0)
134
+ unicode-display_width (1.8.0)
133
135
  webrick (1.7.0)
134
136
  yard (0.9.28)
135
137
  webrick (~> 1.7.0)
@@ -144,6 +146,7 @@ DEPENDENCIES
144
146
  reek
145
147
  rubocop
146
148
  rubocop-rake
149
+ ruby-lint
147
150
  solargraph
148
151
  yard
149
152
 
data/cns.gemspec CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency('reek')
32
32
  spec.add_development_dependency('rubocop')
33
33
  spec.add_development_dependency('rubocop-rake')
34
+ spec.add_development_dependency('ruby-lint')
34
35
  spec.add_development_dependency('solargraph')
35
36
  spec.add_development_dependency('yard')
36
37
 
data/lib/cns/apibc.rb CHANGED
@@ -38,7 +38,6 @@ module Cns
38
38
  []
39
39
  end
40
40
 
41
- # @example account_gm
42
41
  # @example account_gm
43
42
  # {
44
43
  # account_name: '...',
@@ -128,7 +127,7 @@ module Cns
128
127
  # @param [String] add endereco ETH
129
128
  # @param [Integer] pag pagina transacoes
130
129
  # @param [Array<Hash>] aes acumulador transacoes
131
- # @return [Array<Hash>] lista completa transacoes etherscan
130
+ # @return [Array<Hash>] lista transacoes normais etherscan
132
131
  def norml_es(add, pag = 0, aes = [])
133
132
  res = JSON.parse(
134
133
  conn_es.get('/api', action: 'txlist', offset: 10_000, address: add, page: pag += 1).body,
@@ -140,6 +139,73 @@ module Cns
140
139
  aes
141
140
  end
142
141
 
142
+ # @example inter_es
143
+ # {
144
+ # status: '1',
145
+ # message: 'OK',
146
+ # result: [
147
+ # {
148
+ # blockNumber: '15592786',
149
+ # timeStamp: '1663896779',
150
+ # hash: '0x...',
151
+ # from: '0x...',
152
+ # to: '0x...',
153
+ # value: '22000000000000000',
154
+ # contractAddress: '',
155
+ # input: '',
156
+ # type: 'call',
157
+ # gas: '2300',
158
+ # gasUsed: '0',
159
+ # traceId: '0_1_1',
160
+ # isError: '0',
161
+ # errCode: ''
162
+ # }
163
+ # ]
164
+ # }
165
+ # @param (see norml_es)
166
+ # @return [Array<Hash>] lista transacoes internas etherscan
167
+ def inter_es(add, pag = 0, aes = [])
168
+ res = JSON.parse(
169
+ conn_es.get('/api', action: 'txlistinternal', offset: 10_000, address: add, page: pag += 1).body,
170
+ symbolize_names: true
171
+ )[:result]
172
+ aes += res
173
+ res.count < 10_000 ? aes : inter_es(add, pag, aes)
174
+ rescue StandardError
175
+ aes
176
+ end
177
+
178
+ # @example block_es
179
+ # {
180
+ # status: '1',
181
+ # message: 'OK',
182
+ # result: [
183
+ # { blockNumber: '15737070', timeStamp: '1665638459', blockReward: '8922867945448231' },
184
+ # { blockNumber: '15592786', timeStamp: '1663896779', blockReward: '44997990286623752' },
185
+ # { blockNumber: '15570222', timeStamp: '1663622819', blockReward: '261211525682683684' },
186
+ # { blockNumber: '15568554', timeStamp: '1663602539', blockReward: '41993833217879559' }
187
+ # ]
188
+ # }
189
+ # @param (see norml_es)
190
+ # @return [Array<Hash>] lista blocos etherscan
191
+ def block_es(add, pag = 0, aes = [])
192
+ res = JSON.parse(
193
+ conn_es.get(
194
+ '/api',
195
+ action: 'getminedblocks',
196
+ blocktype: 'blocks',
197
+ offset: 10_000,
198
+ address: add,
199
+ page: pag += 1
200
+ ).body,
201
+ symbolize_names: true
202
+ )[:result]
203
+ aes += res
204
+ res.count < 10_000 ? aes : block_es(add, pag, aes)
205
+ rescue StandardError
206
+ aes
207
+ end
208
+
143
209
  # @example token_es
144
210
  # {
145
211
  # status: '1',
@@ -170,7 +236,7 @@ module Cns
170
236
  # ]
171
237
  # }
172
238
  # @param (see norml_es)
173
- # @return [Array<Hash>] lista completa token transfer events etherscan
239
+ # @return [Array<Hash>] lista token transfer events etherscan
174
240
  def token_es(add, pag = 0, aes = [])
175
241
  # registos duplicados aparecem em token events (ver exemplo acima)
176
242
  # -quando ha erros na blockchain (acho)
@@ -258,7 +324,7 @@ module Cns
258
324
  @conn_es ||=
259
325
  Faraday.new(
260
326
  url: 'https://api.etherscan.io',
261
- params: { module: 'account', apikey: ENV['ETHERSCAN_API_KEY'] },
327
+ params: { module: 'account', apikey: ENV.fetch('ETHERSCAN_API_KEY', nil) },
262
328
  headers: { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
263
329
  ) do |con|
264
330
  con.request(:url_encoded)
@@ -16,11 +16,7 @@ module Cns
16
16
  # @param [Hash] hjn dados juntos bigquery & beaconchain
17
17
  # @return [String] texto formatado dum validador
18
18
  def formata_validador(hjn)
19
- format(
20
- '%<s1>-5.5s %<s2>-34.34s ',
21
- s1: hjn[:id],
22
- s2: formata_endereco(hjn[:ax], 34)
23
- ) + formata_valores(hjn)
19
+ format('%<s1>-5.5s %<s2>-34.34s ', s1: hjn[:id], s2: formata_endereco(hjn[:ax], 34)) + formata_valores(hjn)
24
20
  end
25
21
 
26
22
  # @param (see formata_validador)
@@ -48,8 +44,12 @@ module Cns
48
44
  # @param [Integer] max chars a mostrar
49
45
  # @return [String] pubkey formatada
50
46
  def formata_endereco(add, max)
51
- int = Integer((max - 2) / 2)
52
- max < 7 ? 'erro' : "#{add[0, int - 3]}..#{add[-int - 3..]}"
47
+ return 'erro' if max < 7
48
+
49
+ max -= 2
50
+ ini = Integer(max / 2)
51
+ inf = max % 2
52
+ "#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
53
53
  end
54
54
 
55
55
  # @example
@@ -68,7 +68,7 @@ module Cns
68
68
  format(
69
69
  '%<vi>5i %<vl>17.6f %<ep>6i %<id>9i',
70
70
  vi: idx,
71
- vl: (hbh[:balance].to_d / 10**9).round(10),
71
+ vl: (hbh[:balance].to_d / (10**9)).round(10),
72
72
  ep: epc,
73
73
  id: itx(epc, idx)
74
74
  )
data/lib/cns/bigquery1.rb CHANGED
@@ -38,7 +38,7 @@ module Cns
38
38
  apimt.mostra_resumo
39
39
  apies.mostra_resumo
40
40
  apigm.mostra_resumo
41
- apibc.mostra_resumo
41
+ # apibc.mostra_resumo
42
42
  end
43
43
 
44
44
  # insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain no bigquery
@@ -48,7 +48,15 @@ module Cns
48
48
  processa_frmt
49
49
  processa_eth
50
50
  processa_eos
51
- processa_bc
51
+ # processa_bc
52
+ end
53
+
54
+ # insere transacoes blockchain novas nas tabelas etht (norml), ethi (internas), ethp (block), ethk (token)
55
+ def processa_eth
56
+ puts(format("%<n>4i TRANSACOES ETH NORMAIS\tINSERIDAS etht", n: apies.novtx.empty? ? 0 : dml(etht_ins)))
57
+ puts(format("%<n>4i TRANSACOES ETH INTERNAS\tINSERIDAS ethi", n: apies.novix.empty? ? 0 : dml(ethi_ins)))
58
+ puts(format("%<n>4i TRANSACOES ETH BLOCK\tINSERIDAS ethp", n: apies.novpx.empty? ? 0 : dml(ethp_ins)))
59
+ puts(format("%<n>4i TOKENS\tETH\t\tINSERIDAS ethk", n: apies.novkx.empty? ? 0 : dml(ethk_ins)))
52
60
  end
53
61
 
54
62
  private
@@ -71,12 +79,6 @@ module Cns
71
79
  puts(format("%<n>4i LEDGER\tTHEROCK\t\tINSERIDAS mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
72
80
  end
73
81
 
74
- # insere transacoes blockchain novas nas tabelas etht (norml), ethk (token)
75
- def processa_eth
76
- puts(format("%<n>4i TRANSACOES\tETH\t\tINSERIDAS etht", n: apies.novtx.empty? ? 0 : dml(etht_ins)))
77
- puts(format("%<n>4i TOKENS\tETH\t\tINSERIDAS ethk", n: apies.novkx.empty? ? 0 : dml(ethk_ins)))
78
- end
79
-
80
82
  # insere transacoes blockchain novas na tabela eos
81
83
  def processa_eos
82
84
  puts(format("%<n>4i TRANSACOES\tEOS\t\tINSERIDAS eos ", n: apigm.novax.empty? ? 0 : dml(eost_ins)))
data/lib/cns/bigquery2.rb CHANGED
@@ -24,6 +24,8 @@ module Cns
24
24
  {
25
25
  wb: sql("select * from #{BD}.walletEth order by 2"),
26
26
  nt: sql("select itx,iax from #{BD}.ethtx"),
27
+ ni: sql("select itx,iax from #{BD}.ethix"),
28
+ np: sql("select itx,iax from #{BD}.ethpx"),
27
29
  nk: sql("select itx,iax from #{BD}.ethkx")
28
30
  },
29
31
  ops
data/lib/cns/bigquery3.rb CHANGED
@@ -16,6 +16,19 @@ module Cns
16
16
  ") VALUES#{apies.novtx.map { |obj| etht_1val(obj) }.join(',')}"
17
17
  end
18
18
 
19
+ # @return [String] comando insert SQL formatado ethi (internas)
20
+ def ethi_ins
21
+ "insert #{BD}.ethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
22
+ 'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode' \
23
+ ") VALUES#{apies.novix.map { |obj| ethi_1val(obj) }.join(',')}"
24
+ end
25
+
26
+ # @return [String] comando insert SQL formatado ethp (block)
27
+ def ethp_ins
28
+ "insert #{BD}.ethp(blocknumber,timestamp,blockreward,iax" \
29
+ ") VALUES#{apies.novpx.map { |obj| ethp_1val(obj) }.join(',')}"
30
+ end
31
+
19
32
  # @return [String] comando insert SQL formatado ethk (token)
20
33
  def ethk_ins
21
34
  "insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
@@ -78,6 +91,47 @@ module Cns
78
91
  "#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
79
92
  end
80
93
 
94
+ # @example (see Apibc#inter_es)
95
+ # @param [Hash] htx transacao internas etherscan
96
+ # @return [String] valores formatados ethi (internas parte1)
97
+ def ethi_1val(htx)
98
+ cta = htx[:contractAddress]
99
+ "(#{Integer(htx[:blockNumber])}," \
100
+ "#{Integer(htx[:timeStamp])}," \
101
+ "'#{htx[:hash]}'," \
102
+ "'#{htx[:from]}'," \
103
+ "'#{htx[:to]}'," \
104
+ "'#{htx[:iax]}'," \
105
+ "cast('#{htx[:value]}' as numeric)," \
106
+ "#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
107
+ "#{ethi_2val(htx)}"
108
+ end
109
+
110
+ # @param (see ethi_1val)
111
+ # @return [String] valores formatados ethi (internas parte2)
112
+ def ethi_2val(htx)
113
+ inp = htx[:input]
114
+ tid = htx[:traceId]
115
+ txr = htx[:errCode]
116
+ "#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
117
+ "'#{htx[:type]}'," \
118
+ "cast('#{htx[:gas]}' as numeric)," \
119
+ "cast('#{htx[:gasUsed]}' as numeric)," \
120
+ "#{tid.length.zero? ? 'null' : "'#{tid}'"}," \
121
+ "#{Integer(htx[:isError])}," \
122
+ "#{txr.length.zero? ? 'null' : txr})"
123
+ end
124
+
125
+ # @example (see Apibc#block_es)
126
+ # @param [Hash] htx transacao block etherscan
127
+ # @return [String] valores formatados ethi (block parte1)
128
+ def ethp_1val(htx)
129
+ "(#{Integer(htx[:blockNumber])}," \
130
+ "#{Integer(htx[:timeStamp])}," \
131
+ "cast('#{htx[:blockReward]}' as numeric)," \
132
+ "'#{htx[:iax]}')"
133
+ end
134
+
81
135
  # @example (see Apibc#token_es)
82
136
  # @param [Hash] hkx token event etherscan
83
137
  # @return [String] valores formatados ethk (token parte1)
@@ -32,6 +32,16 @@ module Cns
32
32
  @novtx ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten
33
33
  end
34
34
 
35
+ # @return [Array<Hash>] lista transacoes internas novas
36
+ def novix
37
+ @novix ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten
38
+ end
39
+
40
+ # @return [Array<Hash>] lista transacoes block novas
41
+ def novpx
42
+ @novpx ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten
43
+ end
44
+
35
45
  # @return [Array<Hash>] lista transacoes token novas
36
46
  def novkx
37
47
  @novkx ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten
@@ -58,6 +68,18 @@ module Cns
58
68
  (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
59
69
  end
60
70
 
71
+ # @return [Array<Integer>] lista indices transacoes internas novas
72
+ def idi
73
+ @idi ||= bcd.map { |obc| obc[:ix].map { |obj| obj[:itx] } }.flatten -
74
+ (ops[:t] ? [] : bqd[:ni].map { |obq| obq[:itx] })
75
+ end
76
+
77
+ # @return [Array<Integer>] lista indices transacoes block novas
78
+ def idp
79
+ @idp ||= bcd.map { |obc| obc[:px].map { |obj| obj[:itx] } }.flatten -
80
+ (ops[:t] ? [] : bqd[:np].map { |obq| obq[:itx] })
81
+ end
82
+
61
83
  # @return [Array<Integer>] lista indices transacoes token novas
62
84
  def idk
63
85
  @idk ||= bcd.map { |obc| obc[:kx].map { |obj| obj[:itx] } }.flatten -
@@ -71,8 +93,10 @@ module Cns
71
93
  acc = abc[:account].downcase
72
94
  {
73
95
  ax: acc,
74
- sl: (abc[:balance].to_d / 10**18).round(10),
96
+ sl: (abc[:balance].to_d / 10**18),
75
97
  tx: filtrar_tx(acc, api.norml_es(acc)),
98
+ ix: filtrar_tx(acc, api.inter_es(acc)),
99
+ px: filtrar_px(acc, api.block_es(acc)),
76
100
  kx: filtrar_tx(acc, api.token_es(acc))
77
101
  }
78
102
  end
@@ -86,9 +110,13 @@ module Cns
86
110
  ax: xbq = wbq[:ax],
87
111
  bs: wbq[:sl],
88
112
  bt: bqd[:nt].select { |ont| ont[:iax] == xbq },
113
+ bi: bqd[:ni].select { |oni| oni[:iax] == xbq },
114
+ bp: bqd[:np].select { |onp| onp[:iax] == xbq },
89
115
  bk: bqd[:nk].select { |onk| onk[:iax] == xbq },
90
116
  es: hbc[:sl],
91
117
  et: hbc[:tx],
118
+ ei: hbc[:ix],
119
+ ep: hbc[:px],
92
120
  ek: hbc[:kx]
93
121
  }
94
122
  end
@@ -103,11 +131,29 @@ module Cns
103
131
  .map { |omp| omp.delete_if { |key, _| DL.include?(key) }.merge(itx: Integer(omp[:blockNumber]), iax: add) }
104
132
  end
105
133
 
134
+ # @param add (see Apibc#norml_es)
135
+ # @param [Array<Hash>] ary lista blocks events
136
+ # @return [Array<Hash>] lista blocks events filtrada
137
+ def filtrar_px(add, ary)
138
+ # adiciona chave indice itx & adiciona identificador da carteira iax
139
+ ary.map { |omp| omp.merge(itx: Integer(omp[:blockNumber]), iax: add) }
140
+ end
141
+
106
142
  # @return [Array<Hash>] lista ordenada transacoes normais novas
107
143
  def sortx
108
144
  novtx.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
109
145
  end
110
146
 
147
+ # @return [Array<Hash>] lista ordenada transacoes internas novas
148
+ def sorix
149
+ novix.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
150
+ end
151
+
152
+ # @return [Array<Hash>] lista ordenada transacoes block novas
153
+ def sorpx
154
+ novpx.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
155
+ end
156
+
111
157
  # @return [Array<Hash>] lista ordenada transacoes token novas
112
158
  def sorkx
113
159
  novkx.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
@@ -8,9 +8,11 @@ module Cns
8
8
  def mostra_resumo
9
9
  return unless dados.count.positive?
10
10
 
11
- puts("\nid address etherscan nm tk bigquery nm tk")
11
+ puts("\nid address etherscan tn ti tb tk bigquery tn ti tb tk")
12
12
  dados.each { |obj| puts(formata_carteira(obj)) }
13
13
  mostra_transacao_norml
14
+ mostra_transacao_inter
15
+ mostra_transacao_block
14
16
  mostra_transacao_token
15
17
  mostra_configuracao_ajuste_dias
16
18
  end
@@ -19,9 +21,9 @@ module Cns
19
21
  # @return [String] texto formatado duma carteira
20
22
  def formata_carteira(hjn)
21
23
  format(
22
- '%<s1>-6.6s %<s2>-32.32s ',
24
+ '%<s1>-6.6s %<s2>-20.20s ',
23
25
  s1: hjn[:id],
24
- s2: formata_endereco(hjn[:ax], 32)
26
+ s2: formata_enderec1(hjn[:ax], 20)
25
27
  ) + formata_valores(hjn)
26
28
  end
27
29
 
@@ -29,13 +31,17 @@ module Cns
29
31
  # @return [String] texto formatado valores duma carteira
30
32
  def formata_valores(hjn)
31
33
  format(
32
- '%<v1>11.6f %<n1>2i %<n3>2i %<v2>12.6f %<n2>2i %<n4>2i %<ok>-3s',
34
+ '%<v1>12.6f %<n1>2i %<n2>2i %<n3>2i %<n4>2i %<v2>12.6f %<n5>2i %<n6>2i %<n7>2i %<n8>2i %<ok>-3s',
33
35
  v1: hjn[:es],
34
36
  n1: hjn[:et].count,
35
- n3: hjn[:ek].count,
37
+ n2: hjn[:ei].count,
38
+ n3: hjn[:ep].count,
39
+ n4: hjn[:ek].count,
36
40
  v2: hjn[:bs],
37
- n2: hjn[:bt].count,
38
- n4: hjn[:bk].count,
41
+ n5: hjn[:bt].count,
42
+ n6: hjn[:bi].count,
43
+ n7: hjn[:bp].count,
44
+ n8: hjn[:bk].count,
39
45
  ok: ok?(hjn) ? 'OK' : 'NOK'
40
46
  )
41
47
  end
@@ -43,7 +49,7 @@ module Cns
43
49
  # @param (see formata_carteira)
44
50
  # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
45
51
  def ok?(hjn)
46
- hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count && hjn[:bk].count == hjn[:ek].count
52
+ hjn[:bs].round(6) == hjn[:es].round(6) && hjn[:bt].count == hjn[:et].count && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bk].count == hjn[:ek].count
47
53
  end
48
54
 
49
55
  # @example ether address inicio..fim
@@ -51,10 +57,29 @@ module Cns
51
57
  # @param add (see filtrar_tx)
52
58
  # @param [Integer] max chars a mostrar
53
59
  # @return [String] endereco formatado
54
- def formata_endereco(add, max)
55
- int = Integer((max - 2) / 2)
56
- hid = (max <= 20 ? bqd[:wb].select { |obj| obj[:ax] == add }.first : nil) || { id: add }
57
- max < 7 ? 'erro' : "#{hid[:id][0, int - 3]}..#{add[-int - 3..]}"
60
+ def formata_enderec1(add, max)
61
+ return 'erro' if max < 7
62
+
63
+ max -= 2
64
+ ini = Integer(max / 2)
65
+ inf = max % 2
66
+ "#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
67
+ end
68
+
69
+ # @example ether address inicio..fim
70
+ # me-app..4b437776403d
71
+ # @param add (see filtrar_tx)
72
+ # @param [Integer] max chars a mostrar
73
+ # @return [String] endereco formatado
74
+ def formata_enderec2(add, max)
75
+ return 'erro' if max < 7
76
+
77
+ max -= 2
78
+ ini = Integer(max / 2)
79
+ inf = max % 2
80
+ hid = bqd[:wb].select { |obj| obj[:ax] == add }.first
81
+ ndd = hid ? hid[:id] + '-' + add : add
82
+ "#{ndd[0, ini - 3]}..#{ndd[-inf - ini - 3..]}"
58
83
  end
59
84
 
60
85
  # @example (see Apibc#norml_es)
@@ -64,13 +89,26 @@ module Cns
64
89
  format(
65
90
  '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>17.6f',
66
91
  bn: htx[:blockNumber],
67
- fr: formata_endereco(htx[:from], 20),
68
- to: formata_endereco(htx[:to], 20),
92
+ fr: formata_enderec2(htx[:from], 20),
93
+ to: formata_enderec2(htx[:to], 20),
69
94
  dt: Time.at(Integer(htx[:timeStamp])),
70
95
  vl: (htx[:value].to_d / 10**18).round(10)
71
96
  )
72
97
  end
73
98
 
99
+ # @example (see Apibc#block_es)
100
+ # @param [Hash] htx transacao block etherscan
101
+ # @return [String] texto formatado transacao block etherscan
102
+ def formata_transacao_block(htx)
103
+ format(
104
+ '%<bn>9i %<fr>-41.41s %<dt>10.10s %<vl>17.6f',
105
+ bn: htx[:blockNumber],
106
+ fr: formata_enderec2(htx[:iax], 41),
107
+ dt: Time.at(Integer(htx[:timeStamp])),
108
+ vl: (htx[:blockReward].to_d / 10**18).round(10)
109
+ )
110
+ end
111
+
74
112
  # @example (see Apibc#token_es)
75
113
  # @param [Hash] hkx transacao token etherscan
76
114
  # @return [String] texto formatado transacao token etherscan
@@ -78,8 +116,8 @@ module Cns
78
116
  format(
79
117
  '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>11.3f %<sy>-5.5s',
80
118
  bn: hkx[:blockNumber],
81
- fr: formata_endereco(hkx[:from], 20),
82
- to: formata_endereco(hkx[:to], 20),
119
+ fr: formata_enderec2(hkx[:from], 20),
120
+ to: formata_enderec2(hkx[:to], 20),
83
121
  dt: Time.at(Integer(hkx[:timeStamp])),
84
122
  vl: (hkx[:value].to_d / 10**18).round(10),
85
123
  sy: hkx[:tokenSymbol]
@@ -94,6 +132,22 @@ module Cns
94
132
  sortx.each { |obj| puts(formata_transacao_norml(obj)) }
95
133
  end
96
134
 
135
+ # @return [String] texto transacoes internas
136
+ def mostra_transacao_inter
137
+ return unless ops[:v] && novix.count.positive?
138
+
139
+ puts("\ntx intern from to data valor")
140
+ sorix.each { |obj| puts(formata_transacao_norml(obj)) }
141
+ end
142
+
143
+ # @return [String] texto transacoes block
144
+ def mostra_transacao_block
145
+ return unless ops[:v] && novpx.count.positive?
146
+
147
+ puts("\ntx block address data valor")
148
+ sorpx.each { |obj| puts(formata_transacao_block(obj)) }
149
+ end
150
+
97
151
  # @return [String] texto transacoes token
98
152
  def mostra_transacao_token
99
153
  return unless ops[:v] && novkx.count.positive?
data/lib/cns/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.2'
5
5
  end
data/lib/cns.rb CHANGED
@@ -23,6 +23,13 @@ require('cns/version')
23
23
  module Cns
24
24
  # classe para carregar/mostrar dados transacoes eth & eos no bigquery
25
25
  class CLI < Thor
26
+ desc 'weth', 'carrega transacoes eth no bigquery'
27
+ option :h, type: :hash, default: {}, desc: 'configuracao ajuste reposicionamento temporal'
28
+ # carrega transacoes eth no bigquery
29
+ def weth
30
+ Bigquery.new(options).processa_eth
31
+ end
32
+
26
33
  desc 'work', 'carrega transacoes novas no bigquery'
27
34
  option :h, type: :hash, default: {}, desc: 'configuracao ajuste reposicionamento temporal'
28
35
  # carrega transacoes novas no bigquery
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-14 00:00:00.000000000 Z
11
+ date: 2022-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-lint
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: solargraph
85
99
  requirement: !ruby/object:Gem::Requirement