cns 0.5.5 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +28 -24
- data/lib/cns/apibc.rb +18 -19
- data/lib/cns/bigquery.rb +48 -53
- data/lib/cns/etherscan.rb +25 -8
- data/lib/cns/version.rb +1 -1
- data/lib/cns.rb +0 -1
- metadata +2 -3
- data/lib/cns/beaconchain.rb +0 -185
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a2b6e7061f6b33a63f0f488471c29ee549d61e31d46fa3fc4b9c577571087cf
|
4
|
+
data.tar.gz: '0728c393086fe4ea971a98ba8730c9750a1694b0f3be9139647892a1e211dfdb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
4
|
+
cns (0.5.7)
|
5
5
|
curb
|
6
6
|
faraday
|
7
7
|
google-cloud-bigquery
|
@@ -16,20 +16,20 @@ GEM
|
|
16
16
|
backport (1.2.0)
|
17
17
|
base64 (0.2.0)
|
18
18
|
benchmark (0.4.0)
|
19
|
-
bigdecimal (3.1.
|
20
|
-
concurrent-ruby (1.3.
|
19
|
+
bigdecimal (3.1.9)
|
20
|
+
concurrent-ruby (1.3.5)
|
21
21
|
curb (1.0.6)
|
22
22
|
declarative (0.0.20)
|
23
23
|
e2mmap (0.1.0)
|
24
|
-
faraday (2.12.
|
25
|
-
faraday-net_http (>= 2.0, < 3.
|
24
|
+
faraday (2.12.2)
|
25
|
+
faraday-net_http (>= 2.0, < 3.5)
|
26
26
|
json
|
27
27
|
logger
|
28
|
-
faraday-net_http (3.
|
29
|
-
net-http
|
30
|
-
google-apis-bigquery_v2 (0.
|
28
|
+
faraday-net_http (3.4.0)
|
29
|
+
net-http (>= 0.5.0)
|
30
|
+
google-apis-bigquery_v2 (0.83.0)
|
31
31
|
google-apis-core (>= 0.15.0, < 2.a)
|
32
|
-
google-apis-core (0.
|
32
|
+
google-apis-core (0.16.0)
|
33
33
|
addressable (~> 2.5, >= 2.5.1)
|
34
34
|
googleauth (~> 1.9)
|
35
35
|
httpclient (>= 2.8.3, < 3.a)
|
@@ -37,7 +37,7 @@ GEM
|
|
37
37
|
mutex_m
|
38
38
|
representable (~> 3.0)
|
39
39
|
retriable (>= 2.0, < 4.a)
|
40
|
-
google-cloud-bigquery (1.
|
40
|
+
google-cloud-bigquery (1.51.1)
|
41
41
|
bigdecimal (~> 3.0)
|
42
42
|
concurrent-ruby (~> 1.0)
|
43
43
|
google-apis-bigquery_v2 (~> 0.71)
|
@@ -51,30 +51,34 @@ GEM
|
|
51
51
|
google-cloud-env (2.2.1)
|
52
52
|
faraday (>= 1.0, < 3.a)
|
53
53
|
google-cloud-errors (1.4.0)
|
54
|
-
|
54
|
+
google-logging-utils (0.1.0)
|
55
|
+
googleauth (1.13.1)
|
55
56
|
faraday (>= 1.0, < 3.a)
|
56
|
-
google-cloud-env (~> 2.
|
57
|
+
google-cloud-env (~> 2.2)
|
58
|
+
google-logging-utils (~> 0.1)
|
57
59
|
jwt (>= 1.4, < 3.0)
|
58
60
|
multi_json (~> 1.11)
|
59
61
|
os (>= 0.9, < 2.0)
|
60
62
|
signet (>= 0.16, < 2.a)
|
61
63
|
httpclient (2.8.3)
|
62
64
|
jaro_winkler (1.6.0)
|
63
|
-
json (2.
|
64
|
-
jwt (2.
|
65
|
+
json (2.9.1)
|
66
|
+
jwt (2.10.1)
|
65
67
|
base64
|
66
|
-
kramdown (2.
|
67
|
-
rexml
|
68
|
+
kramdown (2.5.1)
|
69
|
+
rexml (>= 3.3.9)
|
68
70
|
kramdown-parser-gfm (1.1.0)
|
69
71
|
kramdown (~> 2.0)
|
70
72
|
kwalify (0.7.2)
|
71
|
-
logger (1.6.
|
73
|
+
logger (1.6.5)
|
72
74
|
mini_mime (1.1.5)
|
75
|
+
mini_portile2 (2.8.8)
|
73
76
|
multi_json (1.15.0)
|
74
|
-
mutex_m (0.
|
75
|
-
net-http (0.
|
77
|
+
mutex_m (0.3.0)
|
78
|
+
net-http (0.6.0)
|
76
79
|
uri
|
77
|
-
nokogiri (1.
|
80
|
+
nokogiri (1.18.2)
|
81
|
+
mini_portile2 (~> 2.8.2)
|
78
82
|
racc (~> 1.4)
|
79
83
|
os (1.1.4)
|
80
84
|
parallel (1.26.3)
|
@@ -90,7 +94,7 @@ GEM
|
|
90
94
|
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
|
91
95
|
psych (~> 3.1)
|
92
96
|
rainbow (>= 2.0, < 4.0)
|
93
|
-
regexp_parser (2.
|
97
|
+
regexp_parser (2.10.0)
|
94
98
|
representable (3.2.0)
|
95
99
|
declarative (< 0.1.0)
|
96
100
|
trailblazer-option (>= 0.1.1, < 0.2.0)
|
@@ -98,7 +102,7 @@ GEM
|
|
98
102
|
retriable (3.1.2)
|
99
103
|
reverse_markdown (2.1.1)
|
100
104
|
nokogiri
|
101
|
-
rexml (3.
|
105
|
+
rexml (3.4.0)
|
102
106
|
rubocop (1.7.0)
|
103
107
|
parallel (~> 1.10)
|
104
108
|
parser (>= 2.7.1.5)
|
@@ -137,11 +141,11 @@ GEM
|
|
137
141
|
tilt (~> 2.0)
|
138
142
|
yard (~> 0.9, >= 0.9.24)
|
139
143
|
thor (1.3.2)
|
140
|
-
tilt (2.
|
144
|
+
tilt (2.6.0)
|
141
145
|
trailblazer-option (0.1.2)
|
142
146
|
uber (0.1.0)
|
143
147
|
unicode-display_width (1.8.0)
|
144
|
-
uri (1.0.
|
148
|
+
uri (1.0.2)
|
145
149
|
yard (0.9.37)
|
146
150
|
|
147
151
|
PLATFORMS
|
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
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
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
|
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
|
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
|
201
|
-
ni: sql("select
|
202
|
-
np: sql("select
|
203
|
-
nw: sql("select
|
204
|
-
nk: sql("select
|
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
|
216
|
-
ni: sql("select
|
217
|
-
np: sql("select
|
218
|
-
nw: sql("select
|
219
|
-
nk: sql("select
|
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
|
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[:
|
125
|
-
bi: bqd[:ni].select { |oni| oni[:iax]
|
126
|
-
bp: bqd[:np].select { |onp| onp[:iax]
|
127
|
-
bw: bqd[:nw].select { |onw| onw[:iax]
|
128
|
-
bk: bqd[:nk].select { |onk| onk[:iax]
|
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 { |
|
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[:
|
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
data/lib/cns.rb
CHANGED
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.
|
4
|
+
version: 0.5.7
|
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:
|
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
|
data/lib/cns/beaconchain.rb
DELETED
@@ -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
|