cns 0.8.9 → 0.9.0

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: aa9737420761247a9d82111220ba71741c591fa08fe035da2f8f4717cd8b179d
4
- data.tar.gz: 6e5b7f03930de50c278a0a1d0a6442b6535c67bfa1874f0402b2c4075c363108
3
+ metadata.gz: fff5558da7a0b92a4511bf3f73b8330d3ad59d92d46c76b64a70bfd19e3dfd1e
4
+ data.tar.gz: eafa8884b41f68f83fa20b547474c7a0717281f8c47d0a948805e9d0a7ae19f4
5
5
  SHA512:
6
- metadata.gz: 92144b9670390bf051d131f2bdf1b35a8c475ac16fa935dc2f6bb37b04298a5304ceadceeac467da687d70e847ee5cfc3974d6deca8519b8a368c3bec446334d
7
- data.tar.gz: 1f519cc3912a0ea47d1cabb557eb191c04dafd6dc308d08da23969ae2fc604f720f3441844c277b1259f446a20aad28645ccf4868d6c5e795efeef17e7f5ef97
6
+ metadata.gz: 8409acef5de4ce834e309710521c44cfe35414e3ec6c3d11b8dce9173720414d828fb320c6865c693867bdac1bf14c41e8f6ac5ac5172dc11253ff77683cd307
7
+ data.tar.gz: 072e66dc223d7c14c20248f25e2c5a72f5e918314881c60faf3b8377cb77d11534d9c5b6d0eaf8e2ab2c7966c4956414d3bfdf433b98e57eb3691fa0b46e78ac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.8.9)
4
+ cns (0.9.0)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
@@ -137,7 +137,7 @@ GEM
137
137
  reverse_markdown (3.0.0)
138
138
  nokogiri
139
139
  rexml (3.4.1)
140
- rubocop (1.72.2)
140
+ rubocop (1.73.1)
141
141
  json (~> 2.3)
142
142
  language_server-protocol (~> 3.17.0.2)
143
143
  lint_roller (~> 1.1.0)
@@ -148,7 +148,7 @@ GEM
148
148
  rubocop-ast (>= 1.38.0, < 2.0)
149
149
  ruby-progressbar (~> 1.7)
150
150
  unicode-display_width (>= 2.4.0, < 4.0)
151
- rubocop-ast (1.38.0)
151
+ rubocop-ast (1.38.1)
152
152
  parser (>= 3.3.1.0)
153
153
  rubocop-rake (0.7.1)
154
154
  lint_roller (~> 1.1)
@@ -159,7 +159,7 @@ GEM
159
159
  faraday (>= 0.17.5, < 3.a)
160
160
  jwt (>= 1.5, < 3.0)
161
161
  multi_json (~> 1.10)
162
- solargraph (0.51.2)
162
+ solargraph (0.52.0)
163
163
  backport (~> 1.2)
164
164
  benchmark
165
165
  bundler (~> 2.0)
@@ -177,6 +177,7 @@ GEM
177
177
  thor (~> 1.0)
178
178
  tilt (~> 2.0)
179
179
  yard (~> 0.9, >= 0.9.24)
180
+ yard-solargraph (~> 0.1)
180
181
  thor (1.3.2)
181
182
  tilt (2.6.0)
182
183
  trailblazer-option (0.1.2)
@@ -184,8 +185,10 @@ GEM
184
185
  unicode-display_width (3.1.4)
185
186
  unicode-emoji (~> 4.0, >= 4.0.4)
186
187
  unicode-emoji (4.0.4)
187
- uri (1.0.2)
188
+ uri (1.0.3)
188
189
  yard (0.9.37)
190
+ yard-solargraph (0.1.0)
191
+ yard (~> 0.9)
189
192
  zeitwerk (2.6.18)
190
193
 
191
194
  PLATFORMS
data/lib/cns/bigquery.rb CHANGED
@@ -45,8 +45,8 @@ module Cns
45
45
  def mtudo
46
46
  apius.mresumo
47
47
  apide.mresumo
48
- # apies.mresumo
49
- # apigm.mresumo
48
+ apies.mresumo
49
+ apigm.mresumo
50
50
  end
51
51
 
52
52
  # mostra situacao completa entre kraken/etherscan & bigquery
@@ -183,26 +183,12 @@ module Cns
183
183
 
184
184
  # @return [Kraken] API exchange kraken
185
185
  def apius
186
- @apius ||= Kraken.new(
187
- {
188
- sl: sql("select * from #{BD}.cuss").first,
189
- nt: sql("select * from #{BD}.cust order by time,txid"),
190
- nl: sql("select * from #{BD}.cusl order by time,txid")
191
- },
192
- ops
193
- )
186
+ @apius ||= Kraken.new({ sl: sql("select * from #{BD}.cuss").first, nt: sql("select * from #{BD}.cust"), nl: sql("select * from #{BD}.cusl") }, ops)
194
187
  end
195
188
 
196
189
  # @return [Bitcoinde] API exchange bitcoinde
197
190
  def apide
198
- @apide ||= Bitcoinde.new(
199
- {
200
- sl: sql("select * from #{BD}.cdes").first,
201
- nt: sql("select * from #{BD}.cdet order by time,txid"),
202
- nl: sql("select * from #{BD}.cdel order by time,txid")
203
- },
204
- ops
205
- )
191
+ @apide ||= Bitcoinde.new({ sl: sql("select * from #{BD}.cdes").first, nt: sql("select * from #{BD}.cdet"), nl: sql("select * from #{BD}.cdel") }, ops)
206
192
  end
207
193
 
208
194
  def tabelas_cus(src, str, ltb, prx = '')
data/lib/cns/bitcoinde.rb CHANGED
@@ -30,16 +30,6 @@ module Cns
30
30
  @exd ||= { sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de) }
31
31
  end
32
32
 
33
- # @return [Array<Hash>] lista trades bitcoinde novos
34
- def novcdet
35
- @novcdet ||= exd[:tt].select { |obj| kyt.include?(obj[:trade_id]) }
36
- end
37
-
38
- # @return [Array<Hash>] lista ledger (deposits + withdrawals) bitcoinde novos
39
- def novcdel
40
- @novcdel ||= exd[:tl].select { |obj| kyl.include?(obj[:txid]) }
41
- end
42
-
43
33
  # @return [String] texto saldos & transacoes & ajuste dias
44
34
  def mresumo
45
35
  puts("\nBITCOINDE\ntipo bitcoinde bigquery")
@@ -60,11 +50,11 @@ module Cns
60
50
  end
61
51
 
62
52
  def bqkyt
63
- show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid] } || [])
53
+ @bqkyt ||= show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid] } || [])
64
54
  end
65
55
 
66
56
  def bqkyl
67
- show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid] } || [])
57
+ @bqkyl ||= show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid] } || [])
68
58
  end
69
59
 
70
60
  # @return [Array<String>] lista txid dos trades novos
@@ -77,6 +67,16 @@ module Cns
77
67
  @kyl ||= exd[:tl].map { |oex| oex[:txid] } - bqkyl
78
68
  end
79
69
 
70
+ # @return [Array<Hash>] lista trades bitcoinde novos
71
+ def novcdet
72
+ @novcdet ||= exd[:tt].select { |obj| kyt.include?(obj[:trade_id]) }
73
+ end
74
+
75
+ # @return [Array<Hash>] lista ledger (deposits + withdrawals) bitcoinde novos
76
+ def novcdel
77
+ @novcdel ||= exd[:tl].select { |obj| kyl.include?(obj[:txid]) }
78
+ end
79
+
80
80
  # @param [String] moe codigo bitcoinde da moeda
81
81
  # @param [Hash] hsx saldo bitcoinde da moeda
82
82
  # @return [String] texto formatado saldos
@@ -134,31 +134,39 @@ module Cns
134
134
 
135
135
  # @return [String] texto transacoes trades
136
136
  def mtrades
137
- return unless ops[:v] && !novcdet.empty?
137
+ return unless ops[:v] && novcdet.any?
138
138
 
139
139
  puts("\ntrades data hora dt criacao tipo par qtd eur")
140
- novcdet.sort_by { |itm| -itm[:srx] }.each { |obj| puts(formata_trades(obj)) }
140
+ novcdet.sort_by { |i| -i[:srx] }.each { |o| puts(formata_trades(o)) }
141
141
  end
142
142
 
143
143
  # @return [String] texto transacoes ledger
144
144
  def mledger
145
- return unless ops[:v] && !novcdel.empty?
145
+ return unless ops[:v] && novcdel.any?
146
146
 
147
147
  puts("\nledger data hora tipo moe quantidade custo")
148
- novcdel.sort_by { |itm| -itm[:srx] }.each { |obj| puts(formata_ledger(obj)) }
148
+ novcdel.sort_by { |i| -i[:srx] }.each { |o| puts(formata_ledger(o)) }
149
149
  end
150
150
 
151
151
  # Processa os trades para garantir que as datas estejam no formato correto
152
152
  def pdea(itm)
153
- itm.select { |ky1, _| EM.include?(ky1) }.transform_values { |o| o.merge(total_amount: o[:total_amount].to_d) }
153
+ itm.select { |k, _| EM.include?(k) }.transform_values { |o| o.merge(total_amount: o[:total_amount].to_d) }
154
+ end
155
+
156
+ # Processa time field somtimes is string
157
+ def ptm(itm)
158
+ itm.is_a?(String) ? Time.parse(itm) : itm
159
+ end
160
+
161
+ def pdes(key, itm)
162
+ tym = ptm(itm[key])
163
+ itm.merge(srx: Integer(tym), key => tym)
154
164
  end
155
165
 
156
166
  # Processa os trades para garantir que as datas estejam no formato correto
157
167
  def pdet(itm)
158
168
  itm.map do |t|
159
- t.merge(
160
- successfully_finished_at: srx = ptm(t[:successfully_finished_at]),
161
- srx: Integer(srx),
169
+ pdes(:successfully_finished_at, t).merge(
162
170
  trade_marked_as_paid_at: ptm(t[:trade_marked_as_paid_at]),
163
171
  amount_currency_to_trade: t[:amount_currency_to_trade].to_d,
164
172
  volume_currency_to_pay: t[:volume_currency_to_pay].to_d,
@@ -169,12 +177,7 @@ module Cns
169
177
 
170
178
  # Processa os ledger entries para garantir que as datas estejam no formato correto
171
179
  def pdel(itm)
172
- itm.map { |t| t.merge(time: srx = ptm(t[:time]), srx: Integer(srx), qt: t[:qt].to_d, fee: t[:fee].to_d, moe: t[:moe].upcase) }
173
- end
174
-
175
- # Processa time field somtimes is string
176
- def ptm(itm)
177
- itm.is_a?(String) ? Time.parse(itm) : itm
180
+ itm.map { |t| pdes(:time, t).merge(qt: t[:qt].to_d, fee: t[:fee].to_d, moe: t[:moe].upcase) }
178
181
  end
179
182
  end
180
183
  end
data/lib/cns/etherscan.rb CHANGED
@@ -16,6 +16,44 @@ module Cns
16
16
  # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
17
17
  attr_reader :ops
18
18
 
19
+ TT = {
20
+ normal: {
21
+ new: :novnetht,
22
+ sort_key: :srx,
23
+ format: :formata_tx_ti,
24
+ header: "\ntx normal from to data valor",
25
+ adjustment_key: :hash
26
+ },
27
+ internal: {
28
+ new: :novnethi,
29
+ sort_key: :srx,
30
+ format: :formata_tx_ti,
31
+ header: "\ntx intern from to data valor",
32
+ adjustment_key: :hash
33
+ },
34
+ block: {
35
+ new: :novnethp,
36
+ sort_key: :itx,
37
+ format: :formata_tx_block,
38
+ header: "\ntx block address data valor",
39
+ adjustment_key: :blockNumber
40
+ },
41
+ token: {
42
+ new: :novnethk,
43
+ sort_key: :srx,
44
+ format: :formata_tx_token,
45
+ header: "\ntx token from to data valor moeda",
46
+ adjustment_key: :hash
47
+ },
48
+ withdrawal: {
49
+ new: :novnethw,
50
+ sort_key: :itx,
51
+ format: :formata_tx_withw,
52
+ header: "\nwithdrawal validator data valor",
53
+ adjustment_key: :withdrawalIndex
54
+ }
55
+ }
56
+
19
57
  # @param [Hash] dad todos os dados bigquery
20
58
  # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
21
59
  # @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
@@ -27,162 +65,28 @@ module Cns
27
65
  @ops = pop.transform_keys(&:to_sym)
28
66
  end
29
67
 
30
- # @return [Array<Hash>] lista transacoes normais novas
31
- def novnetht
32
- @novnetht ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
33
- end
34
-
35
- # @return [Array<Hash>] lista transacoes internas novas
36
- def novnethi
37
- @novnethi ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
38
- end
39
-
40
- # @return [Array<Hash>] lista transacoes block novas
41
- def novnethp
42
- @novnethp ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
43
- end
44
-
45
- # @return [Array<Hash>] lista transacoes withdrawals novas
46
- def novnethw
47
- @novnethw ||= bcd.map { |obc| obc[:wx].select { |obj| idw.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
48
- end
49
-
50
- # @return [Array<Hash>] lista transacoes token novas
51
- def novnethk
52
- @novnethk ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
53
- end
54
-
55
- # @return [Array<String>] lista dos meus enderecos
56
- def lax
57
- @lax ||= bqd[:wb].map { |obj| obj[:ax] }
58
- end
59
-
60
- # @return [Array<Hash>] todos os dados etherscan - saldos & transacoes
61
- def bcd
62
- @bcd ||= api.account_es(lax).map { |obj| base_bc(obj) }
63
- end
64
-
65
- # @return [Array<Hash>] todos os dados juntos bigquery & etherscan
66
- def dados
67
- @dados ||= bqd[:wb].map { |obq| bq_bc(obq, bcd.select { |obc| obq[:ax] == obc[:ax] }.first) }
68
- end
69
-
70
- # @return [Array<Integer>] lista indices transacoes normais novas
71
- def idt
72
- @idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
73
- end
74
-
75
- # @return [Array<Integer>] lista indices transacoes internas novas
76
- def idi
77
- @idi ||= bcd.map { |obc| obc[:ix].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:ni].map { |obq| obq[:itx] })
78
- end
79
-
80
- # @return [Array<Integer>] lista indices transacoes block novas
81
- def idp
82
- @idp ||= bcd.map { |obc| obc[:px].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:np].map { |obq| obq[:itx] })
83
- end
84
-
85
- # @return [Array<Integer>] lista indices transacoes withdrawals novas
86
- def idw
87
- @idw ||= bcd.map { |obc| obc[:wx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nw].map { |obq| obq[:itx] })
88
- end
89
-
90
- # @return [Array<Integer>] lista indices transacoes token novas
91
- def idk
92
- @idk ||= bcd.map { |obc| obc[:kx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nk].map { |obq| obq[:itx] })
93
- end
94
-
95
- # @example (see Apibc#account_es)
96
- # @param [Hash] abc account etherscan
97
- # @return [Hash] dados etherscan - address, saldo & transacoes
98
- def base_bc(abc)
99
- acc = abc[:account].downcase
100
- {
101
- ax: acc,
102
- sl: abc[:balance].to_d / (10**18),
103
- tx: ftik(acc, api.norml_es(acc)),
104
- ix: ftik(acc, api.inter_es(acc)),
105
- px: fppp(acc, api.block_es(acc)),
106
- wx: fwww(acc, api.withw_es(acc)),
107
- kx: ftik(acc, api.token_es(acc))
108
- }
109
- end
110
-
111
- # @param [Hash] wbq wallet bigquery
112
- # @param [Hash] hbc dados etherscan - address, saldo & transacoes
113
- # @return [Hash] dados juntos bigquery & etherscan
114
- def bq_bc(wbq, hbc)
115
- {
116
- id: wbq[:id],
117
- ax: xbq = wbq[:ax],
118
- bs: wbq[:sl],
119
- bt: bqd[:nt].select { |ont| ont[:iax].casecmp?(xbq) },
120
- bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
121
- bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
122
- bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
123
- bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
124
- es: hbc[:sl],
125
- et: hbc[:tx],
126
- ei: hbc[:ix],
127
- ep: hbc[:px],
128
- ew: hbc[:wx],
129
- ek: hbc[:kx]
130
- }
131
- end
132
-
133
- # @return [Array<Hash>] lista ordenada transacoes normais novas
134
- def sortx
135
- novnetht.sort_by { |itm| -itm[:srx] }
136
- end
137
-
138
- # @return [Array<Hash>] lista ordenada transacoes internas novas
139
- def sorix
140
- novnethi.sort_by { |itm| -itm[:srx] }
141
- end
142
-
143
- # @return [Array<Hash>] lista ordenada transacoes block novas
144
- def sorpx
145
- novnethp.sort_by { |itm| -itm[:itx] }
146
- end
147
-
148
- # @return [Array<Hash>] lista ordenada transacoes withdrawals novas
149
- def sorwx
150
- novnethw.sort_by { |itm| -itm[:itx] }
151
- end
152
-
153
- # @return [Array<Hash>] lista ordenada transacoes token novas
154
- def sorkx
155
- novnethk.sort_by { |itm| -itm[:srx] }
156
- end
157
-
158
68
  # @return [String] texto carteiras & transacoes & ajuste dias
159
69
  def mresumo_simples
160
- return unless dados.count.positive?
70
+ return unless dados.any?
161
71
 
162
72
  puts("\nid address etherscan bigquery")
163
73
  dados.each { |obj| puts(formata_carteira_simples(obj)) }
164
- mtx_norml
165
- mtx_inter
166
- mtx_block
167
- mtx_token
168
- mtx_withw
74
+ mtransacoes_novas
169
75
  mconfiguracao_ajuste_dias
170
76
  end
171
77
 
172
78
  # @return [String] texto carteiras & transacoes & ajuste dias
173
79
  def mresumo
174
- return unless dados.count.positive?
80
+ return unless dados.any?
175
81
 
176
82
  puts("\nid address etherscan tn ti tb tk tw bigquery tn ti tb tk tw")
177
83
  dados.each { |obj| puts(formata_carteira(obj)) }
178
- mtx_norml
179
- mtx_inter
180
- mtx_block
181
- mtx_token
182
- mtx_withw
84
+ mtransacoes_novas
183
85
  mconfiguracao_ajuste_dias
184
86
  end
185
87
 
88
+ private
89
+
186
90
  # @param [Hash] hjn dados juntos bigquery & etherscan
187
91
  # @return [String] texto formatado duma carteira
188
92
  def formata_carteira_simples(hjn)
@@ -224,7 +128,16 @@ module Cns
224
128
 
225
129
  # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
226
130
  def ok?(hjn)
227
- hjn[:es].round(6) == hjn[:bs].round(6) && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bw].count == hjn[:ew].count
131
+ oks?(hjn) && okipw?(hjn) && hjn[:bt].count == hjn[:et].count && hjn[:bk].count == hjn[:ek].count
132
+ end
133
+
134
+ def okipw?(hjn)
135
+ oks?(hjn) && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bw].count == hjn[:ew].count
136
+ end
137
+
138
+ # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
139
+ def oks?(hjn)
140
+ hjn[:es].round(6) == hjn[:bs].round(6)
228
141
  end
229
142
 
230
143
  # @example ether address inicio..fim
@@ -250,7 +163,7 @@ module Cns
250
163
  max -= 2
251
164
  ini = Integer(max / 2)
252
165
  inf = max % 2
253
- hid = bqd[:wb].select { |obj| obj[:ax] == add }.first
166
+ hid = bqd[:wb].find { |obj| obj[:ax] == add }
254
167
  ndd = hid ? "#{hid[:id]}-#{add}" : add
255
168
  "#{ndd[0, ini]}..#{ndd[-inf - ini..]}"
256
169
  end
@@ -274,8 +187,8 @@ module Cns
274
187
  # @return [String] texto formatado transacao token etherscan
275
188
  def formata_tx_token(hkx)
276
189
  format(
277
- '%<hx>-23.23s %<fr>-15.15s %<to>-15.15s %<dt>10.10s %<vl>7.3f %<sy>-5.5s',
278
- hx: formata_enderec1(hkx[:hash], 23),
190
+ '%<hx>-20.20s %<fr>-15.15s %<to>-15.15s %<dt>10.10s %<vl>10.3f %<sy>-5.5s',
191
+ hx: formata_enderec1(hkx[:hash], 20),
279
192
  fr: formata_enderec2(hkx[:from], 15),
280
193
  to: formata_enderec2(hkx[:to], 15),
281
194
  dt: hkx[:timeStamp].strftime('%F'),
@@ -304,62 +217,190 @@ module Cns
304
217
  format('%<bn>10i %<vi>9i %<dt>10.10s %<vl>10.6f', bn: htx[:withdrawalIndex], vi: htx[:validatorIndex], dt: htx[:timeStamp].strftime('%F'), vl: htx[:amount] / (10**9))
305
218
  end
306
219
 
307
- # @return [String] texto transacoes normais
308
- def mtx_norml
309
- return unless ops[:v] && novnetht.count.positive?
220
+ # @return [String] Display all new transactions based on verbose option
221
+ def mtransacoes_novas
222
+ TT.each do |_, cfg|
223
+ ntx = send(cfg[:new])
224
+ next unless ops[:v] && ntx.any?
225
+
226
+ puts(cfg[:header])
227
+ ntx.sort_by { |s| -s[cfg[:sort_key]] }.each { |t| puts(send(cfg[:format], t)) }
228
+ end
229
+ end
230
+
231
+ # @return [String] Configuration text for adjusting transaction days
232
+ def mconfiguracao_ajuste_dias
233
+ TT.each do |typ, cfg|
234
+ ntx = send(cfg[:new])
235
+ next unless ntx.any?
236
+
237
+ puts("\najuste dias transacoes #{typ}\n-h=#{ntx.map { |t| "#{t[cfg[:adjustment_key]]}:0" }.join(' ')}")
238
+ end
239
+ end
240
+
241
+ # @return [Array<String>] lista dos meus enderecos
242
+ def lax
243
+ @lax ||= bqd[:wb].map { |obj| obj[:ax] }
244
+ end
245
+
246
+ # @return [Array<Hash>] todos os dados etherscan - saldos & transacoes
247
+ def bcd
248
+ @bcd ||= api.account_es(lax).map { |obj| base_bc(obj) }
249
+ end
310
250
 
311
- puts("\ntx normal from to data valor")
312
- sortx.each { |obj| puts(formata_tx_ti(obj)) }
251
+ # @return [Array<Hash>] todos os dados juntos bigquery & etherscan
252
+ def dados
253
+ @dados ||= bqd[:wb].map { |b| bq_bc(b, bcd.find { |e| b[:ax] == e[:ax] }) }
313
254
  end
314
255
 
315
- # @return [String] texto transacoes internas
316
- def mtx_inter
317
- return unless ops[:v] && novnethi.count.positive?
256
+ def show_all?
257
+ ops[:t] || false
258
+ end
318
259
 
319
- puts("\ntx intern from to data valor")
320
- sorix.each { |obj| puts(formata_tx_ti(obj)) }
260
+ def bqidt
261
+ @bqidt ||= show_all? ? [] : (bqd[:nt]&.map { |i| i[:itx] } || [])
321
262
  end
322
263
 
323
- # @return [String] texto transacoes block
324
- def mtx_block
325
- return unless ops[:v] && novnethp.count.positive?
264
+ # @return [Array<Integer>] lista indices transacoes novas
265
+ def idt
266
+ @idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
267
+ end
326
268
 
327
- puts("\ntx block address data valor")
328
- sorpx.each { |obj| puts(formata_tx_block(obj)) }
269
+ def bqidi
270
+ @bqidi ||= show_all? ? [] : (bqd[:ni]&.map { |i| i[:itx] } || [])
329
271
  end
330
272
 
331
- # @return [String] texto transacoes token
332
- def mtx_token
333
- return unless ops[:v] && novnethk.count.positive?
273
+ # @return [Array<Integer>] lista indices transacoes novas
274
+ def idi
275
+ @idi ||= bcd.map { |o| o[:ix].map { |i| i[:itx] } }.flatten - bqidi
276
+ end
334
277
 
335
- puts("\ntx token from to data valor moeda")
336
- sorkx.each { |obj| puts(formata_tx_token(obj)) }
278
+ def bqidp
279
+ @bqidp ||= show_all? ? [] : (bqd[:np]&.map { |i| i[:itx] } || [])
337
280
  end
338
281
 
339
- # @return [String] texto transacoes withdrawals
340
- def mtx_withw
341
- return unless ops[:v] && novnethw.count.positive?
282
+ # @return [Array<Integer>] lista indices transacoes novas
283
+ def idp
284
+ @idp ||= bcd.map { |o| o[:px].map { |i| i[:itx] } }.flatten - bqidp
285
+ end
342
286
 
343
- puts("\nwithdrawal validator data valor")
344
- sorwx.each { |obj| puts(formata_tx_withw(obj)) }
287
+ def bqidw
288
+ @bqidw ||= show_all? ? [] : (bqd[:nw]&.map { |i| i[:itx] } || [])
345
289
  end
346
290
 
347
- # @return [String] texto configuracao ajuste dias das transacoes (normais & token)
348
- def mconfiguracao_ajuste_dias
349
- puts("\najuste dias transacoes normais \n-h=#{sortx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnetht.count.positive?
350
- puts("\najuste dias transacoes internas \n-h=#{sorix.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethi.count.positive?
351
- puts("\najuste dias transacoes block \n-h=#{sorpx.map { |obj| "#{obj[:blockNumber]}:0" }.join(' ')}") if novnethp.count.positive?
352
- puts("\najuste dias transacoes token \n-h=#{sorkx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethk.count.positive?
353
- puts("\najuste dias transacoes withdrawals\n-h=#{sorwx.map { |obj| "#{obj[:withdrawalIndex]}:0" }.join(' ')}") if novnethw.count.positive?
291
+ # @return [Array<Integer>] lista indices transacoes novas
292
+ def idw
293
+ @idw ||= bcd.map { |o| o[:wx].map { |i| i[:itx] } }.flatten - bqidw
354
294
  end
355
295
 
356
- private
296
+ def bqidk
297
+ @bqidk ||= show_all? ? [] : (bqd[:nk]&.map { |i| i[:itx] } || [])
298
+ end
299
+
300
+ # @return [Array<Integer>] lista indices transacoes novas
301
+ def idk
302
+ @idk ||= bcd.map { |o| o[:kx].map { |i| i[:itx] } }.flatten - bqidk
303
+ end
304
+
305
+ # @example (see Apibc#account_es)
306
+ # @param [Hash] abc account etherscan
307
+ # @return [Hash] dados etherscan - address, saldo & transacoes
308
+ def base_bc(abc)
309
+ acc = abc[:account].downcase
310
+ {
311
+ ax: acc,
312
+ sl: abc[:balance].to_d / (10**18),
313
+ tx: ftik(acc, api.norml_es(acc)),
314
+ ix: ftik(acc, api.inter_es(acc)),
315
+ px: fppp(acc, api.block_es(acc)),
316
+ wx: fwww(acc, api.withw_es(acc)),
317
+ kx: ftik(acc, api.token_es(acc))
318
+ }
319
+ end
320
+
321
+ # @param [Hash] wbq wallet bigquery
322
+ # @param [Hash] hbc dados etherscan - address, saldo & transacoes
323
+ # @return [Hash] dados juntos bigquery & etherscan
324
+ def bq_bc(wbq, hbc)
325
+ xbq = wbq[:ax]
326
+ {
327
+ id: wbq[:id],
328
+ ax: xbq,
329
+ bs: wbq[:sl],
330
+ bt: bqd[:nt].select { |ont| ont[:iax].casecmp?(xbq) },
331
+ bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
332
+ bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
333
+ bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
334
+ bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
335
+ es: hbc[:sl],
336
+ et: hbc[:tx],
337
+ ei: hbc[:ix],
338
+ ep: hbc[:px],
339
+ ew: hbc[:wx],
340
+ ek: hbc[:kx]
341
+ }
342
+ end
343
+
344
+ # @return [Array<Hash>] lista transacoes normais novas
345
+ def novnetht
346
+ @novnetht ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
347
+ end
348
+
349
+ # @return [Array<Hash>] lista transacoes internas novas
350
+ def novnethi
351
+ @novnethi ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
352
+ end
353
+
354
+ # @return [Array<Hash>] lista transacoes block novas
355
+ def novnethp
356
+ @novnethp ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
357
+ end
358
+
359
+ # @return [Array<Hash>] lista transacoes withdrawals novas
360
+ def novnethw
361
+ @novnethw ||= bcd.map { |obc| obc[:wx].select { |obj| idw.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
362
+ end
363
+
364
+ # @return [Array<Hash>] lista transacoes token novas
365
+ def novnethk
366
+ @novnethk ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
367
+ end
368
+
369
+ # @return [Array<Hash>] lista ordenada transacoes normais novas
370
+ def sortx
371
+ novnetht.sort_by { |i| -i[:srx] }
372
+ end
373
+
374
+ # @return [Array<Hash>] lista ordenada transacoes internas novas
375
+ def sorix
376
+ novnethi.sort_by { |i| -i[:srx] }
377
+ end
378
+
379
+ # @return [Array<Hash>] lista ordenada transacoes block novas
380
+ def sorpx
381
+ novnethp.sort_by { |i| -i[:itx] }
382
+ end
383
+
384
+ # @return [Array<Hash>] lista ordenada transacoes withdrawals novas
385
+ def sorwx
386
+ novnethw.sort_by { |i| -i[:itx] }
387
+ end
388
+
389
+ # @return [Array<Hash>] lista ordenada transacoes token novas
390
+ def sorkx
391
+ novnethk.sort_by { |i| -i[:srx] }
392
+ end
393
+
394
+ def pess(itm)
395
+ tym = Integer(itm[:timeStamp])
396
+ itm.merge(srx: tym, timeStamp: Time.at(tym))
397
+ end
357
398
 
358
399
  # @param add (see Apibc#norml_es)
359
400
  # @param [Array<Hash>] ary lista transacoes/token events
360
401
  # @return [Array<Hash>] lista transacoes/token events filtrada
361
402
  def ftik(add, ary)
362
- ary.map { |o| o.merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d, srx: (tym = Integer(o[:timeStamp])), timeStamp: Time.at(tym)) }
403
+ ary.map { |o| pess(o).merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d) }
363
404
  end
364
405
 
365
406
  # @param add (see Apibc#norml_es)
data/lib/cns/greymass.rb CHANGED
@@ -25,57 +25,17 @@ module Cns
25
25
  @ops = pop.transform_keys(&:to_sym)
26
26
  end
27
27
 
28
- # @return [Array<Hash>] lista transacoes novas
29
- def novneost
30
- @novneost ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten
31
- end
32
-
33
- # @return [Array<String>] lista dos meus enderecos
34
- def lax
35
- @lax ||= bqd[:wb].map { |obj| obj[:ax] }
36
- end
37
-
38
- # @return [Array<Hash>] todos os dados greymass - saldos & transacoes
39
- def bcd
40
- @bcd ||= bqd[:wb].map { |obj| base_bc(obj) }
41
- end
42
-
43
- # @return [Array<Hash>] todos os dados juntos bigquery & greymass
44
- def dados
45
- @dados ||= bqd[:wb].map { |obq| bq_bc(obq, bcd.select { |obj| obq[:ax] == obj[:ax] }.first) }
46
- end
47
-
48
- # @return [Array<Integer>] lista indices transacoes novas
49
- def idt
50
- @idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
51
- end
52
-
53
- # @example (see Apibc#account_gm)
54
- # @param [Hash] wbq wallet bigquery
55
- # @return [Hash] dados greymass - address, saldo & transacoes
56
- def base_bc(wbq)
57
- xbq = wbq[:ax]
58
- { ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq)) }
59
- end
60
-
61
- # @param wbq (see base_bc)
62
- # @param [Hash] hbc dados greymass - address, saldo & transacoes
63
- # @return [Hash] dados juntos bigquery & greymass
64
- def bq_bc(wbq, hbc)
65
- xbq = wbq[:ax]
66
- {
67
- id: wbq[:id],
68
- ax: xbq,
69
- bs: wbq[:sl],
70
- bt: bqd[:nt].select { |obj| obj[:iax] == xbq },
71
- es: hbc[:sl],
72
- et: hbc[:tx]
73
- }
74
- end
28
+ TT = {
29
+ new: :novneost,
30
+ sort_key: :itx,
31
+ format: :formata_ledger,
32
+ header: "\nsequence num from to accao data valor moeda",
33
+ adjustment_key: :itx
34
+ }
75
35
 
76
36
  # @return [String] texto carteiras & transacoes & ajuste dias
77
37
  def mresumo
78
- return unless dados.count.positive?
38
+ return unless dados.any?
79
39
 
80
40
  puts("\naddress greymass ntx bigquery ntx")
81
41
  dados.each { |obj| puts(formata_carteira(obj)) }
@@ -83,6 +43,8 @@ module Cns
83
43
  mconfiguracao_ajuste_dias
84
44
  end
85
45
 
46
+ private
47
+
86
48
  # @param [Hash] hjn dados juntos bigquery & greymass
87
49
  # @return [String] texto formatado duma carteira
88
50
  def formata_carteira(hjn)
@@ -119,26 +81,77 @@ module Cns
119
81
  )
120
82
  end
121
83
 
122
- # @return [String] texto transacoes
84
+ # @return [String] Display new transactions based on verbose option
123
85
  def mtransacoes_novas
124
- return unless ops[:v] && novneost.count.positive?
86
+ ntx = send(TT[:new])
87
+ return unless ops[:v] && ntx.any?
125
88
 
126
- puts("\nsequence num from to accao data valor moeda")
127
- soreost.each { |obj| puts(formata_ledger(obj)) }
89
+ puts(TT[:header])
90
+ ntx.sort_by { |s| -s[TT[:sort_key]] }.each { |t| puts(send(TT[:format], t)) }
128
91
  end
129
92
 
130
93
  # @return [String] texto configuracao ajuste dias das transacoes
131
94
  def mconfiguracao_ajuste_dias
132
- return unless novneost.count.positive?
95
+ ntx = send(TT[:new])
96
+ return unless ntx.any?
133
97
 
134
- puts("\nstring ajuste dias\n-h=#{soreost.map { |obj| "#{obj[:itx]}:0" }.join(' ')}")
98
+ puts("\nstring ajuste dias\n-h=#{ntx.map { |t| "#{t[TT[:adjustment_key]]}:0" }.join(' ')}")
135
99
  end
136
100
 
137
- private
101
+ # @return [Array<Hash>] todos os dados greymass - saldos & transacoes
102
+ def bcd
103
+ @bcd ||= bqd[:wb].map { |obj| base_bc(obj) }
104
+ end
105
+
106
+ # @return [Array<Hash>] todos os dados juntos bigquery & greymass
107
+ def dados
108
+ @dados ||= bqd[:wb].map { |b| bq_bc(b, bcd.find { |g| b[:ax] == g[:ax] }) }
109
+ end
110
+
111
+ def show_all?
112
+ ops[:t] || false
113
+ end
114
+
115
+ def bqidt
116
+ @bqidt ||= show_all? ? [] : (bqd[:nt]&.map { |i| i[:itx] } || [])
117
+ end
118
+
119
+ # @return [Array<Integer>] lista indices transacoes novas
120
+ def idt
121
+ @idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
122
+ end
123
+
124
+ # @example (see Apibc#account_gm)
125
+ # @param [Hash] wbq wallet bigquery
126
+ # @return [Hash] dados greymass - address, saldo & transacoes
127
+ def base_bc(wbq)
128
+ xbq = wbq[:ax]
129
+ { ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq)) }
130
+ end
131
+
132
+ # @param wbq (see base_bc)
133
+ # @param [Hash] hbc dados greymass - address, saldo & transacoes
134
+ # @return [Hash] dados juntos bigquery & greymass
135
+ def bq_bc(wbq, hbc)
136
+ xbq = wbq[:ax]
137
+ {
138
+ id: wbq[:id],
139
+ ax: xbq,
140
+ bs: wbq[:sl],
141
+ bt: bqd[:nt].select { |obj| obj[:iax] == xbq },
142
+ es: hbc[:sl],
143
+ et: hbc[:tx]
144
+ }
145
+ end
146
+
147
+ # @return [Array<Hash>] lista transacoes novas
148
+ def novneost
149
+ @novneost ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten
150
+ end
138
151
 
139
152
  # @return [Array<Hash>] lista ordenada transacoes
140
153
  def soreost
141
- novneost.sort_by { |itm| -itm[:itx] }
154
+ novneost.sort_by { |i| -i[:itx] }
142
155
  end
143
156
 
144
157
  # @return [Array<BigDecimal>] lista recursos - liquido, net, spu
@@ -153,10 +166,13 @@ module Cns
153
166
  # @return [Array<Hash>] lista transacoes filtrada
154
167
  def peost(add, ary)
155
168
  ary.map do |omp|
169
+ act = omp[:action_trace][:act]
170
+ adt = act[:data]
171
+ qtd = adt[:quantity].to_s
156
172
  omp.merge(
157
- name: (act = omp[:action_trace][:act])[:name],
158
- from: (adt = act[:data])[:from],
159
- quantity: (qtd = adt[:quantity].to_s).to_d,
173
+ name: act[:name],
174
+ from: adt[:from],
175
+ quantity: qtd.to_d,
160
176
  account: act[:account],
161
177
  to: adt[:to],
162
178
  memo: String(adt[:memo]).gsub(/\p{C}/, ''), # remove Non-Printable Characters
data/lib/cns/kraken.rb CHANGED
@@ -30,16 +30,6 @@ module Cns
30
30
  @exd ||= { sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us) }
31
31
  end
32
32
 
33
- # @return [Hash] trades kraken novos
34
- def novcust
35
- @novcust ||= exd[:kt].slice(*kyt)
36
- end
37
-
38
- # @return [Hash] ledger kraken novos
39
- def novcusl
40
- @novcusl ||= exd[:kl].slice(*kyl)
41
- end
42
-
43
33
  # @return [String] texto saldos & transacoes & ajuste dias
44
34
  def mresumo
45
35
  puts("\nKRAKEN\ntipo kraken bigquery")
@@ -60,11 +50,11 @@ module Cns
60
50
  end
61
51
 
62
52
  def bqkyt
63
- show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid].to_sym } || [])
53
+ @bqkyt ||= show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid].to_sym } || [])
64
54
  end
65
55
 
66
56
  def bqkyl
67
- show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid].to_sym } || [])
57
+ @bqkyl ||= show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid].to_sym } || [])
68
58
  end
69
59
 
70
60
  # @return [Array<String>] lista txid dos trades novos
@@ -77,6 +67,16 @@ module Cns
77
67
  @kyl ||= exd[:kl].keys - bqkyl
78
68
  end
79
69
 
70
+ # @return [Hash] trades kraken novos
71
+ def novcust
72
+ @novcust ||= exd[:kt].slice(*kyt)
73
+ end
74
+
75
+ # @return [Hash] ledger kraken novos
76
+ def novcusl
77
+ @novcusl ||= exd[:kl].slice(*kyl)
78
+ end
79
+
80
80
  # @example (see Apice#account_us)
81
81
  # @param [String] moe codigo kraken da moeda
82
82
  # @param [BigDecimal] sal saldo kraken da moeda
@@ -136,33 +136,38 @@ module Cns
136
136
 
137
137
  # @return [String] texto transacoes trades
138
138
  def mtrades
139
- return unless ops[:v] && novcust.count.positive?
139
+ return unless ops[:v] && novcust.any?
140
140
 
141
141
  puts("\ntrade data hora tipo par preco volume custo")
142
- novcust.sort_by { |itm| -itm[1][:srx] }.each { |key, val| puts(formata_trades(key, val)) }
142
+ novcust.sort_by { |_, v| -v[:srx] }.each { |i, t| puts(formata_trades(i, t)) }
143
143
  end
144
144
 
145
145
  # @return [String] texto transacoes ledger
146
146
  def mledger
147
- return unless ops[:v] && novcusl.count.positive?
147
+ return unless ops[:v] && novcusl.any?
148
148
 
149
149
  puts("\nledger data hora tipo moeda quantidade custo")
150
- novcusl.sort_by { |itm| -itm[1][:srx] }.each { |key, val| puts(formata_ledger(key, val)) }
150
+ novcusl.sort_by { |_, v| -v[:srx] }.each { |i, t| puts(formata_ledger(i, t)) }
151
151
  end
152
152
 
153
153
  # Processa os trades para garantir que as datas estejam no formato correto
154
154
  def pusa(itm)
155
- itm.select { |key, _| EM.include?(key) }.transform_values { |val| val.to_d }
155
+ itm.select { |k, _| EM.include?(k) }.transform_values { |v| v.to_d }
156
+ end
157
+
158
+ def puss(itm)
159
+ tym = Integer(itm[:time])
160
+ itm.merge(srx: tym, time: Time.at(tym))
156
161
  end
157
162
 
158
163
  # Processa os trades para garantir que as datas estejam no formato correto
159
164
  def pust(itm)
160
- itm.transform_values { |t| t.merge(srx: (tym = Integer(t[:time])), time: Time.at(tym), pair: t[:pair].upcase, price: t[:price].to_d, vol: t[:vol].to_d, cost: t[:cost].to_d) }
165
+ itm.transform_values { |t| puss(t).merge(pair: t[:pair].upcase, price: t[:price].to_d, vol: t[:vol].to_d, cost: t[:cost].to_d) }
161
166
  end
162
167
 
163
168
  # Processa os ledger entries para garantir que as datas estejam no formato correto
164
169
  def pusl(itm)
165
- itm.transform_values { |t| t.merge(srx: (tym = Integer(t[:time])), time: Time.at(tym), asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
170
+ itm.transform_values { |t| puss(t).merge(asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
166
171
  end
167
172
  end
168
173
  end
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.8.9'
4
+ VERSION = '0.9.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.9
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-25 00:00:00.000000000 Z
10
+ date: 2025-03-01 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler