lib/etht/formatar.rb in etht-0.1.5 vs lib/etht/formatar.rb in etht-0.1.6
- old
+ new
@@ -2,12 +2,40 @@
# @author Hernani Rodrigues Vaz
module Etht
# (see Carteiras)
class Carteiras
+ # @param [String] add endereco carteira ether
+ # @param [Integer] max chars a mostrar
+ # @return [String] endereco ether formatado
+ # @example ether address inicio..fim
+ # 0x10f3a0cf0b534c..c033cf32e8a03586
+ def formata_endereco(add, max)
+ i = Integer((max - 2) / 2)
+ e = (max <= 20 ? dbq[:wb].select { |s| s[:ax] == add }.first : nil) || { id: add }
+ max < 7 ? 'erro' : "#{e[:id][0, i - 3]}..#{add[-i - 3..]}"
+ end
+
+ # @parm [Hash] hjn dados juntos bigquery & etherscan
+ # @return [String] texto formatado duma carteira
+ def formata_carteira(hjn)
+ format(
+ '%<s1>-6.6s %<s2>-34.34s ',
+ s1: hjn[:id],
+ s2: formata_endereco(hjn[:ax], 34)
+ ) + formata_valores(hjn)
+ end
+
+ # @parm (see formata_carteira)
+ # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
+ def ok?(hjn)
+ hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count && hjn[:bk].count == hjn[:ek].count
+ end
+
+ # @parm (see formata_carteira)
# @return [String] texto formatado valores duma carteira
- def valores(hjn)
+ def formata_valores(hjn)
format(
'%<v1>10.6f %<n1>2i %<n3>2i %<v2>11.6f %<n2>2i %<n4>2i %<ok>-3s',
v1: hjn[:bs],
n1: hjn[:bt].count,
n3: hjn[:bk].count,
@@ -16,75 +44,67 @@
n4: hjn[:ek].count,
ok: ok?(hjn) ? 'OK' : 'NOK'
)
end
+ # @parm [Hash] htx transacao normal
# @return [String] texto formatado transacao normal
- def formata_tx(htx)
+ def formata_transacao_norml(htx)
format(
'%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>17.6f',
bn: htx['blockNumber'],
- fr: ftx(htx['from'], 20),
- to: ftx(htx['to'], 20),
+ fr: formata_endereco(htx['from'], 20),
+ to: formata_endereco(htx['to'], 20),
dt: Time.at(Integer(htx['timeStamp'])),
vl: (htx['value'].to_d / 10**18).round(10)
)
end
+ # @parm [Hash] hkx transacao token
# @return [String] texto formatado transacao token
- def formata_kx(hkx)
+ def formata_transacao_token(hkx)
format(
- '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>11.3f %<sy>-5.5s',
+ '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<sy>-5.5s %<vl>11.3f',
bn: hkx['blockNumber'],
- fr: ftx(hkx['from'], 20),
- to: ftx(hkx['to'], 20),
+ fr: formata_endereco(hkx['from'], 20),
+ to: formata_endereco(hkx['to'], 20),
dt: Time.at(Integer(hkx['timeStamp'])),
vl: (hkx['value'].to_d / 10**18).round(10),
sy: hkx['tokenSymbol']
)
end
- # @return [String] texto lista carteiras & lista transacoes & ajuste dias
- def mostra
- return unless dadosjn.count.positive?
+ # @return [String] texto carteiras & transacoes & ajuste dias
+ def mostra_resumo
+ return unless djn.count.positive?
puts("\nid address ----bigquery---- ----etherscan----")
- dadosjn.each { |e| puts format('%<s1>-6.6s %<s2>-34.34s ', s1: e[:id], s2: ftx(e[:ax], 34)) + valores(e) }
- mostra_tx
- mostra_kx
- mostra_ha
+ djn.each { |e| puts(formata_carteira(e)) }
+ mostra_transacao_norml
+ mostra_transacao_token
+ mostra_configuracao_ajuste_dias
end
- # @example ether address inicio..fim
- # 0x10f3a0cf0b534c..c033cf32e8a03586
- # @param [String] add ether address
- # @param [Integer] max chars a mostrar
- # @return [String] ether address formatada
- def ftx(add, max)
- i = Integer((max - 2) / 2)
- max < 7 ? 'erro' : "#{add[0, i]}..#{add[-i..]}"
- end
+ # @return [String] texto transacoes normais
+ def mostra_transacao_norml
+ return unless ops[:v] && norml.count.positive?
- # @return [String] lista transacoes normais
- def mostra_tx
- return unless novaest.count.positive? && ops[:v]
-
puts("\ntx normal address from address to ---data--- ------valor------")
- sortest.each { |e| puts formata_tx(e) }
+ norml_sort.each { |e| puts(formata_transacao_norml(e)) }
end
- # @return [String] lista transacoes token
- def mostra_kx
- return unless novaesk.count.positive? && ops[:v]
+ # @return [String] texto transacoes token
+ def mostra_transacao_token
+ return unless ops[:v] && token.count.positive?
- puts("\ntx token address from address to ---data--- ---valor--- token")
- sortesk.each { |e| puts formata_kx(e) }
+ puts("\ntx token address from address to ---data--- token ---valor---")
+ token_sort.each { |e| puts(formata_transacao_token(e)) }
end
- # @return [String] texto configuracao ajuste dias
- def mostra_ha
- return unless (novaest.count + novaesk.count).positive? && ops[:v]
+ # @return [String] texto configuracao ajuste dias das transacoes (normais & tokan)
+ def mostra_configuracao_ajuste_dias
+ return unless (norml.count + token.count).positive?
- puts("\nstring ajuste dias\n-h=#{totalha.map { |e| "#{e['blockNumber']}:0" }.join(' ')}")
+ puts("\nstring ajuste dias\n-h=#{todas_sort.map { |e| "#{e['blockNumber']}:0" }.join(' ')}")
end
end
end