cns 0.3.3 → 0.3.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: 00db558ab8907678d896c4c9af0a4520815eb2159340804799be40e487e788a8
4
- data.tar.gz: 533c85ce882e271dd9f66ae5445066e0fbf0ff265f66f7de25222d86e0789f0a
3
+ metadata.gz: 628583895b421b1b5d84af2753d24d28d4c0f2d1e4ed4f363160ef07b1d0e23d
4
+ data.tar.gz: 7e14420b81120d01f9abe1171fc248949ff8ffbeff2c698901dc0d60d7d68ad5
5
5
  SHA512:
6
- metadata.gz: 16fb0ed5e6430cdf5eec1f16157df679605ed691ed558249059002b7772764b8230e4b04e8017d81ab0c0e58b6644e8b157c324c9cd2cadd37b4042abdea2183
7
- data.tar.gz: 4744d1fa97206235eb403ae9ce703e4d55369b3b0b614f0ed80556c248feb99fcd0fbbeac8f1e9105830c3f84873b5cd828eb8abeb019b9ad7e05f19adff96b7
6
+ metadata.gz: 2d0f31b4f43dcef2abcfddce96174ee06de7650fa5413390e126bd532056df1349f3e438f13759651b35cf666e78e688a6378f92f3dff782a0a14f51ff1c575c
7
+ data.tar.gz: 89e7998c421ad34256815ca720f02814875a2d58958c97604c24b3313388e9d6c324ba67473784299a47c9fb90b76af8806bad80563bd985fd3d56a588110029
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.3.3)
4
+ cns (0.3.4)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
data/lib/cns/apibc.rb CHANGED
@@ -206,6 +206,40 @@ module Cns
206
206
  aes
207
207
  end
208
208
 
209
+ # @example withw_es
210
+ # {
211
+ # "status":"1",
212
+ # "message":"OK",
213
+ # "result":[
214
+ # {
215
+ # "withdrawalIndex":"14",
216
+ # "validatorIndex":"119023",
217
+ # "address":"0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f",
218
+ # "amount":"3244098967",
219
+ # "blockNumber":"17034877",
220
+ # "timestamp":"1681338599"
221
+ # }
222
+ # ]
223
+ # }
224
+ # @param (see norml_es)
225
+ # @return [Array<Hash>] lista blocos etherscan
226
+ def withw_es(add, pag = 0, aes = [])
227
+ res = JSON.parse(
228
+ conn_es.get(
229
+ '/api',
230
+ action: 'txsBeaconWithdrawal',
231
+ address: add,
232
+ offset: 10_000,
233
+ page: pag += 1
234
+ ).body,
235
+ symbolize_names: true
236
+ )[:result]
237
+ aes += res
238
+ res.count < 10_000 ? aes : withw_es(add, pag, aes)
239
+ rescue StandardError
240
+ aes
241
+ end
242
+
209
243
  # @example token_es
210
244
  # {
211
245
  # status: '1',
data/lib/cns/bigquery1.rb CHANGED
@@ -34,21 +34,21 @@ module Cns
34
34
  def mostra_tudo
35
35
  apius.mostra_resumo
36
36
  apide.mostra_resumo
37
- apifr.mostra_resumo
38
- apimt.mostra_resumo
37
+ #apifr.mostra_resumo
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
45
45
  def processa_tudo
46
46
  processa_us
47
47
  processa_de
48
- processa_frmt
48
+ #processa_frmt
49
49
  processa_eth
50
50
  processa_eos
51
- # processa_bc
51
+ #processa_bc
52
52
  end
53
53
 
54
54
  # insere transacoes blockchain novas nas tabelas etht (norml), ethi (internas), ethp (block), ethk (token)
@@ -56,6 +56,7 @@ module Cns
56
56
  puts(format("%<n>4i TRANSACOES ETH NORMAIS\tINSERIDAS etht", n: apies.novtx.empty? ? 0 : dml(etht_ins)))
57
57
  puts(format("%<n>4i TRANSACOES ETH INTERNAS\tINSERIDAS ethi", n: apies.novix.empty? ? 0 : dml(ethi_ins)))
58
58
  puts(format("%<n>4i TRANSACOES ETH BLOCK\tINSERIDAS ethp", n: apies.novpx.empty? ? 0 : dml(ethp_ins)))
59
+ puts(format("%<n>4i TRANSACOES ETH WITHDRAWALS\tINSERIDAS ethw", n: apies.novwx.empty? ? 0 : dml(ethw_ins)))
59
60
  puts(format("%<n>4i TOKENS\tETH\t\tINSERIDAS ethk", n: apies.novkx.empty? ? 0 : dml(ethk_ins)))
60
61
  end
61
62
 
data/lib/cns/bigquery2.rb CHANGED
@@ -26,6 +26,7 @@ module Cns
26
26
  nt: sql("select itx,iax from #{BD}.ethtx"),
27
27
  ni: sql("select itx,iax from #{BD}.ethix"),
28
28
  np: sql("select itx,iax from #{BD}.ethpx"),
29
+ nw: sql("select itx,iax from #{BD}.ethwx"),
29
30
  nk: sql("select itx,iax from #{BD}.ethkx")
30
31
  },
31
32
  ops
data/lib/cns/bigquery3.rb CHANGED
@@ -29,6 +29,12 @@ module Cns
29
29
  ") VALUES#{apies.novpx.map { |obj| ethp_1val(obj) }.join(',')}"
30
30
  end
31
31
 
32
+ # @return [String] comando insert SQL formatado ethw (withdrawals)
33
+ def ethw_ins
34
+ "insert #{BD}.ethw(withdrawalindex,validatorindex,address,amount,blocknumber,timestamp" \
35
+ ") VALUES#{apies.novwx.map { |obj| ethw_1val(obj) }.join(',')}"
36
+ end
37
+
32
38
  # @return [String] comando insert SQL formatado ethk (token)
33
39
  def ethk_ins
34
40
  "insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
@@ -132,6 +138,18 @@ module Cns
132
138
  "'#{htx[:iax]}')"
133
139
  end
134
140
 
141
+ # @example (see Apibc#block_es)
142
+ # @param [Hash] htx transacao withdrawals etherscan
143
+ # @return [String] valores formatados ethi (withdrawals parte1)
144
+ def ethw_1val(htx)
145
+ "(#{Integer(htx[:withdrawalIndex])}," \
146
+ "#{Integer(htx[:validatorIndex])}," \
147
+ "'#{htx[:address]}'," \
148
+ "cast('#{htx[:amount]}' as numeric)," \
149
+ "#{Integer(htx[:blockNumber])}," \
150
+ "#{Integer(htx[:timestamp])})"
151
+ end
152
+
135
153
  # @example (see Apibc#token_es)
136
154
  # @param [Hash] hkx token event etherscan
137
155
  # @return [String] valores formatados ethk (token parte1)
@@ -42,6 +42,11 @@ module Cns
42
42
  @novpx ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten
43
43
  end
44
44
 
45
+ # @return [Array<Hash>] lista transacoes withdrawals novas
46
+ def novwx
47
+ @novwx ||= bcd.map { |obc| obc[:wx].select { |obj| idw.include?(obj[:itx]) } }.flatten
48
+ end
49
+
45
50
  # @return [Array<Hash>] lista transacoes token novas
46
51
  def novkx
47
52
  @novkx ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten
@@ -80,6 +85,12 @@ module Cns
80
85
  (ops[:t] ? [] : bqd[:np].map { |obq| obq[:itx] })
81
86
  end
82
87
 
88
+ # @return [Array<Integer>] lista indices transacoes withdrawals novas
89
+ def idw
90
+ @idw ||= bcd.map { |obc| obc[:wx].map { |obj| obj[:itx] } }.flatten -
91
+ (ops[:t] ? [] : bqd[:nw].map { |obq| obq[:itx] })
92
+ end
93
+
83
94
  # @return [Array<Integer>] lista indices transacoes token novas
84
95
  def idk
85
96
  @idk ||= bcd.map { |obc| obc[:kx].map { |obj| obj[:itx] } }.flatten -
@@ -97,6 +108,7 @@ module Cns
97
108
  tx: filtrar_tx(acc, api.norml_es(acc)),
98
109
  ix: filtrar_tx(acc, api.inter_es(acc)),
99
110
  px: filtrar_px(acc, api.block_es(acc)),
111
+ wx: filtrar_px(acc, api.withw_es(acc)),
100
112
  kx: filtrar_tx(acc, api.token_es(acc))
101
113
  }
102
114
  end
@@ -112,11 +124,13 @@ module Cns
112
124
  bt: bqd[:nt].select { |ont| ont[:iax] == xbq },
113
125
  bi: bqd[:ni].select { |oni| oni[:iax] == xbq },
114
126
  bp: bqd[:np].select { |onp| onp[:iax] == xbq },
127
+ bw: bqd[:nw].select { |onw| onw[:iax] == xbq },
115
128
  bk: bqd[:nk].select { |onk| onk[:iax] == xbq },
116
129
  es: hbc[:sl],
117
130
  et: hbc[:tx],
118
131
  ei: hbc[:ix],
119
132
  ep: hbc[:px],
133
+ ew: hbc[:wx],
120
134
  ek: hbc[:kx]
121
135
  }
122
136
  end
@@ -154,6 +168,11 @@ module Cns
154
168
  novpx.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
155
169
  end
156
170
 
171
+ # @return [Array<Hash>] lista ordenada transacoes withdrawals novas
172
+ def sorwx
173
+ novwx.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
174
+ end
175
+
157
176
  # @return [Array<Hash>] lista ordenada transacoes token novas
158
177
  def sorkx
159
178
  novkx.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
@@ -8,12 +8,13 @@ module Cns
8
8
  def mostra_resumo
9
9
  return unless dados.count.positive?
10
10
 
11
- puts("\nid address etherscan tn ti tb tk bigquery tn ti tb tk")
11
+ puts("\nid address etherscan tn ti tb tk tw bigquery tn ti tb tk tw")
12
12
  dados.each { |obj| puts(formata_carteira(obj)) }
13
13
  mostra_transacao_norml
14
14
  mostra_transacao_inter
15
15
  mostra_transacao_block
16
16
  mostra_transacao_token
17
+ mostra_transacao_withw
17
18
  mostra_configuracao_ajuste_dias
18
19
  end
19
20
 
@@ -21,9 +22,9 @@ module Cns
21
22
  # @return [String] texto formatado duma carteira
22
23
  def formata_carteira(hjn)
23
24
  format(
24
- '%<s1>-6.6s %<s2>-20.20s ',
25
+ '%<s1>-6.6s %<s2>-16.16s ',
25
26
  s1: hjn[:id],
26
- s2: formata_enderec1(hjn[:ax], 20)
27
+ s2: formata_enderec1(hjn[:ax], 16)
27
28
  ) + formata_valores(hjn)
28
29
  end
29
30
 
@@ -31,17 +32,19 @@ module Cns
31
32
  # @return [String] texto formatado valores duma carteira
32
33
  def formata_valores(hjn)
33
34
  format(
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',
35
+ '%<v1>12.6f %<n1>3i %<n2>2i %<n3>2i %<n4>2i %<w1>3i %<v2>12.6f %<n5>3i %<n6>2i %<n7>2i %<n8>2i %<w2>3i %<ok>-3s',
35
36
  v1: hjn[:es],
36
37
  n1: hjn[:et].count,
37
38
  n2: hjn[:ei].count,
38
39
  n3: hjn[:ep].count,
39
40
  n4: hjn[:ek].count,
41
+ w1: hjn[:ew].count,
40
42
  v2: hjn[:bs],
41
43
  n5: hjn[:bt].count,
42
44
  n6: hjn[:bi].count,
43
45
  n7: hjn[:bp].count,
44
46
  n8: hjn[:bk].count,
47
+ w2: hjn[:bw].count,
45
48
  ok: ok?(hjn) ? 'OK' : 'NOK'
46
49
  )
47
50
  end
@@ -49,7 +52,7 @@ module Cns
49
52
  # @param (see formata_carteira)
50
53
  # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
51
54
  def ok?(hjn)
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
55
+ 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 && hjn[:bw].count == hjn[:ew].count
53
56
  end
54
57
 
55
58
  # @example ether address inicio..fim
@@ -61,7 +64,7 @@ module Cns
61
64
  return 'erro' if max < 7
62
65
 
63
66
  max -= 2
64
- ini = Integer(max / 2)
67
+ ini = Integer(max / 2) + 3
65
68
  inf = max % 2
66
69
  "#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
67
70
  end
@@ -124,6 +127,19 @@ module Cns
124
127
  )
125
128
  end
126
129
 
130
+ # @example (see Apibc#block_es)
131
+ # @param [Hash] htx transacao withdrawals etherscan
132
+ # @return [String] texto formatado transacao withdrawals etherscan
133
+ def formata_transacao_withw(htx)
134
+ format(
135
+ '%<vi>9i %<bn>9i %<dt>10.10s %<vl>10.6f',
136
+ vi: htx[:validatorIndex],
137
+ bn: htx[:blockNumber],
138
+ dt: Time.at(Integer(htx[:timestamp])),
139
+ vl: (htx[:amount].to_d / 10**9).round(10)
140
+ )
141
+ end
142
+
127
143
  # @return [String] texto transacoes normais
128
144
  def mostra_transacao_norml
129
145
  return unless ops[:v] && novtx.count.positive?
@@ -156,6 +172,14 @@ module Cns
156
172
  sorkx.each { |obj| puts(formata_transacao_token(obj)) }
157
173
  end
158
174
 
175
+ # @return [String] texto transacoes withdrawals
176
+ def mostra_transacao_withw
177
+ return unless ops[:v] && novwx.count.positive?
178
+
179
+ puts("\nvalidator block data valor")
180
+ sorwx.each { |obj| puts(formata_transacao_withw(obj)) }
181
+ end
182
+
159
183
  # @return [String] texto configuracao ajuste dias das transacoes (normais & token)
160
184
  def mostra_configuracao_ajuste_dias
161
185
  return unless (novtx.count + 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.3'
4
+ VERSION = '0.3.4'
5
5
  end
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.3
4
+ version: 0.3.4
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: 2023-07-08 00:00:00.000000000 Z
11
+ date: 2023-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler