etht 0.1.5 → 0.1.6

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: f5a76fade4364cb9ecc118fcfae181f13d84fe3e39ba85a6078e8974ab403652
4
- data.tar.gz: 269e68983b59463ec5aaeb3e0179b28f79f6a43135e2401269c467e0d90a74c4
3
+ metadata.gz: 7f58f14834a4fe6a2b700d12029a4bf6a59142961ae668853698d4879da51728
4
+ data.tar.gz: 511eb750d417812fbd074499fdd7734c5c146e2558f0ac1fb9a9c017b74a476a
5
5
  SHA512:
6
- metadata.gz: 9f446bfb04b77cf6d7cfc366f12b564a6385837484d388121341dbb4fa26d36e07f30d3883871d8e7bbbe1a353a3ed838fa95a2aa5b1d15026a8fc099f6e8389
7
- data.tar.gz: 65936552f2176a0706e417579fa6747a8c7fcc9937a23d1f83fca413c2a964c6e37ee58cfd1dd086e964367d723e0ce828a130e182043129c4cc84117227ae75
6
+ metadata.gz: 33e1a218d03fa87bc4ce457c1c4b922ac2d9d3f6d3adbcc4fce4cabf3c2197f1e34a32e1a7e11a209a13e06b41003340a57373f5c23d2cf96ad09b2e46cfb3bd
7
+ data.tar.gz: 03dbc955e3ac7fef1f3f17b50c2ca9b40b2f333e84f6d0569fc90f19eea32b7c5754eb24a96693344a08006942b455d322f4820fb0fd6af1fc7281b5ae55afa2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- etht (0.1.5)
4
+ etht (0.1.6)
5
5
  faraday
6
6
  google-cloud-bigquery
7
7
  json
@@ -26,11 +26,12 @@ module Etht
26
26
  Bigquery.new(options).processa
27
27
  end
28
28
 
29
- desc 'show', 'mostra carteiras e dados bigquery & etherscan'
30
- option :v, type: :boolean, default: false, desc: 'mostra dados transacoes normais & token'
31
- # mostra carteiras e dados bigquery & etherscan
29
+ desc 'show', 'mostra reumo carteiras & transacoes'
30
+ option :v, type: :boolean, default: false, desc: 'mostra transacoes normais & token'
31
+ option :t, type: :boolean, default: false, desc: 'mostra transacoes todas ou somente novas'
32
+ # mostra reumo carteiras & transacoes
32
33
  def show
33
- Bigquery.new(options).carteiras.mostra
34
+ Bigquery.new(options).carteiras.mostra_resumo
34
35
  end
35
36
 
36
37
  default_task :show
@@ -18,7 +18,8 @@ module Etht
18
18
 
19
19
  # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
20
20
  # @option pop [Hash] :h ({}) configuracao ajuste reposicionamento temporal
21
- # @option pop [Boolean] :v (false) mostra dados transacoes normais & token?
21
+ # @option pop [Boolean] :v (false) mostra transacoes normais & token?
22
+ # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
22
23
  # @return [Bigquery] API bigquery & API etherscan
23
24
  def initialize(pop)
24
25
  # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
@@ -28,8 +29,8 @@ module Etht
28
29
  end
29
30
 
30
31
  # @return [Carteiras] API etherscan - processar transacoes normais e tokens
31
- def carteiras
32
- @carteiras ||= Carteiras.new(
32
+ def transacoes
33
+ @transacoes ||= Carteiras.new(
33
34
  {
34
35
  wb: sql("select * from #{BD}.walletEth order by 2")
35
36
  .map { |e| { id: e[:id], ax: e[:address], sl: e[:saldo].to_d.round(10) } },
@@ -40,20 +41,32 @@ module Etht
40
41
  )
41
42
  end
42
43
 
43
- # insere transacoes novas nas tabelas etht, ethk
44
+ # @return [Carteiras] API etherscan - processar carteiras & transacoes normais e tokens
45
+ def carteiras
46
+ transacoes
47
+ end
48
+
49
+ # insere transacoes novas nas tabelas etht (trx normais), ethk (trx token)
44
50
  def processa
45
- puts(format("%<n>2i LINHAS INSERIDAS #{BD}.etht", n: carteiras.novaest.count.positive? ? dml(etht_ins) : 0))
46
- puts(format("%<n>2i LINHAS INSERIDAS #{BD}.ethk", n: carteiras.novaesk.count.positive? ? dml(ethk_ins) : 0))
51
+ puts(format("%<n>2i LINHAS INSERIDAS #{BD}.etht", n: transacoes.norml.count.positive? ? dml(etht_ins) : 0))
52
+ puts(format("%<n>2i LINHAS INSERIDAS #{BD}.ethk", n: transacoes.token.count.positive? ? dml(ethk_ins) : 0))
47
53
  end
48
54
 
49
- # @return [String] comando insert SQL formatado bigquery.etht
55
+ # @return [String] comando insert SQL formatado etht (trx normais)
50
56
  def etht_ins
51
57
  "insert #{BD}.etht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,value,gas," \
52
58
  'gasprice,iserror,txreceipt_status,input,contractaddress,cumulativegasused,gasused,confirmations,dias' \
53
- ") VALUES(#{carteiras.novaest.map { |e| etht_val1(e) }.join(',')})"
59
+ ") VALUES(#{transacoes.norml.map { |e| etht_val1(e) }.join(',')})"
60
+ end
61
+
62
+ # @return [String] comando insert SQL formatado ethk (trx token)
63
+ def ethk_ins
64
+ "insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,axfrom,contractaddress,axto,value,tokenname," \
65
+ 'tokensymbol,tokendecimal,transactionindex,gas,gasprice,gasused,cumulativegasused,input,confirmations,dias' \
66
+ ") VALUES(#{transacoes.token.map { |e| ethk_val1(e) }.join(',')})"
54
67
  end
55
68
 
56
- # @return [String] valores formatados bigquery.etht parte1
69
+ # @return [String] valores formatados etht (trx normais parte1)
57
70
  def etht_val1(hes)
58
71
  "#{Integer(hes['blockNumber'])}," \
59
72
  "#{Integer(hes['timeStamp'])}," \
@@ -66,7 +79,7 @@ module Etht
66
79
  "#{etht_val2(hes)}"
67
80
  end
68
81
 
69
- # @return [String] valores formatados bigquery.etht parte2
82
+ # @return [String] valores formatados etht (trx normais parte2)
70
83
  def etht_val2(hes)
71
84
  "cast('#{hes['value']}' as numeric)," \
72
85
  "cast('#{hes['gas']}' as numeric)," \
@@ -77,21 +90,14 @@ module Etht
77
90
  "#{etht_val3(hes)}"
78
91
  end
79
92
 
80
- # @return [String] valores formatados bigquery.etht parte3
93
+ # @return [String] valores formatados etht (trx normais parte3)
81
94
  def etht_val3(hes)
82
95
  "#{hes['contractAddress'].length.zero? ? 'null' : "'#{hes['contractAddress']}'"}," \
83
96
  "0,cast('#{hes['gasUsed']}' as numeric),0," \
84
97
  "#{Integer(ops[:h][hes['blockNumber']] || 0)}"
85
98
  end
86
99
 
87
- # @return [String] comando insert SQL formatado bigquery.ethk
88
- def ethk_ins
89
- "insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,axfrom,contractaddress,axto,value,tokenname," \
90
- 'tokensymbol,tokendecimal,transactionindex,gas,gasprice,gasused,cumulativegasused,input,confirmations,dias' \
91
- ") VALUES(#{carteiras.novaesk.map { |e| ethk_val1(e) }.join(',')})"
92
- end
93
-
94
- # @return [String] valores formatados bigquery.ethk parte1
100
+ # @return [String] valores formatados ethk (trx token parte1)
95
101
  def ethk_val1(hes)
96
102
  "#{Integer(hes['blockNumber'])}," \
97
103
  "#{Integer(hes['timeStamp'])}," \
@@ -102,7 +108,7 @@ module Etht
102
108
  "#{ethk_val2(hes)}"
103
109
  end
104
110
 
105
- # @return [String] valores formatados bigquery.ethk parte2
111
+ # @return [String] valores formatados ethk (trx token parte2)
106
112
  def ethk_val2(hes)
107
113
  "#{hes['contractAddress'].length.zero? ? 'null' : "'#{hes['contractAddress']}'"}," \
108
114
  "'#{hes['to']}'," \
@@ -114,7 +120,7 @@ module Etht
114
120
  "#{ethk_val3(hes)}"
115
121
  end
116
122
 
117
- # @return [String] valores formatados bigquery.ethk parte3
123
+ # @return [String] valores formatados ethk (trx token parte3)
118
124
  def ethk_val3(hes)
119
125
  "cast('#{hes['gas']}' as numeric)," \
120
126
  "cast('#{hes['gasPrice']}' as numeric)," \
@@ -22,53 +22,54 @@ module Etht
22
22
  @api = Etherscan.new
23
23
  @dbq = dad
24
24
  @ops = pop
25
+ p(ops)
25
26
  end
26
27
 
27
28
  # @return [Array<Hash>] todos os dados etherscan - saldos & transacoes
28
- def dadoses
29
- @dadoses ||= api.multi_address_balance(dbq[:wb].map { |c| c[:ax] }).map { |e| base_etherscan(e) }
29
+ def des
30
+ @des ||= api.multi_address_balance(dbq[:wb].map { |c| c[:ax] }).map { |e| base_etherscan(e) }
30
31
  end
31
32
 
32
- # @return [Array<Integer>] lista blocknumbers novos de transacoes normais
33
- def novobnt
34
- @novobnt ||= (dadoses.map { |e| e[:tx].map { |n| Integer(n['blockNumber']) } }.flatten -
35
- dbq[:nt].map { |t| t[:blocknumber] }).uniq
33
+ # @return [Array<Hash>] todos os dados juntos bigquery & etherscan
34
+ def djn
35
+ @djn ||= dbq[:wb].map { |b| bigquery_etherscan(b, des.select { |s| b[:ax] == s[:ax] }.first) }
36
36
  end
37
37
 
38
- # @return [Array<Integer>] lista blocknumbers novos de transacoes token
39
- def novobnk
40
- @novobnk ||= (dadoses.map { |e| e[:kx].map { |n| Integer(n['blockNumber']) } }.flatten -
41
- dbq[:nk].map { |t| t[:blocknumber] }).uniq
38
+ # @return [Array<Integer>] lista blocknumbers de transacoes normais
39
+ def bnt
40
+ @bnt ||= (des.map { |e| e[:tx].map { |n| Integer(n['blockNumber']) } }.flatten -
41
+ (ops[:t] ? [] : dbq[:nt].map { |t| t[:blocknumber] })).uniq
42
42
  end
43
43
 
44
- # @return [Array<Hash>] lista transacoes normais novas
45
- def novaest
46
- @novaest ||= dadoses.map { |e| e[:tx].select { |s| novobnt.include?(Integer(s['blockNumber'])) } }.flatten.uniq
44
+ # @return [Array<Integer>] lista blocknumbers de transacoes token
45
+ def bnk
46
+ @bnk ||= (des.map { |e| e[:kx].map { |n| Integer(n['blockNumber']) } }.flatten -
47
+ (ops[:t] ? [] : dbq[:nk].map { |t| t[:blocknumber] })).uniq
47
48
  end
48
49
 
49
- # @return [Array<Hash>] lista transacoes tokan novas
50
- def novaesk
51
- @novaesk ||= dadoses.map { |e| e[:kx].select { |s| novobnk.include?(Integer(s['blockNumber'])) } }.flatten.uniq
50
+ # @return [Array<Hash>] lista transacoes normais
51
+ def norml
52
+ @norml ||= des.map { |e| e[:tx].select { |s| bnt.include?(Integer(s['blockNumber'])) } }.flatten.uniq
52
53
  end
53
54
 
54
- # @return [Array<Hash>] totdos dados juntos bigquery & etherscan
55
- def dadosjn
56
- @dadosjn ||= dbq[:wb].map { |b| bigquery_etherscan(b, dadoses.select { |s| b[:ax] == s[:ax] }.first) }
55
+ # @return [Array<Hash>] lista transacoes tokan
56
+ def token
57
+ @token ||= des.map { |e| e[:kx].select { |s| bnk.include?(Integer(s['blockNumber'])) } }.flatten.uniq
57
58
  end
58
59
 
59
- # @return [Array<Hash>] lista ordenada transacoes normais novas
60
- def sortest
61
- novaest.sort { |a, b| Integer(a['blockNumber']) <=> Integer(b['blockNumber']) }
60
+ # @return [Array<Hash>] lista ordenada transacoes normais
61
+ def norml_sort
62
+ norml.sort { |a, b| Integer(a['blockNumber']) <=> Integer(b['blockNumber']) }
62
63
  end
63
64
 
64
- # @return [Array<Hash>] lista ordenada transacoes tokan novas
65
- def sortesk
66
- novaesk.sort { |a, b| Integer(a['blockNumber']) <=> Integer(b['blockNumber']) }
65
+ # @return [Array<Hash>] lista ordenada transacoes tokan
66
+ def token_sort
67
+ token.sort { |a, b| Integer(a['blockNumber']) <=> Integer(b['blockNumber']) }
67
68
  end
68
69
 
69
- # @return [Array<Hash>] lista ordenada transacoes normais & tokan novas
70
- def totalha
71
- (novaest + novaesk).sort { |a, b| Integer(a['blockNumber']) <=> Integer(b['blockNumber']) }
70
+ # @return [Array<Hash>] lista ordenada todas as transacoes (normais & tokan)
71
+ def todas_sort
72
+ (norml + token).sort { |a, b| Integer(a['blockNumber']) <=> Integer(b['blockNumber']) }
72
73
  end
73
74
 
74
75
  # @param [Hash] hes dados etherscan
@@ -98,7 +99,7 @@ module Etht
98
99
  }
99
100
  end
100
101
 
101
- # @param [String] add endereco da carteira
102
+ # @param add (see formata_endereco)
102
103
  # @return [Array<Hash>] lista transacoes normais ligadas a uma carteira - sem elementos irrelevantes
103
104
  def etherscan_tx(add)
104
105
  api.normal_tx(add).map do |e|
@@ -108,7 +109,7 @@ module Etht
108
109
  end
109
110
  end
110
111
 
111
- # @param (see etherscan_tx)
112
+ # @param add (see formata_endereco)
112
113
  # @return [Array<Hash>] lista transacoes token ligadas a uma carteira - sem elementos irrelevantes
113
114
  def etherscan_kx(add)
114
115
  api.token_tx(add).map do |e|
@@ -117,10 +118,5 @@ module Etht
117
118
  e
118
119
  end
119
120
  end
120
-
121
- # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
122
- def ok?(hjn)
123
- hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count && hjn[:bk].count == hjn[:ek].count
124
- end
125
121
  end
126
122
  end
@@ -4,8 +4,36 @@
4
4
  module Etht
5
5
  # (see Carteiras)
6
6
  class Carteiras
7
+ # @param [String] add endereco carteira ether
8
+ # @param [Integer] max chars a mostrar
9
+ # @return [String] endereco ether formatado
10
+ # @example ether address inicio..fim
11
+ # 0x10f3a0cf0b534c..c033cf32e8a03586
12
+ def formata_endereco(add, max)
13
+ i = Integer((max - 2) / 2)
14
+ e = (max <= 20 ? dbq[:wb].select { |s| s[:ax] == add }.first : nil) || { id: add }
15
+ max < 7 ? 'erro' : "#{e[:id][0, i - 3]}..#{add[-i - 3..]}"
16
+ end
17
+
18
+ # @parm [Hash] hjn dados juntos bigquery & etherscan
19
+ # @return [String] texto formatado duma carteira
20
+ def formata_carteira(hjn)
21
+ format(
22
+ '%<s1>-6.6s %<s2>-34.34s ',
23
+ s1: hjn[:id],
24
+ s2: formata_endereco(hjn[:ax], 34)
25
+ ) + formata_valores(hjn)
26
+ end
27
+
28
+ # @parm (see formata_carteira)
29
+ # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
30
+ def ok?(hjn)
31
+ hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count && hjn[:bk].count == hjn[:ek].count
32
+ end
33
+
34
+ # @parm (see formata_carteira)
7
35
  # @return [String] texto formatado valores duma carteira
8
- def valores(hjn)
36
+ def formata_valores(hjn)
9
37
  format(
10
38
  '%<v1>10.6f %<n1>2i %<n3>2i %<v2>11.6f %<n2>2i %<n4>2i %<ok>-3s',
11
39
  v1: hjn[:bs],
@@ -18,73 +46,65 @@ module Etht
18
46
  )
19
47
  end
20
48
 
49
+ # @parm [Hash] htx transacao normal
21
50
  # @return [String] texto formatado transacao normal
22
- def formata_tx(htx)
51
+ def formata_transacao_norml(htx)
23
52
  format(
24
53
  '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>17.6f',
25
54
  bn: htx['blockNumber'],
26
- fr: ftx(htx['from'], 20),
27
- to: ftx(htx['to'], 20),
55
+ fr: formata_endereco(htx['from'], 20),
56
+ to: formata_endereco(htx['to'], 20),
28
57
  dt: Time.at(Integer(htx['timeStamp'])),
29
58
  vl: (htx['value'].to_d / 10**18).round(10)
30
59
  )
31
60
  end
32
61
 
62
+ # @parm [Hash] hkx transacao token
33
63
  # @return [String] texto formatado transacao token
34
- def formata_kx(hkx)
64
+ def formata_transacao_token(hkx)
35
65
  format(
36
- '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>11.3f %<sy>-5.5s',
66
+ '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<sy>-5.5s %<vl>11.3f',
37
67
  bn: hkx['blockNumber'],
38
- fr: ftx(hkx['from'], 20),
39
- to: ftx(hkx['to'], 20),
68
+ fr: formata_endereco(hkx['from'], 20),
69
+ to: formata_endereco(hkx['to'], 20),
40
70
  dt: Time.at(Integer(hkx['timeStamp'])),
41
71
  vl: (hkx['value'].to_d / 10**18).round(10),
42
72
  sy: hkx['tokenSymbol']
43
73
  )
44
74
  end
45
75
 
46
- # @return [String] texto lista carteiras & lista transacoes & ajuste dias
47
- def mostra
48
- return unless dadosjn.count.positive?
76
+ # @return [String] texto carteiras & transacoes & ajuste dias
77
+ def mostra_resumo
78
+ return unless djn.count.positive?
49
79
 
50
80
  puts("\nid address ----bigquery---- ----etherscan----")
51
- dadosjn.each { |e| puts format('%<s1>-6.6s %<s2>-34.34s ', s1: e[:id], s2: ftx(e[:ax], 34)) + valores(e) }
52
- mostra_tx
53
- mostra_kx
54
- mostra_ha
55
- end
56
-
57
- # @example ether address inicio..fim
58
- # 0x10f3a0cf0b534c..c033cf32e8a03586
59
- # @param [String] add ether address
60
- # @param [Integer] max chars a mostrar
61
- # @return [String] ether address formatada
62
- def ftx(add, max)
63
- i = Integer((max - 2) / 2)
64
- max < 7 ? 'erro' : "#{add[0, i]}..#{add[-i..]}"
81
+ djn.each { |e| puts(formata_carteira(e)) }
82
+ mostra_transacao_norml
83
+ mostra_transacao_token
84
+ mostra_configuracao_ajuste_dias
65
85
  end
66
86
 
67
- # @return [String] lista transacoes normais
68
- def mostra_tx
69
- return unless novaest.count.positive? && ops[:v]
87
+ # @return [String] texto transacoes normais
88
+ def mostra_transacao_norml
89
+ return unless ops[:v] && norml.count.positive?
70
90
 
71
91
  puts("\ntx normal address from address to ---data--- ------valor------")
72
- sortest.each { |e| puts formata_tx(e) }
92
+ norml_sort.each { |e| puts(formata_transacao_norml(e)) }
73
93
  end
74
94
 
75
- # @return [String] lista transacoes token
76
- def mostra_kx
77
- return unless novaesk.count.positive? && ops[:v]
95
+ # @return [String] texto transacoes token
96
+ def mostra_transacao_token
97
+ return unless ops[:v] && token.count.positive?
78
98
 
79
- puts("\ntx token address from address to ---data--- ---valor--- token")
80
- sortesk.each { |e| puts formata_kx(e) }
99
+ puts("\ntx token address from address to ---data--- token ---valor---")
100
+ token_sort.each { |e| puts(formata_transacao_token(e)) }
81
101
  end
82
102
 
83
- # @return [String] texto configuracao ajuste dias
84
- def mostra_ha
85
- return unless (novaest.count + novaesk.count).positive? && ops[:v]
103
+ # @return [String] texto configuracao ajuste dias das transacoes (normais & tokan)
104
+ def mostra_configuracao_ajuste_dias
105
+ return unless (norml.count + token.count).positive?
86
106
 
87
- puts("\nstring ajuste dias\n-h=#{totalha.map { |e| "#{e['blockNumber']}:0" }.join(' ')}")
107
+ puts("\nstring ajuste dias\n-h=#{todas_sort.map { |e| "#{e['blockNumber']}:0" }.join(' ')}")
88
108
  end
89
109
  end
90
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Etht
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etht
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
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-08-20 00:00:00.000000000 Z
11
+ date: 2020-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler