cns 0.1.6 → 0.1.8

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: ef054c95506b8f32415f3c3f47b2272886ac824f10666c91a4bd0f3b118b3ffb
4
- data.tar.gz: c18711c2d3ffcdf131218d3509f954f163046fa5b498e39b47e15332b3fb53a1
3
+ metadata.gz: cc5b551cbe1640989e78c17c34c848e288c2e4f4362728b80f1f66b105b37330
4
+ data.tar.gz: 2dc4fa72a53d44b8414e22c5e823de2536acfdf2d44ba4f91ab13819264db712
5
5
  SHA512:
6
- metadata.gz: ef30f7f2617710c765d6dd8d4a21e673a55da5aa59ee4bb1ac15343c70a9ee5cfa7b9e26ccc01019c53cbd69d571fd07981e3bba35fbc53a04d308ccd61d118c
7
- data.tar.gz: df9e5fbe45744df8bb75dc5b8145fe8f875a6085877d8709e9cc7d2cf5a907ec797a9cad8f3c557b7599bfc079873822e7c4aa390334e8696dd3b21aa57c0db5
6
+ metadata.gz: 338cefa7800ece67c7b846a14b14aae3613cf510362a68fb41c3684216c7cc09108ca5386f94b423731435787c2de5c6bca8318ff30ff8b9ff860c76dec52f44
7
+ data.tar.gz: 9541c7a135edfb7a272b3118083714c4629b5ef46b065db710f32c41791f9385a3b75188521b123db6a699605b00ec3c27de71b9cdfaf8f398f70e3419ad7c70
data/.reek.yml CHANGED
@@ -37,18 +37,25 @@ detectors:
37
37
  - "Cns::Greymass#formata_carteira"
38
38
  - "Cns::Greymass#formata_ledger"
39
39
  - "Cns::Greymass#filtrar_tx"
40
+ - "Cns::Beaconchain#base_bc"
41
+ - "Cns::Beaconchain#bq_bc"
40
42
  - "Cns::Kraken#formata_ledger"
41
43
  - "Cns::Kraken#formata_trades"
42
44
  - "Cns::Paymium#formata_ledger"
43
45
  - "Cns::Paymium#formata_uuid"
44
46
  - "Cns::TheRock#formata_ledger"
45
47
  - "Cns::TheRock#formata_saldos"
48
+ - "Cns::Beaconchain#formata_saldos"
49
+ - "Cns::Beaconchain#formata_endereco"
50
+ - "Cns::Beaconchain#formata_valores"
46
51
  UtilityFunction:
47
52
  exclude:
48
53
  - "Cns::Apice#hus"
49
54
  - "Cns::Bigquery#del_val"
50
55
  - "Cns::Etherscan#ok?"
51
56
  - "Cns::Greymass#ok?"
57
+ - "Cns::Beaconchain#itx"
58
+ - "Cns::Beaconchain#ok?"
52
59
  NestedIterators:
53
60
  exclude:
54
61
  - "Cns::Etherscan#idk"
@@ -62,3 +69,6 @@ detectors:
62
69
  - "Cns::Greymass#dados"
63
70
  - "Cns::Paymium#kyl"
64
71
  - "Cns::Paymium#ledger"
72
+ - "Cns::Beaconchain#dados"
73
+ - "Cns::Beaconchain#idb"
74
+ - "Cns::Beaconchain#nov"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.1.6)
4
+ cns (0.1.8)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
@@ -14,15 +14,17 @@ GEM
14
14
  public_suffix (>= 2.0.2, < 5.0)
15
15
  ast (2.4.1)
16
16
  backport (1.1.2)
17
- benchmark (0.1.0)
17
+ benchmark (0.1.1)
18
18
  concurrent-ruby (1.1.7)
19
19
  curb (0.9.11)
20
20
  declarative (0.0.20)
21
21
  declarative-option (0.1.0)
22
22
  e2mmap (0.1.0)
23
- faraday (1.1.0)
23
+ faraday (1.3.0)
24
+ faraday-net_http (~> 1.0)
24
25
  multipart-post (>= 1.2, < 3)
25
26
  ruby2_keywords
27
+ faraday-net_http (1.0.0)
26
28
  google-api-client (0.52.0)
27
29
  addressable (~> 2.5, >= 2.5.1)
28
30
  googleauth (~> 0.9)
@@ -61,17 +63,19 @@ GEM
61
63
  kwalify (0.7.2)
62
64
  memoist (0.16.2)
63
65
  mini_mime (1.0.2)
64
- mini_portile2 (2.4.0)
66
+ mini_portile2 (2.5.0)
65
67
  multi_json (1.15.0)
66
68
  multipart-post (2.1.1)
67
- nokogiri (1.10.10)
68
- mini_portile2 (~> 2.4.0)
69
+ nokogiri (1.11.1)
70
+ mini_portile2 (~> 2.5.0)
71
+ racc (~> 1.4)
69
72
  os (1.1.1)
70
73
  parallel (1.20.1)
71
74
  parser (2.7.2.0)
72
75
  ast (~> 2.4.1)
73
- psych (3.2.1)
76
+ psych (3.3.0)
74
77
  public_suffix (4.0.6)
78
+ racc (1.5.2)
75
79
  rainbow (3.0.0)
76
80
  rake (12.3.3)
77
81
  reek (6.0.2)
@@ -79,7 +83,7 @@ GEM
79
83
  parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
80
84
  psych (~> 3.1)
81
85
  rainbow (>= 2.0, < 4.0)
82
- regexp_parser (2.0.1)
86
+ regexp_parser (2.0.3)
83
87
  representable (3.0.4)
84
88
  declarative (< 0.1.0)
85
89
  declarative-option (< 0.2.0)
@@ -88,7 +92,7 @@ GEM
88
92
  reverse_markdown (2.0.0)
89
93
  nokogiri
90
94
  rexml (3.2.4)
91
- rubocop (1.6.1)
95
+ rubocop (1.7.0)
92
96
  parallel (~> 1.10)
93
97
  parser (>= 2.7.1.5)
94
98
  rainbow (>= 2.2.2, < 4.0)
@@ -97,18 +101,18 @@ GEM
97
101
  rubocop-ast (>= 1.2.0, < 2.0)
98
102
  ruby-progressbar (~> 1.7)
99
103
  unicode-display_width (>= 1.4.0, < 2.0)
100
- rubocop-ast (1.3.0)
104
+ rubocop-ast (1.4.0)
101
105
  parser (>= 2.7.1.5)
102
106
  rubocop-rake (0.5.1)
103
107
  rubocop
104
- ruby-progressbar (1.10.1)
108
+ ruby-progressbar (1.11.0)
105
109
  ruby2_keywords (0.0.2)
106
110
  signet (0.14.0)
107
111
  addressable (~> 2.3)
108
112
  faraday (>= 0.17.3, < 2.0)
109
113
  jwt (>= 1.5, < 3.0)
110
114
  multi_json (~> 1.10)
111
- solargraph (0.40.0)
115
+ solargraph (0.40.1)
112
116
  backport (~> 1.1)
113
117
  benchmark
114
118
  bundler (>= 1.17.2)
@@ -126,7 +130,7 @@ GEM
126
130
  tilt (2.0.10)
127
131
  uber (0.1.0)
128
132
  unicode-display_width (1.7.0)
129
- yard (0.9.25)
133
+ yard (0.9.26)
130
134
 
131
135
  PLATFORMS
132
136
  ruby
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')
@@ -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(1.5)
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',
@@ -20,13 +31,14 @@ module Cns
20
31
  # @return [Array<Hash>] lista enderecos e seus saldos
21
32
  def account_es(ads)
22
33
  JSON.parse(
23
- conn_es.get('api', action: 'balancemulti', tag: 'latest', address: ads.join(',')).body,
34
+ conn_es.get('/api', action: 'balancemulti', tag: 'latest', address: ads.join(',')).body,
24
35
  symbolize_names: true
25
36
  )[:result]
26
37
  rescue StandardError
27
38
  []
28
39
  end
29
40
 
41
+ # @example account_gm
30
42
  # @example account_gm
31
43
  # {
32
44
  # account_name: '...',
@@ -119,7 +131,7 @@ module Cns
119
131
  # @return [Array<Hash>] lista completa transacoes etherscan
120
132
  def norml_es(add, pag = 0, aes = [])
121
133
  res = JSON.parse(
122
- conn_es.get('api', action: 'txlist', offset: 10_000, address: add, page: pag += 1).body,
134
+ conn_es.get('/api', action: 'txlist', offset: 10_000, address: add, page: pag += 1).body,
123
135
  symbolize_names: true
124
136
  )[:result]
125
137
  aes += res
@@ -164,7 +176,7 @@ module Cns
164
176
  # -quando ha erros na blockchain (acho)
165
177
  # -quando ha token events identicos no mesmo block (acho)
166
178
  res = JSON.parse(
167
- conn_es.get('api', action: 'tokentx', offset: 10_000, address: add, page: pag += 1).body,
179
+ conn_es.get('/api', action: 'tokentx', offset: 10_000, address: add, page: pag += 1).body,
168
180
  symbolize_names: true
169
181
  )[:result]
170
182
  aes += res
@@ -245,7 +257,7 @@ module Cns
245
257
  def conn_es
246
258
  @conn_es ||=
247
259
  Faraday.new(
248
- url: 'https://api.etherscan.io/',
260
+ url: 'https://api.etherscan.io',
249
261
  params: { module: 'account', apikey: ENV['ETHERSCAN_API_KEY'] },
250
262
  headers: { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
251
263
  ) do |con|
@@ -262,5 +274,14 @@ module Cns
262
274
  con.adapter(adapter)
263
275
  end
264
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)
284
+ end
285
+ end
265
286
  end
266
287
  end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('bigdecimal/util')
4
+
5
+ # @author Hernani Rodrigues Vaz
6
+ module Cns
7
+ # (see 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
+ end
102
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @author Hernani Rodrigues Vaz
4
+ module Cns
5
+ # classe para processar historicos da beaconchain
6
+ class Beaconchain
7
+ # @return [String] texto validadores & saldos historicos
8
+ def mostra_resumo
9
+ return unless dados.count.positive?
10
+
11
+ puts("\nindex address beaconchain blh bigquery blh")
12
+ dados.each { |obj| puts(formata_validador(obj)) }
13
+ mostra_saldos
14
+ end
15
+
16
+ # @param [Hash] hjn dados juntos bigquery & beaconchain
17
+ # @return [String] texto formatado dum validador
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)
24
+ end
25
+
26
+ # @param (see formata_validador)
27
+ # @return [String] texto formatado valores dum validador
28
+ def formata_valores(hjn)
29
+ format(
30
+ '%<v1>11.6f %<n1>3i %<v2>12.6f %<n2>6i %<ok>-3s',
31
+ v1: hjn[:es],
32
+ n1: hjn[:eb].count,
33
+ v2: hjn[:bs],
34
+ n2: hjn[:bb].count,
35
+ ok: ok?(hjn) ? 'OK' : 'NOK'
36
+ )
37
+ end
38
+
39
+ # @param (see formata_validador)
40
+ # @return [Boolean] validador tem historicos novos(sim=NOK, nao=OK)?
41
+ def ok?(hjn)
42
+ hjn[:bs] == hjn[:es]
43
+ end
44
+
45
+ # @example pubkey inicio..fim
46
+ # 0x10f3a0cf0b534c..c033cf32e8a03586
47
+ # @param [String] add chave publica validador
48
+ # @param [Integer] max chars a mostrar
49
+ # @return [String] pubkey formatada
50
+ def formata_endereco(add, max)
51
+ int = Integer((max - 2) / 2)
52
+ max < 7 ? 'erro' : "#{add[0, int - 3]}..#{add[-int - 3..]}"
53
+ end
54
+
55
+ # @example
56
+ # {
57
+ # balance: 32_489_497_108,
58
+ # effectivebalance: 32_000_000_000,
59
+ # epoch: 8296,
60
+ # validatorindex: 11_766,
61
+ # week: 5
62
+ # }
63
+ # @param [Hash] hbh historico beaconchain
64
+ # @return [String] texto formatado historico beaconchain
65
+ def formata_saldos(hbh)
66
+ idx = hbh[:validatorindex]
67
+ epc = hbh[:epoch]
68
+ format(
69
+ '%<vi>5i %<vl>17.6f %<ep>6i %<id>9i',
70
+ vi: idx,
71
+ vl: (hbh[:balance].to_d / 10**9).round(10),
72
+ ep: epc,
73
+ id: itx(epc, idx)
74
+ )
75
+ end
76
+
77
+ # @return [String] texto historico saldos
78
+ def mostra_saldos
79
+ return unless ops[:v] && nov.count.positive?
80
+
81
+ puts("\nindex saldo epoch itx")
82
+ sorbx.each { |obj| puts(formata_saldos(obj)) }
83
+ end
84
+
85
+ # @return [Array<Hash>] lista ordenada historico saldos
86
+ def sorbx
87
+ nov.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
88
+ end
89
+ end
90
+ end
@@ -30,7 +30,7 @@ module Cns
30
30
  @ops = pop
31
31
  end
32
32
 
33
- # mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass & bigquery
33
+ # mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain & bigquery
34
34
  def mostra_tudo
35
35
  apius.mostra_resumo
36
36
  apide.mostra_resumo
@@ -38,16 +38,17 @@ module Cns
38
38
  apimt.mostra_resumo
39
39
  apies.mostra_resumo
40
40
  apigm.mostra_resumo
41
+ apibc.mostra_resumo
41
42
  end
42
43
 
43
- # insere (caso existam) transacoes novas kraken/bitcoinde/paymium/therock/etherscan/greymass no bigquery
44
+ # insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain no bigquery
44
45
  def processa_tudo
45
46
  processa_us
46
47
  processa_de
47
- processa_fr
48
- processa_mt
48
+ processa_frmt
49
49
  processa_eth
50
50
  processa_eos
51
+ processa_bc
51
52
  end
52
53
 
53
54
  private
@@ -64,13 +65,9 @@ module Cns
64
65
  puts(format("%<n>2i LEDGER BITCOINDE INSERIDAS #{BD}.del", n: apide.ledger.empty? ? 0 : dml(del_ins)))
65
66
  end
66
67
 
67
- # insere transacoes exchange paymium novas na tabela fr (ledger)
68
- def processa_fr
68
+ # insere transacoes exchange paymium/therock novas na tabela fr/mt (ledger)
69
+ def processa_frmt
69
70
  puts(format("%<n>2i LEDGER PAYMIUM INSERIDAS #{BD}.fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
70
- end
71
-
72
- # insere transacoes exchange therock novas na tabela mt (ledger)
73
- def processa_mt
74
71
  puts(format("%<n>2i LEDGER THEROCK INSERIDAS #{BD}.mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
75
72
  end
76
73
 
@@ -85,6 +82,13 @@ module Cns
85
82
  puts(format("%<n>2i TRANSACOES EOS INSERIDAS #{BD}.eos ", n: apigm.novax.empty? ? 0 : dml(eost_ins)))
86
83
  end
87
84
 
85
+ # insere historico sados novos na tabela eth2bh
86
+ def processa_bc
87
+ # puts(format("%<n>2i ATTESTATIONS INSERIDAS #{BD}.eth2at", n: apibc.novtx.empty? ? 0 : dml(eth2at_ins)))
88
+ # puts(format("%<n>2i PROPOSALS INSERIDAS #{BD}.eth2pr", n: apibc.novkx.empty? ? 0 : dml(eth2pr_ins)))
89
+ puts(format("%<n>2i BALANCES INSERIDOS #{BD}.eth2bh", n: apibc.nov.empty? ? 0 : dml(eth2bh_ins)))
90
+ end
91
+
88
92
  # cria job bigquery & verifica execucao
89
93
  #
90
94
  # @param cmd (see sql)
@@ -6,6 +6,18 @@ module Cns
6
6
  class Bigquery
7
7
  private
8
8
 
9
+ # @return [String] comando insert SQL formatado fr (ledger)
10
+ def mtl_ins
11
+ "insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
12
+ "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
13
+ end
14
+
15
+ # @return [String] comando insert SQL formatado eth2bh
16
+ def eth2bh_ins
17
+ "insert #{BD}.eth2bh(balance,effectivebalance,epoch,validatorindex" \
18
+ ") VALUES#{apibc.nov[0..900].map { |obj| eth2bh_1val(obj) }.join(',')}"
19
+ end
20
+
9
21
  # @return [Etherscan] API blockchain ETH
10
22
  def apies
11
23
  @apies ||= Etherscan.new(
@@ -29,6 +41,17 @@ module Cns
29
41
  )
30
42
  end
31
43
 
44
+ # @return [Beaconchain] API blockchain ETH2
45
+ def apibc
46
+ @apibc ||= Beaconchain.new(
47
+ {
48
+ wb: sql("select * from #{BD}.walletEth2 order by 1"),
49
+ nb: sql("select itx,iax from #{BD}.eth2bhx")
50
+ },
51
+ ops
52
+ )
53
+ end
54
+
32
55
  # @return [Kraken] API exchange kraken
33
56
  def apius
34
57
  @apius ||= Kraken.new(
@@ -29,14 +29,14 @@ module Cns
29
29
  ") VALUES#{apigm.novax.map { |obj| eost_1val(obj) }.join(',')}"
30
30
  end
31
31
 
32
- # @return [String] comando insert SQL formatado det (trades)
33
- def det_ins
34
- "insert #{BD}.det(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_1val(obj) }.join(',')}"
35
- end
36
-
37
- # @return [String] comando insert SQL formatado del (ledger)
38
- def del_ins
39
- "insert #{BD}.del(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
32
+ # @example (see Beaconchain#formata_saldos)
33
+ # @param (see Beaconchain#formata_saldos)
34
+ # @return [String] valores formatados etht (norml parte1)
35
+ def eth2bh_1val(htb)
36
+ "(#{Integer(htb[:balance])}," \
37
+ "#{Integer(htb[:effectivebalance])}," \
38
+ "#{Integer(htb[:epoch])}," \
39
+ "#{Integer(htb[:validatorindex])})"
40
40
  end
41
41
 
42
42
  # @example (see Apibc#norml_es)
@@ -145,5 +145,52 @@ module Cns
145
145
  "nullif('#{str.gsub(/['"]/, '')}','nil')," \
146
146
  "#{ops[:h][String(hlx[:itx])] || 0})"
147
147
  end
148
+
149
+ # def eth2at_ins
150
+ # "insert #{BD}.eth2at(attesterslot,committeeindex,epoch,inclusionslot,status,validatorindex" \
151
+ # ") VALUES#{apibc.novtx.map { |obj| eth2at_1val(obj) }.join(',')}"
152
+ # end
153
+ # def eth2pr_ins
154
+ # "insert #{BD}.eth2pr(attestationscount,attesterslashingscount,blockroot,depositscount,epoch," \
155
+ # 'eth1data_blockhash,eth1data_depositcount,eth1data_depositroot,graffiti,graffiti_text,parentroot,' \
156
+ # 'proposer,proposerslashingscount,randaoreveal,signature,slot,stateroot,status,voluntaryexitscount' \
157
+ # ") VALUES#{apibc.novkx.map { |obj| eth2pr_1val(obj) }.join(',')}"
158
+ # end
159
+ # def eth2at_1val(htx)
160
+ # "(#{Integer(htx[:attesterslot])}," \
161
+ # "#{Integer(htx[:committeeindex])}," \
162
+ # "#{Integer(htx[:epoch])}," \
163
+ # "#{Integer(htx[:inclusionslot])}," \
164
+ # "#{Integer(htx[:status])}," \
165
+ # "#{Integer(htx[:validatorindex])})"
166
+ # end
167
+ # def eth2pr_1val(htx)
168
+ # "(#{Integer(htx[:attestationscount])}," \
169
+ # "#{Integer(htx[:attesterslashingscount])}," \
170
+ # "'#{htx[:blockroot]}'," \
171
+ # "#{Integer(htx[:depositscount])}," \
172
+ # "#{Integer(htx[:epoch])}," \
173
+ # "'#{htx[:eth1data_blockhash]}'," \
174
+ # "#{eth2pr_2val(htx)}"
175
+ # end
176
+ # def eth2pr_2val(htx)
177
+ # grf = htx[:graffiti_text]
178
+ # "#{Integer(htx[:eth1data_depositcount])}," \
179
+ # "'#{htx[:eth1data_depositroot]}'," \
180
+ # "'#{htx[:graffiti]}'," \
181
+ # "#{grf.length.zero? ? 'null' : "'#{grf}'"}," \
182
+ # "'#{htx[:parentroot]}'," \
183
+ # "#{Integer(htx[:proposer])}," \
184
+ # "#{eth2pr_3val(htx)}"
185
+ # end
186
+ # def eth2pr_3val(htx)
187
+ # "#{Integer(htx[:proposerslashingscount])}," \
188
+ # "'#{htx[:randaoreveal]}'," \
189
+ # "'#{htx[:signature]}'," \
190
+ # "#{Integer(htx[:slot])}," \
191
+ # "'#{htx[:stateroot]}'," \
192
+ # "#{Integer(htx[:status])}," \
193
+ # "#{Integer(htx[:voluntaryexitscount])})"
194
+ # end
148
195
  end
149
196
  end
@@ -6,6 +6,16 @@ module Cns
6
6
  class Bigquery
7
7
  private
8
8
 
9
+ # @return [String] comando insert SQL formatado det (trades)
10
+ def det_ins
11
+ "insert #{BD}.det(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_1val(obj) }.join(',')}"
12
+ end
13
+
14
+ # @return [String] comando insert SQL formatado del (ledger)
15
+ def del_ins
16
+ "insert #{BD}.del(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
17
+ end
18
+
9
19
  # @return [String] comando insert SQL formatado ust (trades)
10
20
  def ust_ins
11
21
  "insert #{BD}.ust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
@@ -23,12 +33,6 @@ module Cns
23
33
  "insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
24
34
  end
25
35
 
26
- # @return [String] comando insert SQL formatado fr (ledger)
27
- def mtl_ins
28
- "insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
29
- "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
30
- end
31
-
32
36
  # @example (see Apice#trades_de)
33
37
  # @param [Hash] htx trade bitcoinde
34
38
  # @return [String] valores formatados det (trades parte1)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.8'
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.1.6
4
+ version: 0.1.8
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: 2020-12-21 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -191,6 +191,8 @@ files:
191
191
  - lib/cns/apibc.rb
192
192
  - lib/cns/apice1.rb
193
193
  - lib/cns/apice2.rb
194
+ - lib/cns/beaconchain1.rb
195
+ - lib/cns/beaconchain2.rb
194
196
  - lib/cns/bigquery1.rb
195
197
  - lib/cns/bigquery2.rb
196
198
  - lib/cns/bigquery3.rb