cns 0.8.2 → 0.8.4

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.
data/lib/cns/bigquery.rb CHANGED
@@ -7,17 +7,27 @@ require('bigdecimal/util')
7
7
  module Cns
8
8
  BD = 'hernanirvaz.coins'
9
9
  FO = File.expand_path("~/#{File.basename($PROGRAM_NAME)}.log")
10
+ # Define table configurations at the class level
11
+ TC = {
12
+ i: %w[blocknumber timestamp txhash axfrom axto iax value contractaddress input type gas gasused traceid iserror errcode],
13
+ p: %w[blocknumber timestamp blockreward iax],
14
+ w: %w[withdrawalindex validatorindex address amount blocknumber timestamp],
15
+ t: %w[blocknumber timestamp txhash nonce blockhash transactionindex axfrom axto iax value gas gasprice gasused iserror txreceipt_status input contractaddress dias],
16
+ k: %w[blocknumber timestamp txhash nonce blockhash transactionindex axfrom axto iax value tokenname tokensymbol tokendecimal gas gasprice gasused input contractaddress dias],
17
+ neost: %w[gseq aseq bnum time contract action acfrom acto iax amount moeda memo dias],
18
+ cdet: %w[txid time tp user btc eur dtc dias],
19
+ cdel: %w[txid time tp add moe qt fee],
20
+ cust: %w[txid ordertxid pair time type ordertype price cost fee vol margin misc ledgers dias],
21
+ cusl: %w[txid refid time type aclass asset amount fee]
22
+ }
10
23
 
11
24
  # classe para processar bigquery
12
25
  class Bigquery
13
26
  # @return [Google::Cloud::Bigquery] API bigquery
14
- attr_reader :api
15
27
  # @return [Google::Cloud::Bigquery::QueryJob] job bigquery
16
- attr_reader :job
17
28
  # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
18
- attr_reader :ops
19
29
  # @return (see sql)
20
- attr_reader :sqr
30
+ attr_reader :api, :job, :ops, :sqr
21
31
 
22
32
  # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
23
33
  # @option pop [Hash] :h ({}) configuracao ajuste reposicionamento temporal
@@ -85,26 +95,14 @@ module Cns
85
95
  #
86
96
  # @return [String] linhas & tabelas afetadas
87
97
  def processa_eth
88
- str = 'ETH'
89
- str += format(' %<n>i netht', n: dml(netht_ins)) if apies.novtx.count.positive?
90
- str += format(' %<n>i nethi', n: dml(nethi_ins)) if apies.novix.count.positive?
91
- str += format(' %<n>i nethp', n: dml(nethp_ins)) if apies.novpx.count.positive?
92
- str += format(' %<n>i nethw', n: dml(nethw_ins)) if apies.novwx.count.positive?
93
- str += format(' %<n>i nethk', n: dml(nethk_ins)) if apies.novkx.count.positive?
94
- str
98
+ tabelas_eth(apies, 'netb')
95
99
  end
96
100
 
97
101
  # insere transacoes blockchain novas nas tabelas netht (norml), nethi (internas), nethp (block), nethw (withdrawals), nethk (token)
98
102
  #
99
103
  # @return [String] linhas & tabelas afetadas
100
104
  def processa_ethc
101
- str = 'ETH'
102
- str += format(' %<n>i netht', n: dml(netbt_ins)) if apiesc.novtx.count.positive?
103
- str += format(' %<n>i nethi', n: dml(netbi_ins)) if apiesc.novix.count.positive?
104
- str += format(' %<n>i nethp', n: dml(netbp_ins)) if apiesc.novpx.count.positive?
105
- str += format(' %<n>i nethw', n: dml(netbw_ins)) if apiesc.novwx.count.positive?
106
- str += format(' %<n>i nethk', n: dml(netbk_ins)) if apiesc.novkx.count.positive?
107
- str
105
+ tabelas_eth(apiesc, 'netc')
108
106
  end
109
107
 
110
108
  # insere transacoes exchange kraken novas nas tabelas ust (trades), usl (ledger)
@@ -143,9 +141,11 @@ module Cns
143
141
  def job?(cmd)
144
142
  @job = api.query_job(cmd)
145
143
  job.wait_until_done!
146
- fld = job.failed?
147
- puts(job.error['message']) if fld
148
- fld
144
+
145
+ return false unless job.failed?
146
+
147
+ puts("BigQuery Error: #{job.error['message']}")
148
+ true
149
149
  end
150
150
 
151
151
  # cria Structured Query Language (SQL) job bigquery
@@ -165,34 +165,28 @@ module Cns
165
165
  job?(cmd) ? 0 : job.num_dml_affected_rows
166
166
  end
167
167
 
168
- # @return [Etherscan] API blockchain ETH
169
- def apies
170
- @apies ||= Etherscan.new(
168
+ def initialize_etherscan_client(prx)
169
+ Etherscan.new(
171
170
  {
172
- wb: sql("select * from #{BD}.wetb order by ax"),
173
- ni: sql("select * from #{BD}.netbi"),
174
- nk: sql("select * from #{BD}.netbk"),
175
- np: sql("select * from #{BD}.netbp"),
176
- nt: sql("select * from #{BD}.netbt"),
177
- nw: sql("select * from #{BD}.netbw")
171
+ wb: sql("SELECT * FROM #{BD}.wet#{prx[-1]} ORDER BY ax"),
172
+ ni: sql("SELECT * FROM #{BD}.#{prx}i"),
173
+ nk: sql("SELECT * FROM #{BD}.#{prx}k"),
174
+ np: sql("SELECT * FROM #{BD}.#{prx}p"),
175
+ nt: sql("SELECT * FROM #{BD}.#{prx}t"),
176
+ nw: sql("SELECT * FROM #{BD}.#{prx}w")
178
177
  },
179
178
  ops
180
179
  )
181
180
  end
182
181
 
182
+ # @return [Etherscan] API blockchain ETH
183
+ def apies
184
+ @apies ||= initialize_etherscan_client('netb')
185
+ end
186
+
183
187
  # @return [Etherscan] API blockchain ETH
184
188
  def apiesc
185
- @apiesc ||= Etherscan.new(
186
- {
187
- wb: sql("select * from #{BD}.wetc order by ax"),
188
- ni: sql("select * from #{BD}.netci"),
189
- nk: sql("select * from #{BD}.netck"),
190
- np: sql("select * from #{BD}.netcp"),
191
- nt: sql("select * from #{BD}.netct"),
192
- nw: sql("select * from #{BD}.netcw")
193
- },
194
- ops
195
- )
189
+ @apiesc ||= initialize_etherscan_client('netc')
196
190
  end
197
191
 
198
192
  # @return [Greymass] API blockchain EOS
@@ -224,140 +218,92 @@ module Cns
224
218
  )
225
219
  end
226
220
 
227
- # @return [String] comando insert SQL formatado netht (norml)
228
- def bnetht_ins
229
- "insert #{BD}.netht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
230
- 'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias) VALUES'
231
- end
232
-
233
- # @return [String] comando insert SQL formatado nethi (internas)
234
- def bnethi_ins
235
- "insert #{BD}.nethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
236
- 'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode) VALUES'
237
- end
238
-
239
- # @return [String] comando insert SQL formatado nethp (block)
240
- def bnethp_ins
241
- "insert #{BD}.nethp(blocknumber,timestamp,blockreward,iax) VALUES"
242
- end
243
-
244
- # @return [String] comando insert SQL formatado nethw (withdrawals)
245
- def bnethw_ins
246
- "insert #{BD}.nethw(withdrawalindex,validatorindex,address,amount,blocknumber,timestamp) VALUES"
247
- end
248
-
249
- # @return [String] comando insert SQL formatado nethk (token)
250
- def bnethk_ins
251
- "insert #{BD}.nethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
252
- 'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias) VALUES'
253
- end
254
-
255
- # @return [String] comando insert SQL formatado netht (norml)
256
- def netht_ins
257
- "#{bnetht_ins}#{apies.novtx.map { |obj| netht_val(obj) }.join(',')}"
258
- end
259
-
260
- # @return [String] comando insert SQL formatado nethi (internas)
261
- def nethi_ins
262
- "#{bnethi_ins}#{apies.novix.map { |obj| nethi_val(obj) }.join(',')}"
263
- end
221
+ # Generic ETH data processor
222
+ def tabelas_eth(src, prx)
223
+ str = ['ETH']
224
+ %i[t i p w k].each do |typ|
225
+ novx = src.send("nov#{typ}x")
226
+ next if novx.empty?
264
227
 
265
- # @return [String] comando insert SQL formatado nethp (block)
266
- def nethp_ins
267
- "#{bnethp_ins}#{apies.novpx.map { |obj| nethp_val(obj) }.join(',')}"
228
+ str << format(' %<n>i %<t>s', n: dml(insert_eht(typ, novx)), t: "#{prx.chop}h#{typ}")
229
+ end
230
+ str.join
268
231
  end
269
232
 
270
- # @return [String] comando insert SQL formatado nethw (withdrawals)
271
- def nethw_ins
272
- "#{bnethw_ins}#{apies.novwx.map { |obj| nethw_val(obj) }.join(',')}"
273
- end
274
-
275
- # @return [String] comando insert SQL formatado nethk (token)
276
- def nethk_ins
277
- "#{bnethk_ins}#{apies.novkx.map { |obj| nethk_val(obj) }.join(',')}"
278
- end
279
-
280
- # @return [String] comando insert SQL formatado netht (norml)
281
- def netbt_ins
282
- "#{bnetht_ins}#{apiesc.novtx.map { |obj| netht_val(obj) }.join(',')}"
283
- end
284
-
285
- # @return [String] comando insert SQL formatado nethi (internas)
286
- def netbi_ins
287
- "#{bnethi_ins}#{apiesc.novix.map { |obj| nethi_val(obj) }.join(',')}"
288
- end
289
-
290
- # @return [String] comando insert SQL formatado nethp (block)
291
- def netbp_ins
292
- "#{bnethp_ins}#{apiesc.novpx.map { |obj| nethp_val(obj) }.join(',')}"
293
- end
294
-
295
- # @return [String] comando insert SQL formatado nethw (withdrawals)
296
- def netbw_ins
297
- "#{bnethw_ins}#{apiesc.novwx.map { |obj| nethw_val(obj) }.join(',')}"
298
- end
299
-
300
- # @return [String] comando insert SQL formatado nethk (token)
301
- def netbk_ins
302
- "#{bnethk_ins}#{apiesc.novkx.map { |obj| nethk_val(obj) }.join(',')}"
233
+ def insert_eht(typ, lin)
234
+ "INSERT #{BD}.neth#{typ} (#{TC[typ].join(',')}) VALUES #{lin.map { |itm| send("neth#{typ}_val", itm) }.join(',')}"
303
235
  end
304
236
 
305
237
  # @return [String] comando insert SQL formatado eos
306
238
  def eost_ins
307
- "insert #{BD}.neost(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
308
- ") VALUES#{apigm.novax.map { |obj| eost_val(obj) }.join(',')}"
239
+ "insert #{BD}.neost(#{TC[:neost].join(',')}) VALUES#{apigm.novax.map { |obj| eost_val(obj) }.join(',')}"
309
240
  end
310
241
 
311
242
  # @return [String] comando insert SQL formatado det (trades)
312
243
  def det_ins
313
- "insert #{BD}.cdet(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_val(obj) }.join(',')}"
244
+ "insert #{BD}.cdet(#{TC[:cdet].join(',')}) VALUES#{apide.trades.map { |obj| det_val(obj) }.join(',')}"
314
245
  end
315
246
 
316
247
  # @return [String] comando insert SQL formatado del (ledger)
317
248
  def del_ins
318
- "insert #{BD}.cdel(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
249
+ "insert #{BD}.cdel(#{TC[:cdel].join(',')}) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
319
250
  end
320
251
 
321
252
  # @return [String] comando insert SQL formatado ust (trades)
322
253
  def ust_ins
323
- "insert #{BD}.cust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
324
- "VALUES#{apius.trades.map { |key, val| ust_val(key, val) }.join(',')}"
254
+ "insert #{BD}.cust(#{TC[:cust].join(',')}) VALUES#{apius.trades.map { |key, val| ust_val(key, val) }.join(',')}"
325
255
  end
326
256
 
327
257
  # @return [String] comando insert SQL formatado usl (ledger)
328
258
  def usl_ins
329
- "insert #{BD}.cusl(txid,refid,time,type,aclass,asset,amount,fee) " \
330
- "VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
259
+ "insert #{BD}.cusl(#{TC[:cusl].join(',')}) VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
260
+ end
261
+
262
+ # SQL value formatting methods with improved safety
263
+ def quote(value)
264
+ return 'null' if value.nil? || value.empty?
265
+
266
+ "'#{value.gsub('\'', "''")}'" # Escape single quotes
267
+ end
268
+
269
+ def numeric(value)
270
+ "CAST('#{value}' AS NUMERIC)"
271
+ end
272
+
273
+ def integer(value)
274
+ Integer(value).to_s
275
+ rescue StandardError
276
+ 'null'
331
277
  end
332
278
 
333
- # @example (see Apibc#norml_es)
334
279
  # @param [Hash] htx transacao norml etherscan
335
280
  # @return [String] valores formatados netht (norml parte1)
336
281
  def netht_val(htx)
337
282
  txr = htx[:txreceipt_status]
338
- cta = htx[:contractAddress]
339
283
  inp = htx[:input]
340
- "(#{Integer(htx[:blockNumber])}," \
341
- "#{Integer(htx[:timeStamp])}," \
342
- "'#{htx[:hash]}'," \
343
- "#{Integer(htx[:nonce])}," \
344
- "'#{htx[:blockHash]}'," \
345
- "#{Integer(htx[:transactionIndex])}," \
346
- "'#{htx[:from]}'," \
347
- "'#{htx[:to]}'," \
348
- "'#{htx[:iax]}'," \
349
- "cast('#{htx[:value]}' as numeric)," \
350
- "cast('#{htx[:gas]}' as numeric)," \
351
- "cast('#{htx[:gasPrice]}' as numeric)," \
352
- "cast('#{htx[:gasUsed]}' as numeric)," \
353
- "#{Integer(htx[:isError])}," \
354
- "#{txr.empty? ? 'null' : txr}," \
355
- "#{inp.empty? ? 'null' : "'#{inp}'"}," \
356
- "#{cta.empty? ? 'null' : "'#{cta}'"}," \
357
- "#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
358
- end
359
-
360
- # @example (see Apibc#inter_es)
284
+ cta = htx[:contractAddress]
285
+ "(#{[
286
+ integer(htx[:blockNumber]),
287
+ integer(htx[:timeStamp]),
288
+ quote(htx[:hash]),
289
+ integer(htx[:nonce]),
290
+ quote(htx[:blockHash]),
291
+ integer(htx[:transactionIndex]),
292
+ quote(htx[:from]),
293
+ quote(htx[:to]),
294
+ quote(htx[:iax]),
295
+ numeric(htx[:value]),
296
+ numeric(htx[:gas]),
297
+ numeric(htx[:gasPrice]),
298
+ numeric(htx[:gasUsed]),
299
+ integer(htx[:isError]),
300
+ txr.empty? ? 'null' : integer(txr),
301
+ inp.empty? ? 'null' : quote(inp),
302
+ cta.empty? ? 'null' : quote(cta),
303
+ integer(ops.dig(:h, htx[:blockNumber]) || 0)
304
+ ].join(',')})"
305
+ end
306
+
361
307
  # @param [Hash] htx transacao internas etherscan
362
308
  # @return [String] valores formatados nethi (internas parte1)
363
309
  def nethi_val(htx)
@@ -365,70 +311,70 @@ module Cns
365
311
  inp = htx[:input]
366
312
  tid = htx[:traceId]
367
313
  txr = htx[:errCode]
368
- "(#{Integer(htx[:blockNumber])}," \
369
- "#{Integer(htx[:timeStamp])}," \
370
- "'#{htx[:hash]}'," \
371
- "'#{htx[:from]}'," \
372
- "'#{htx[:to]}'," \
373
- "'#{htx[:iax]}'," \
374
- "cast('#{htx[:value]}' as numeric)," \
375
- "#{cta.empty? ? 'null' : "'#{cta}'"}," \
376
- "#{inp.empty? ? 'null' : "'#{inp}'"}," \
377
- "'#{htx[:type]}'," \
378
- "cast('#{htx[:gas]}' as numeric)," \
379
- "cast('#{htx[:gasUsed]}' as numeric)," \
380
- "#{tid.empty? ? 'null' : "'#{tid}'"}," \
381
- "#{Integer(htx[:isError])}," \
382
- "#{txr.empty? ? 'null' : txr})"
314
+ "(#{[
315
+ integer(htx[:blockNumber]),
316
+ integer(htx[:timeStamp]),
317
+ quote(htx[:hash]),
318
+ quote(htx[:from]),
319
+ quote(htx[:to]),
320
+ quote(htx[:iax]),
321
+ numeric(htx[:value]),
322
+ cta.empty? ? 'null' : quote(cta),
323
+ inp.empty? ? 'null' : quote(inp),
324
+ quote(htx[:type]),
325
+ numeric(htx[:gas]),
326
+ numeric(htx[:gasUsed]),
327
+ tid.empty? ? 'null' : quote(tid),
328
+ integer(htx[:isError]),
329
+ txr.empty? ? 'null' : integer(txr)
330
+ ].join(',')})"
383
331
  end
384
332
 
385
- # @example (see Apibc#block_es)
386
333
  # @param [Hash] htx transacao block etherscan
387
334
  # @return [String] valores formatados nethi (block parte1)
388
335
  def nethp_val(htx)
389
- "(#{Integer(htx[:blockNumber])}," \
390
- "#{Integer(htx[:timeStamp])}," \
391
- "cast('#{htx[:blockReward]}' as numeric)," \
392
- "'#{htx[:iax]}')"
336
+ "(#{[integer(htx[:blockNumber]), integer(htx[:timeStamp]), numeric(htx[:blockReward]), quote(htx[:iax])].join(',')})"
393
337
  end
394
338
 
395
- # @example (see Apibc#block_es)
396
339
  # @param [Hash] htx transacao withdrawals etherscan
397
340
  # @return [String] valores formatados nethi (withdrawals parte1)
398
341
  def nethw_val(htx)
399
- "(#{Integer(htx[:withdrawalIndex])}," \
400
- "#{Integer(htx[:validatorIndex])}," \
401
- "'#{htx[:address]}'," \
402
- "cast('#{htx[:amount]}' as numeric)," \
403
- "#{Integer(htx[:blockNumber])}," \
404
- "#{Integer(htx[:timestamp])})"
342
+ "(#{[
343
+ integer(htx[:withdrawalIndex]),
344
+ integer(htx[:validatorIndex]),
345
+ quote(htx[:address]),
346
+ numeric(htx[:amount]),
347
+ integer(htx[:blockNumber]),
348
+ integer(htx[:timestamp])
349
+ ].join(',')})"
405
350
  end
406
351
 
407
- # @example (see Apibc#token_es)
408
352
  # @param [Hash] hkx token event etherscan
409
353
  # @return [String] valores formatados nethk (token parte1)
410
- def nethk_val(hkx)
411
- cta = hkx[:contractAddress]
412
- inp = hkx[:input]
413
- "(#{Integer(hkx[:blockNumber])}," \
414
- "#{Integer(hkx[:timeStamp])}," \
415
- "'#{hkx[:hash]}'," \
416
- "#{Integer(hkx[:nonce])}," \
417
- "'#{hkx[:blockHash]}'," \
418
- "#{Integer(hkx[:transactionIndex])}," \
419
- "'#{hkx[:from]}'," \
420
- "'#{hkx[:to]}'," \
421
- "'#{hkx[:iax]}'," \
422
- "cast('#{hkx[:value]}' as numeric)," \
423
- "'#{hkx[:tokenName]}'," \
424
- "'#{hkx[:tokenSymbol]}'," \
425
- "#{Integer(hkx[:tokenDecimal])}," \
426
- "cast('#{hkx[:gas]}' as numeric)," \
427
- "cast('#{hkx[:gasPrice]}' as numeric)," \
428
- "cast('#{hkx[:gasUsed]}' as numeric)," \
429
- "#{inp.empty? ? 'null' : "'#{inp}'"}," \
430
- "#{cta.empty? ? 'null' : "'#{cta}'"}," \
431
- "#{Integer(ops[:h][hkx[:blockNumber]] || 0)})"
354
+ def nethk_val(htx)
355
+ inp = htx[:input]
356
+ cta = htx[:contractAddress]
357
+ "(#{[
358
+ integer(htx[:blockNumber]),
359
+ integer(htx[:timeStamp]),
360
+ quote(htx[:hash]),
361
+ integer(htx[:nonce]),
362
+ quote(htx[:blockHash]),
363
+ integer(htx[:transactionIndex]),
364
+ quote(htx[:from]),
365
+ quote(htx[:to]),
366
+ quote(htx[:iax]),
367
+ numeric(htx[:value]),
368
+ quote(htx[:tokenName]),
369
+ quote(htx[:tokenSymbol]),
370
+ integer(htx[:tokenDecimal]),
371
+ numeric(htx[:gas]),
372
+ numeric(htx[:gasPrice]),
373
+ numeric(htx[:gasUsed]),
374
+ inp.empty? ? 'null' : quote(inp),
375
+ cta.empty? ? 'null' : quote(cta),
376
+ integer(ops.dig(:h, htx[:blockNumber]) || 0)
377
+ ].join(',')})"
432
378
  end
433
379
 
434
380
  # @example (see Apibc#ledger_gm)
@@ -453,7 +399,6 @@ module Cns
453
399
  "#{ops[:h][String(hlx[:itx])] || 0})"
454
400
  end
455
401
 
456
- # @example (see Apice#trades_de)
457
402
  # @param [Hash] htx trade bitcoinde
458
403
  # @return [String] valores formatados det (trades parte1)
459
404
  def det_val(htx)
@@ -469,8 +414,6 @@ module Cns
469
414
  "#{Integer(ops[:h][htx[:trade_id]] || 0)})"
470
415
  end
471
416
 
472
- # @example (see Apice#deposits_de)
473
- # @example (see Apice#withdrawals_de)
474
417
  # @param [Hash] hlx ledger (deposits + withdrawals) bitcoinde
475
418
  # @return [String] valores formatados del (ledger)
476
419
  def del_val(hlx)
@@ -484,7 +427,6 @@ module Cns
484
427
  "cast(#{hlx[:fee]} as numeric))"
485
428
  end
486
429
 
487
- # @example (see Apice#trades_us)
488
430
  # @param [String] idx identificador transacao
489
431
  # @param [Hash] htx trade kraken
490
432
  # @return [String] valores formatados ust (trades parte1)
@@ -506,7 +448,6 @@ module Cns
506
448
  "#{Integer(ops[:h][idx] || 0)})"
507
449
  end
508
450
 
509
- # @example (see Apice#ledger_us)
510
451
  # @param idx (see ust_val)
511
452
  # @param [Hash] hlx ledger kraken
512
453
  # @return [String] valores formatados usl (ledger)
data/lib/cns/bitcoinde.rb CHANGED
@@ -63,7 +63,6 @@ module Cns
63
63
  @kyl ||= exd[:tl].map { |oex| oex[:txid] }.flatten - (ops[:t] ? [] : bqd[:nl].map { |obq| obq[:txid] })
64
64
  end
65
65
 
66
- # @example (see Apice#account_de)
67
66
  # @param [String] moe codigo bitcoinde da moeda
68
67
  # @param [Hash] hsx saldo bitcoinde da moeda
69
68
  # @return [String] texto formatado saldos
@@ -79,7 +78,6 @@ module Cns
79
78
  )
80
79
  end
81
80
 
82
- # @example (see Apice#trades_de)
83
81
  # @param (see Bigquery#det_val1)
84
82
  # @return [String] texto formatado trade
85
83
  def formata_trades(htx)
@@ -95,8 +93,6 @@ module Cns
95
93
  )
96
94
  end
97
95
 
98
- # @example (see Apice#deposits_unif_de)
99
- # @example (see Apice#withdrawals_unif_de)
100
96
  # @param (see Bigquery#del_val)
101
97
  # @return [String] texto formatado ledger
102
98
  def formata_ledger(hlx)
data/lib/cns/etherscan.rb CHANGED
@@ -29,27 +29,27 @@ module Cns
29
29
 
30
30
  # @return [Array<Hash>] lista transacoes normais novas
31
31
  def novtx
32
- @novtx ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten
32
+ @novtx ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
33
33
  end
34
34
 
35
35
  # @return [Array<Hash>] lista transacoes internas novas
36
36
  def novix
37
- @novix ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten
37
+ @novix ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
38
38
  end
39
39
 
40
40
  # @return [Array<Hash>] lista transacoes block novas
41
41
  def novpx
42
- @novpx ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten
42
+ @novpx ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
43
43
  end
44
44
 
45
45
  # @return [Array<Hash>] lista transacoes withdrawals novas
46
46
  def novwx
47
- @novwx ||= bcd.map { |obc| obc[:wx].select { |obj| idw.include?(obj[:itx]) } }.flatten
47
+ @novwx ||= bcd.map { |obc| obc[:wx].select { |obj| idw.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
48
48
  end
49
49
 
50
50
  # @return [Array<Hash>] lista transacoes token novas
51
51
  def novkx
52
- @novkx ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten
52
+ @novkx ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
53
53
  end
54
54
 
55
55
  # @return [Array<String>] lista dos meus enderecos
@@ -108,7 +108,7 @@ module Cns
108
108
  tx: filtrar_tx(acc, api.norml_es(acc)),
109
109
  ix: filtrar_tx(acc, api.inter_es(acc)),
110
110
  px: filtrar_px(acc, api.block_es(acc)),
111
- wx: filtrar_px(acc, api.withw_es(acc)),
111
+ wx: filtrar_wx(acc, api.withw_es(acc)),
112
112
  kx: filtrar_tx(acc, api.token_es(acc))
113
113
  }
114
114
  end
@@ -153,6 +153,14 @@ module Cns
153
153
  ary.map { |omp| omp.merge(itx: Integer(omp[:blockNumber]), iax: add) }
154
154
  end
155
155
 
156
+ # @param add (see Apibc#norml_es)
157
+ # @param [Array<Hash>] ary lista blocks events
158
+ # @return [Array<Hash>] lista blocks events filtrada
159
+ def filtrar_wx(add, ary)
160
+ # adiciona chave indice itx & adiciona identificador da carteira iax
161
+ ary.map { |omp| omp.merge(itx: Integer(omp[:withdrawalIndex]), iax: add) }
162
+ end
163
+
156
164
  # dt: Time.at(Integer(htx[:timeStamp])),
157
165
  # @return [Array<Hash>] lista ordenada transacoes normais novas
158
166
  def sortx
@@ -339,9 +347,9 @@ module Cns
339
347
  # @return [String] texto formatado transacao withdrawals etherscan
340
348
  def formata_transacao_withw(htx)
341
349
  format(
342
- '%<vi>9i %<bn>9i %<dt>10.10s %<vl>10.6f',
350
+ '%<vi>9i %<bn>10i %<dt>10.10s %<vl>10.6f',
343
351
  vi: htx[:validatorIndex],
344
- bn: htx[:blockNumber],
352
+ bn: htx[:withdrawalIndex],
345
353
  dt: Time.at(Integer(htx[:timestamp])),
346
354
  vl: (htx[:amount].to_d / (10**9)).round(10)
347
355
  )
@@ -383,7 +391,7 @@ module Cns
383
391
  def mostra_transacao_withw
384
392
  return unless ops[:v] && novwx.count.positive?
385
393
 
386
- puts("\nvalidator block data valor")
394
+ puts("\nvalidator withdrawal data valor")
387
395
  sorwx.each { |obj| puts(formata_transacao_withw(obj)) }
388
396
  end
389
397
 
data/lib/cns/greymass.rb CHANGED
@@ -83,11 +83,7 @@ module Cns
83
83
  def greymass_sl(add)
84
84
  hac = api.account_gm(add)
85
85
  htr = hac[:total_resources]
86
- [
87
- hac[:core_liquid_balance].to_d,
88
- htr[:net_weight].to_d,
89
- htr[:cpu_weight].to_d
90
- ]
86
+ [hac[:core_liquid_balance].to_d, htr[:net_weight].to_d, htr[:cpu_weight].to_d]
91
87
  end
92
88
 
93
89
  # @param add (see Apibc#account_gm)
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.2"
4
+ VERSION = '0.8.4'
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.2
4
+ version: 0.8.4
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-16 00:00:00.000000000 Z
10
+ date: 2025-02-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler