cns 0.5.3 → 0.5.7

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: a5c81184cadadec18414492a966d23fd39e6072f8c5619b7e0062b8fa753708f
4
- data.tar.gz: 9e893a5f6a1c69eb41d426254fd5c4f8d9fef82313edf2b01065b1e62fa70e41
3
+ metadata.gz: 6a2b6e7061f6b33a63f0f488471c29ee549d61e31d46fa3fc4b9c577571087cf
4
+ data.tar.gz: '0728c393086fe4ea971a98ba8730c9750a1694b0f3be9139647892a1e211dfdb'
5
5
  SHA512:
6
- metadata.gz: 74b5dae5710abb4b48c12f56f92bf15f7d4fc282a3640bce09e50b8dcab0c421a56d3ae21fa60fbc1100e51725b439aadb9a2463e184ab285cc2c0618836c2be
7
- data.tar.gz: 4dcce3fe4996b0d30dd448a4df7a12290fe3bc267ef7ebbb66bc843ee60326beb13e440ad4b285cbecc05a76d14bdf72cc576b37b7e514ba2ae3a6ba00e79c42
6
+ metadata.gz: dce2de5b56472572d4ba0d8526f51ad999093204a3098d228bd44abd656aeaaff19a02d0ef32a65c17bfd1ebc2b9d6bf8e9851fdacb02eb82ceabda0bf724f5f
7
+ data.tar.gz: 2899e7e111ea1bc08cbdb1421857964d0dd4b3a553761af67e02679331db546fc2d372ba9b4b61949cce90ff680bab08b29f5c129626cfd7b8cf96d5dc6d8d25
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.5.3)
4
+ cns (0.5.7)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
@@ -10,74 +10,83 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.8.6)
14
- public_suffix (>= 2.0.2, < 6.0)
13
+ addressable (2.8.7)
14
+ public_suffix (>= 2.0.2, < 7.0)
15
15
  ast (2.4.2)
16
16
  backport (1.2.0)
17
17
  base64 (0.2.0)
18
- benchmark (0.3.0)
19
- bigdecimal (3.1.8)
20
- concurrent-ruby (1.3.3)
21
- curb (1.0.5)
18
+ benchmark (0.4.0)
19
+ bigdecimal (3.1.9)
20
+ concurrent-ruby (1.3.5)
21
+ curb (1.0.6)
22
22
  declarative (0.0.20)
23
23
  e2mmap (0.1.0)
24
- faraday (2.9.1)
25
- faraday-net_http (>= 2.0, < 3.2)
26
- faraday-net_http (3.1.0)
27
- net-http
28
- google-apis-bigquery_v2 (0.71.0)
24
+ faraday (2.12.2)
25
+ faraday-net_http (>= 2.0, < 3.5)
26
+ json
27
+ logger
28
+ faraday-net_http (3.4.0)
29
+ net-http (>= 0.5.0)
30
+ google-apis-bigquery_v2 (0.83.0)
29
31
  google-apis-core (>= 0.15.0, < 2.a)
30
- google-apis-core (0.15.0)
32
+ google-apis-core (0.16.0)
31
33
  addressable (~> 2.5, >= 2.5.1)
32
34
  googleauth (~> 1.9)
33
- httpclient (>= 2.8.1, < 3.a)
35
+ httpclient (>= 2.8.3, < 3.a)
34
36
  mini_mime (~> 1.0)
37
+ mutex_m
35
38
  representable (~> 3.0)
36
39
  retriable (>= 2.0, < 4.a)
37
- rexml
38
- google-cloud-bigquery (1.49.1)
40
+ google-cloud-bigquery (1.51.1)
39
41
  bigdecimal (~> 3.0)
40
42
  concurrent-ruby (~> 1.0)
41
- google-apis-bigquery_v2 (~> 0.62)
43
+ google-apis-bigquery_v2 (~> 0.71)
42
44
  google-apis-core (~> 0.13)
43
45
  google-cloud-core (~> 1.6)
44
46
  googleauth (~> 1.9)
45
47
  mini_mime (~> 1.0)
46
- google-cloud-core (1.7.0)
48
+ google-cloud-core (1.7.1)
47
49
  google-cloud-env (>= 1.0, < 3.a)
48
50
  google-cloud-errors (~> 1.0)
49
- google-cloud-env (2.1.1)
51
+ google-cloud-env (2.2.1)
50
52
  faraday (>= 1.0, < 3.a)
51
53
  google-cloud-errors (1.4.0)
52
- googleauth (1.11.0)
54
+ google-logging-utils (0.1.0)
55
+ googleauth (1.13.1)
53
56
  faraday (>= 1.0, < 3.a)
54
- google-cloud-env (~> 2.1)
57
+ google-cloud-env (~> 2.2)
58
+ google-logging-utils (~> 0.1)
55
59
  jwt (>= 1.4, < 3.0)
56
60
  multi_json (~> 1.11)
57
61
  os (>= 0.9, < 2.0)
58
62
  signet (>= 0.16, < 2.a)
59
63
  httpclient (2.8.3)
60
64
  jaro_winkler (1.6.0)
61
- jwt (2.8.1)
65
+ json (2.9.1)
66
+ jwt (2.10.1)
62
67
  base64
63
- kramdown (2.4.0)
64
- rexml
68
+ kramdown (2.5.1)
69
+ rexml (>= 3.3.9)
65
70
  kramdown-parser-gfm (1.1.0)
66
71
  kramdown (~> 2.0)
67
72
  kwalify (0.7.2)
73
+ logger (1.6.5)
68
74
  mini_mime (1.1.5)
75
+ mini_portile2 (2.8.8)
69
76
  multi_json (1.15.0)
70
- net-http (0.4.1)
77
+ mutex_m (0.3.0)
78
+ net-http (0.6.0)
71
79
  uri
72
- nokogiri (1.16.6-x86_64-linux)
80
+ nokogiri (1.18.2)
81
+ mini_portile2 (~> 2.8.2)
73
82
  racc (~> 1.4)
74
83
  os (1.1.4)
75
- parallel (1.25.1)
84
+ parallel (1.26.3)
76
85
  parser (2.7.2.0)
77
86
  ast (~> 2.4.1)
78
87
  psych (3.3.4)
79
- public_suffix (5.0.5)
80
- racc (1.8.0)
88
+ public_suffix (6.0.1)
89
+ racc (1.8.1)
81
90
  rainbow (3.1.1)
82
91
  rake (12.3.3)
83
92
  reek (6.0.2)
@@ -85,7 +94,7 @@ GEM
85
94
  parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
86
95
  psych (~> 3.1)
87
96
  rainbow (>= 2.0, < 4.0)
88
- regexp_parser (2.9.2)
97
+ regexp_parser (2.10.0)
89
98
  representable (3.2.0)
90
99
  declarative (< 0.1.0)
91
100
  trailblazer-option (>= 0.1.1, < 0.2.0)
@@ -93,8 +102,7 @@ GEM
93
102
  retriable (3.1.2)
94
103
  reverse_markdown (2.1.1)
95
104
  nokogiri
96
- rexml (3.3.0)
97
- strscan
105
+ rexml (3.4.0)
98
106
  rubocop (1.7.0)
99
107
  parallel (~> 1.10)
100
108
  parser (>= 2.7.1.5)
@@ -132,14 +140,13 @@ GEM
132
140
  thor (~> 1.0)
133
141
  tilt (~> 2.0)
134
142
  yard (~> 0.9, >= 0.9.24)
135
- strscan (3.1.0)
136
- thor (1.3.1)
137
- tilt (2.3.0)
143
+ thor (1.3.2)
144
+ tilt (2.6.0)
138
145
  trailblazer-option (0.1.2)
139
146
  uber (0.1.0)
140
147
  unicode-display_width (1.8.0)
141
- uri (0.13.0)
142
- yard (0.9.36)
148
+ uri (1.0.2)
149
+ yard (0.9.37)
143
150
 
144
151
  PLATFORMS
145
152
  x86_64-linux
data/lib/cns/apibc.rb CHANGED
@@ -7,17 +7,6 @@ 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
-
21
10
  # @example account_es
22
11
  # {
23
12
  # status: '1',
@@ -27,7 +16,7 @@ module Cns
27
16
  # { account: '0x...', balance: '87000000000000000000' }
28
17
  # ]
29
18
  # }
30
- # @param [String] ads lista enderecos ETH (max 20)
19
+ # @param [Array<String>] ads lista enderecos ETH (max 20)
31
20
  # @return [Array<Hash>] lista enderecos e seus saldos
32
21
  def account_es(ads)
33
22
  JSON.parse(
@@ -375,13 +364,23 @@ module Cns
375
364
  end
376
365
  end
377
366
 
367
+ # @param [String] uri ETH2 API
368
+ # @return [Array<Hash>] lista dados beaconchain
369
+ # def data_bc(uri)
370
+ # res = JSON.parse(conn_bc.get(uri).body, symbolize_names: true)[:data] || []
371
+ # # calls are rate limited to 10 requests/minute/IP
372
+ # sleep(3)
373
+ # res.is_a?(Array) ? res : [res]
374
+ # rescue StandardError
375
+ # []
376
+ # end
378
377
  # @return [<Faraday::Connection>] connection object for beaconchain
379
- def conn_bc
380
- @conn_bc ||=
381
- Faraday.new(url: 'https://beaconcha.in', headers: { accept: 'application/json' }) do |con|
382
- con.request(:url_encoded)
383
- con.adapter(adapter)
384
- end
385
- end
378
+ # def conn_bc
379
+ # @conn_bc ||=
380
+ # Faraday.new(url: 'https://beaconcha.in', headers: { accept: 'application/json' }) do |con|
381
+ # con.request(:url_encoded)
382
+ # con.adapter(adapter)
383
+ # end
384
+ # end
386
385
  end
387
386
  end
data/lib/cns/bigquery.rb CHANGED
@@ -31,7 +31,7 @@ module Cns
31
31
  @ops = pop
32
32
  end
33
33
 
34
- # mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain & bigquery
34
+ # mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass & bigquery
35
35
  def mostra_tudo
36
36
  apius.mostra_resumo
37
37
  apide.mostra_resumo
@@ -39,7 +39,6 @@ module Cns
39
39
  #apimt.mostra_resumo
40
40
  apies.mostra_resumo
41
41
  apigm.mostra_resumo
42
- #apibc.mostra_resumo
43
42
  end
44
43
 
45
44
  # mostra situacao completa entre kraken/etherscan & bigquery
@@ -58,7 +57,7 @@ module Cns
58
57
  Time.now.strftime("TRANSACOES %Y-%m-%d %H:%M:%S ")
59
58
  end
60
59
 
61
- # insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain no bigquery
60
+ # insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass no bigquery
62
61
  def processa_tudo
63
62
  str = processa_us + ", " + processa_de + ", " + processa_eth + ", " + processa_eos
64
63
  puts(trs_ini + str)
@@ -139,18 +138,6 @@ module Cns
139
138
  str
140
139
  end
141
140
 
142
- # insere transacoes exchange paymium/therock novas na tabela fr/mt (ledger)
143
- # def processa_frmt
144
- # puts(format("%<n>4i LEDGER\tPAYMIUM\t\tINSERIDAS fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
145
- # puts(format("%<n>4i LEDGER\tTHEROCK\t\tINSERIDAS mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
146
- # end
147
- # insere historico sados novos na tabela eth2bh
148
- # def processa_bc
149
- # puts(format("%<n>4i ATTESTATIONS INSERIDAS eth2at", n: apibc.novtx.empty? ? 0 : dml(eth2at_ins)))
150
- # puts(format("%<n>4i PROPOSALS INSERIDAS eth2pr", n: apibc.novkx.empty? ? 0 : dml(eth2pr_ins)))
151
- # puts(format("%<n>4i BALANCES\tETH2\t\tINSERIDOS eth2bh", n: apibc.nov.empty? ? 0 : dml(eth2bh_ins)))
152
- # end
153
-
154
141
  # cria job bigquery & verifica execucao
155
142
  #
156
143
  # @param cmd (see sql)
@@ -186,22 +173,16 @@ module Cns
186
173
  "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
187
174
  end
188
175
 
189
- # @return [String] comando insert SQL formatado eth2bh
190
- def eth2bh_ins
191
- "insert #{BD}.eth2bh(balance,effectivebalance,epoch,validatorindex" \
192
- ") VALUES#{apibc.nov[0..1000].map { |obj| eth2bh_1val(obj) }.join(',')}"
193
- end
194
-
195
176
  # @return [Etherscan] API blockchain ETH
196
177
  def apies
197
178
  @apies ||= Etherscan.new(
198
179
  {
199
180
  wb: sql("select * from #{BD}.walletEth order by 2"),
200
- nt: sql("select itx,iax from #{BD}.ethtx"),
201
- ni: sql("select itx,iax from #{BD}.ethix"),
202
- np: sql("select itx,iax from #{BD}.ethpx"),
203
- nw: sql("select itx,iax from #{BD}.ethwx"),
204
- nk: sql("select itx,iax from #{BD}.ethkx")
181
+ nt: sql("select * from #{BD}.ethtx"),
182
+ ni: sql("select * from #{BD}.ethix"),
183
+ np: sql("select * from #{BD}.ethpx"),
184
+ nw: sql("select * from #{BD}.ethwx"),
185
+ nk: sql("select * from #{BD}.ethkx")
205
186
  },
206
187
  ops
207
188
  )
@@ -212,11 +193,11 @@ module Cns
212
193
  @apies ||= Etherscan.new(
213
194
  {
214
195
  wb: sql("select * from #{BD}.walletEthc order by 2"),
215
- nt: sql("select itx,iax from #{BD}.ethtxc"),
216
- ni: sql("select itx,iax from #{BD}.ethixc"),
217
- np: sql("select itx,iax from #{BD}.ethpxc"),
218
- nw: sql("select itx,iax from #{BD}.ethwxc"),
219
- nk: sql("select itx,iax from #{BD}.ethkxc")
196
+ nt: sql("select * from #{BD}.ethtxc"),
197
+ ni: sql("select * from #{BD}.ethixc"),
198
+ np: sql("select * from #{BD}.ethpxc"),
199
+ nw: sql("select * from #{BD}.ethwxc"),
200
+ nk: sql("select * from #{BD}.ethkxc")
220
201
  },
221
202
  ops
222
203
  )
@@ -227,18 +208,7 @@ module Cns
227
208
  @apigm ||= Greymass.new(
228
209
  {
229
210
  wb: sql("select * from #{BD}.walletEos order by 2"),
230
- nt: sql("select itx,iax from #{BD}.eostx")
231
- },
232
- ops
233
- )
234
- end
235
-
236
- # @return [Beaconchain] API blockchain ETH2
237
- def apibc
238
- @apibc ||= Beaconchain.new(
239
- {
240
- wb: sql("select * from #{BD}.walletEth2 order by 1"),
241
- nb: sql("select itx,iax from #{BD}.eth2bhx")
211
+ nt: sql("select * from #{BD}.eostx")
242
212
  },
243
213
  ops
244
214
  )
@@ -389,16 +359,6 @@ module Cns
389
359
  "insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
390
360
  end
391
361
 
392
- # @example (see Beaconchain#formata_saldos)
393
- # @param (see Beaconchain#formata_saldos)
394
- # @return [String] valores formatados etht (norml parte1)
395
- def eth2bh_1val(htb)
396
- "(#{Integer(htb[:balance])}," \
397
- "#{Integer(htb[:effectivebalance])}," \
398
- "#{Integer(htb[:epoch])}," \
399
- "#{Integer(htb[:validatorindex])})"
400
- end
401
-
402
362
  # @example (see Apibc#norml_es)
403
363
  # @param [Hash] htx transacao norml etherscan
404
364
  # @return [String] valores formatados etht (norml parte1)
@@ -677,6 +637,41 @@ module Cns
677
637
  "#{Integer(ops[:h][String(hlx[:id])] || 0)})"
678
638
  end
679
639
 
640
+ # @example (see Beaconchain#formata_saldos)
641
+ # @param (see Beaconchain#formata_saldos)
642
+ # @return [String] valores formatados etht (norml parte1)
643
+ # def eth2bh_1val(htb)
644
+ # "(#{Integer(htb[:balance])}," \
645
+ # "#{Integer(htb[:effectivebalance])}," \
646
+ # "#{Integer(htb[:epoch])}," \
647
+ # "#{Integer(htb[:validatorindex])})"
648
+ # end
649
+ # @return [Beaconchain] API blockchain ETH2
650
+ # def apibc
651
+ # @apibc ||= Beaconchain.new(
652
+ # {
653
+ # wb: sql("select * from #{BD}.walletEth2 order by 1"),
654
+ # nb: sql("select itx,iax from #{BD}.eth2bhx")
655
+ # },
656
+ # ops
657
+ # )
658
+ # end
659
+ # @return [String] comando insert SQL formatado eth2bh
660
+ # def eth2bh_ins
661
+ # "insert #{BD}.eth2bh(balance,effectivebalance,epoch,validatorindex" \
662
+ # ") VALUES#{apibc.nov[0..1000].map { |obj| eth2bh_1val(obj) }.join(',')}"
663
+ # end
664
+ # insere transacoes exchange paymium/therock novas na tabela fr/mt (ledger)
665
+ # def processa_frmt
666
+ # puts(format("%<n>4i LEDGER\tPAYMIUM\t\tINSERIDAS fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
667
+ # puts(format("%<n>4i LEDGER\tTHEROCK\t\tINSERIDAS mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
668
+ # end
669
+ # insere historico sados novos na tabela eth2bh
670
+ # def processa_bc
671
+ # puts(format("%<n>4i ATTESTATIONS INSERIDAS eth2at", n: apibc.novtx.empty? ? 0 : dml(eth2at_ins)))
672
+ # puts(format("%<n>4i PROPOSALS INSERIDAS eth2pr", n: apibc.novkx.empty? ? 0 : dml(eth2pr_ins)))
673
+ # puts(format("%<n>4i BALANCES\tETH2\t\tINSERIDOS eth2bh", n: apibc.nov.empty? ? 0 : dml(eth2bh_ins)))
674
+ # end
680
675
  # def eth2at_ins
681
676
  # "insert #{BD}.eth2at(attesterslot,committeeindex,epoch,inclusionslot,status,validatorindex" \
682
677
  # ") VALUES#{apibc.novtx.map { |obj| eth2at_1val(obj) }.join(',')}"
data/lib/cns/etherscan.rb CHANGED
@@ -121,11 +121,11 @@ module Cns
121
121
  id: wbq[:id],
122
122
  ax: xbq = wbq[:ax],
123
123
  bs: wbq[:sl],
124
- bt: bqd[:nt].select { |ont| ont[:iax] == xbq },
125
- bi: bqd[:ni].select { |oni| oni[:iax] == xbq },
126
- bp: bqd[:np].select { |onp| onp[:iax] == xbq },
127
- bw: bqd[:nw].select { |onw| onw[:iax] == xbq },
128
- bk: bqd[:nk].select { |onk| onk[:iax] == xbq },
124
+ bt: bqd[:nt].select { |ont| ont[:axfrom].casecmp?(xbq) },
125
+ bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
126
+ bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
127
+ bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
128
+ bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
129
129
  es: hbc[:sl],
130
130
  et: hbc[:tx],
131
131
  ei: hbc[:ix],
@@ -140,9 +140,9 @@ module Cns
140
140
  # @return [Array<Hash>] lista transacoes/token events filtrada
141
141
  def filtrar_tx(add, ary)
142
142
  # elimina transferencia from: (lax) to: (add) - esta transferencia aparece em from: (add) to: (lax)
143
+ # .delete_if { |odl| add.casecmp?(odl[:to]) && lax.include?(odl[:from].downcase) }
143
144
  # elimina chaves irrelevantes (DL) & adiciona chave indice itx & adiciona identificador da carteira iax
144
- ary.delete_if { |odl| add.casecmp?(odl[:to]) && lax.include?(odl[:from].downcase) }
145
- .map { |omp| omp.delete_if { |key, _| DL.include?(key) }.merge(itx: Integer(omp[:blockNumber]), iax: add) }
145
+ ary.map { |omp| omp.delete_if { |key, _| DL.include?(key) }.merge(itx: Integer(omp[:blockNumber]), iax: add) }
146
146
  end
147
147
 
148
148
  # @param add (see Apibc#norml_es)
@@ -229,9 +229,26 @@ module Cns
229
229
  end
230
230
 
231
231
  # @param (see formata_carteira)
232
+ # @example set hjn
233
+ # {
234
+ # id: wbq[:id],
235
+ # ax: xbq = wbq[:ax],
236
+ # bs: wbq[:sl], INPORTANTE saldo bigquery
237
+ # bt: bqd[:nt].select { |ont| ont[:axfrom].casecmp?(xbq) },
238
+ # bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
239
+ # bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
240
+ # bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
241
+ # bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
242
+ # es: hbc[:sl], INPORTANTE saldo etherscan
243
+ # et: hbc[:tx],
244
+ # ei: hbc[:ix],
245
+ # ep: hbc[:px],
246
+ # ew: hbc[:wx],
247
+ # ek: hbc[:kx]
248
+ # }
232
249
  # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
233
250
  def ok?(hjn)
234
- hjn[:es].round(4) == hjn[:bs].round(4) && 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
251
+ hjn[:es].round(4) == hjn[:bs].round(4) && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bw].count == hjn[:ew].count
235
252
  end
236
253
 
237
254
  # @example ether address inicio..fim
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.5.3'
4
+ VERSION = '0.5.7'
5
5
  end
data/lib/cns.rb CHANGED
@@ -6,7 +6,6 @@ require('cns/apice')
6
6
  require('cns/bigquery')
7
7
  require('cns/etherscan')
8
8
  require('cns/greymass')
9
- require('cns/beaconchain')
10
9
  require('cns/bitcoinde')
11
10
  require('cns/kraken')
12
11
  require('cns/paymium')
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.5.3
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
11
+ date: 2025-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -204,7 +204,6 @@ files:
204
204
  - lib/cns.rb
205
205
  - lib/cns/apibc.rb
206
206
  - lib/cns/apice.rb
207
- - lib/cns/beaconchain.rb
208
207
  - lib/cns/bigquery.rb
209
208
  - lib/cns/bitcoinde.rb
210
209
  - lib/cns/etherscan.rb
@@ -220,7 +219,7 @@ licenses:
220
219
  metadata:
221
220
  homepage_uri: https://github.com/hernanirvaz/cns
222
221
  yard.run: yard
223
- post_install_message:
222
+ post_install_message:
224
223
  rdoc_options: []
225
224
  require_paths:
226
225
  - lib
@@ -236,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
235
  version: '0'
237
236
  requirements: []
238
237
  rubygems_version: 3.3.7
239
- signing_key:
238
+ signing_key:
240
239
  specification_version: 4
241
240
  summary: Arquiva transactions etherscan/greymass/bitcoinde/kraken/paymium/therock
242
241
  no bigquery.
@@ -1,185 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require('bigdecimal/util')
4
-
5
- # @author Hernani Rodrigues Vaz
6
- module Cns
7
- # classe para processar historicos da beaconchain
8
- class Beaconchain
9
- # @return [Apibc] API blockchains
10
- attr_reader :api
11
- # @return [Array<Hash>] todos os dados bigquery
12
- attr_reader :bqd
13
- # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
14
- attr_reader :ops
15
-
16
- # @param [Hash] dad todos os dados bigquery
17
- # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
18
- # @option pop [Boolean] :v (false) mostra saldos?
19
- # @option pop [Boolean] :t (false) mostra todos saldos ou somente novos?
20
- # @return [Beaconchain] API beaconchain - processar historico saldos
21
- def initialize(dad, pop)
22
- @api = Apibc.new
23
- @bqd = dad
24
- @ops = pop
25
- end
26
-
27
- # @return [Array<Hash>] lista balancos novos
28
- def nov
29
- @nov ||= bcd.map { |obc| obc[:bx].select { |obj| idb.include?(itx(obj[:epoch], obj[:validatorindex])) } }.flatten
30
- end
31
-
32
- # @return [Array<Integer>] lista dos meus validators
33
- def lax
34
- @lax ||= bqd[:wb].map { |obj| obj[:id] }
35
- end
36
-
37
- # @return [Array<Hash>] todos os dados beaconchain - saldos & historico
38
- def bcd
39
- @bcd ||= api.data_bc("/api/v1/validator/#{lax.join(',')}").map { |obj| base_bc(obj) }
40
- end
41
-
42
- # @return [Array<Hash>] todos os dados juntos bigquery & beaconchain
43
- def dados
44
- @dados ||= bqd[:wb].map { |obq| bq_bc(obq, bcd.select { |obc| obq[:id] == obc[:ax] }.first) }
45
- end
46
-
47
- # @return [Array<Integer>] lista historicos novos
48
- def idb
49
- @idb ||= bcd.map { |obc| obc[:bx].map { |obj| itx(obj[:epoch], obj[:validatorindex]) } }.flatten -
50
- (ops[:t] ? [] : bqd[:nb].map { |obq| obq[:itx] })
51
- end
52
-
53
- # @param [Integer] intum
54
- # @param [Integer] intdois
55
- # @return [Integer] szudzik pairing two integers
56
- def itx(intum, intdois)
57
- intum >= intdois ? intum * intum + intum + intdois : intum + intdois * intdois
58
- end
59
-
60
- # @example
61
- # {
62
- # activationeligibilityepoch: 0,
63
- # activationepoch: 0,
64
- # balance: 32_489_497_108,
65
- # effectivebalance: 32_000_000_000,
66
- # exitepoch: 9_223_372_036_854_775_807,
67
- # lastattestationslot: 265_446,
68
- # name: '',
69
- # pubkey: '0x93bf23a587f11f9eca329a12ef51296b8a9848af8c0fe61201524b14cb85b0c6fbd3e427501cdfa3b28719bd1ed96fff',
70
- # slashed: false,
71
- # status: 'active_online',
72
- # validatorindex: 11_766,
73
- # withdrawableepoch: 9_223_372_036_854_775_807,
74
- # withdrawalcredentials: '0x004f11be01cb72187715c55d6348c67c5a3880687cd42692306fdbc91ac2da9b'
75
- # }
76
- # @param [Hash] abc account beaconchain
77
- # @return [Hash] dados beaconchain - index, saldo & historico
78
- def base_bc(abc)
79
- acc = abc[:validatorindex]
80
- {
81
- ax: acc,
82
- sl: (abc[:balance].to_d / 10**9).round(10),
83
- bx: api.data_bc("/api/v1/validator/#{acc}/balancehistory")
84
- }
85
- end
86
-
87
- # @param [Hash] wbq wallet bigquery
88
- # @param abc (see base_bc)
89
- # @return [Hash] dados juntos bigquery & beaconchain
90
- def bq_bc(wbq, abc)
91
- xbq = wbq[:id]
92
- {
93
- id: xbq,
94
- ax: wbq[:ax],
95
- bs: wbq[:sl],
96
- bb: bqd[:nb].select { |onb| onb[:iax] == xbq },
97
- es: abc[:sl],
98
- eb: abc[:bx]
99
- }
100
- end
101
-
102
- # @return [String] texto validadores & saldos historicos
103
- def mostra_resumo
104
- return unless dados.count.positive?
105
-
106
- puts("\nindex address beaconchain blh bigquery blh")
107
- dados.each { |obj| puts(formata_validador(obj)) }
108
- mostra_saldos
109
- end
110
-
111
- # @param [Hash] hjn dados juntos bigquery & beaconchain
112
- # @return [String] texto formatado dum validador
113
- def formata_validador(hjn)
114
- format('%<s1>-5.5s %<s2>-34.34s ', s1: hjn[:id], s2: formata_endereco(hjn[:ax], 34)) + formata_valores(hjn)
115
- end
116
-
117
- # @param (see formata_validador)
118
- # @return [String] texto formatado valores dum validador
119
- def formata_valores(hjn)
120
- format(
121
- '%<v1>11.6f %<n1>3i %<v2>12.6f %<n2>6i %<ok>-3s',
122
- v1: hjn[:es],
123
- n1: hjn[:eb].count,
124
- v2: hjn[:bs],
125
- n2: hjn[:bb].count,
126
- ok: ok?(hjn) ? 'OK' : 'NOK'
127
- )
128
- end
129
-
130
- # @param (see formata_validador)
131
- # @return [Boolean] validador tem historicos novos(sim=NOK, nao=OK)?
132
- def ok?(hjn)
133
- hjn[:bs] == hjn[:es]
134
- end
135
-
136
- # @example pubkey inicio..fim
137
- # 0x10f3a0cf0b534c..c033cf32e8a03586
138
- # @param [String] add chave publica validador
139
- # @param [Integer] max chars a mostrar
140
- # @return [String] pubkey formatada
141
- def formata_endereco(add, max)
142
- return 'erro' if max < 7
143
-
144
- max -= 2
145
- ini = Integer(max / 2)
146
- inf = max % 2
147
- "#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
148
- end
149
-
150
- # @example
151
- # {
152
- # balance: 32_489_497_108,
153
- # effectivebalance: 32_000_000_000,
154
- # epoch: 8296,
155
- # validatorindex: 11_766,
156
- # week: 5
157
- # }
158
- # @param [Hash] hbh historico beaconchain
159
- # @return [String] texto formatado historico beaconchain
160
- def formata_saldos(hbh)
161
- idx = hbh[:validatorindex]
162
- epc = hbh[:epoch]
163
- format(
164
- '%<vi>5i %<vl>17.6f %<ep>6i %<id>9i',
165
- vi: idx,
166
- vl: (hbh[:balance].to_d / (10**9)).round(10),
167
- ep: epc,
168
- id: itx(epc, idx)
169
- )
170
- end
171
-
172
- # @return [String] texto historico saldos
173
- def mostra_saldos
174
- return unless ops[:v] && nov.count.positive?
175
-
176
- puts("\nindex saldo epoch itx")
177
- sorbx.each { |obj| puts(formata_saldos(obj)) }
178
- end
179
-
180
- # @return [Array<Hash>] lista ordenada historico saldos
181
- def sorbx
182
- nov.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
183
- end
184
- end
185
- end