cns 0.3.4 → 0.3.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.
@@ -1,190 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @author Hernani Rodrigues Vaz
4
- module Cns
5
- # classe para processar transacoes do etherscan
6
- class Etherscan
7
- # @return [String] texto carteiras & transacoes & ajuste dias
8
- def mostra_resumo
9
- return unless dados.count.positive?
10
-
11
- puts("\nid address etherscan tn ti tb tk tw bigquery tn ti tb tk tw")
12
- dados.each { |obj| puts(formata_carteira(obj)) }
13
- mostra_transacao_norml
14
- mostra_transacao_inter
15
- mostra_transacao_block
16
- mostra_transacao_token
17
- mostra_transacao_withw
18
- mostra_configuracao_ajuste_dias
19
- end
20
-
21
- # @param [Hash] hjn dados juntos bigquery & etherscan
22
- # @return [String] texto formatado duma carteira
23
- def formata_carteira(hjn)
24
- format(
25
- '%<s1>-6.6s %<s2>-16.16s ',
26
- s1: hjn[:id],
27
- s2: formata_enderec1(hjn[:ax], 16)
28
- ) + formata_valores(hjn)
29
- end
30
-
31
- # @param (see formata_carteira)
32
- # @return [String] texto formatado valores duma carteira
33
- def formata_valores(hjn)
34
- format(
35
- '%<v1>12.6f %<n1>3i %<n2>2i %<n3>2i %<n4>2i %<w1>3i %<v2>12.6f %<n5>3i %<n6>2i %<n7>2i %<n8>2i %<w2>3i %<ok>-3s',
36
- v1: hjn[:es],
37
- n1: hjn[:et].count,
38
- n2: hjn[:ei].count,
39
- n3: hjn[:ep].count,
40
- n4: hjn[:ek].count,
41
- w1: hjn[:ew].count,
42
- v2: hjn[:bs],
43
- n5: hjn[:bt].count,
44
- n6: hjn[:bi].count,
45
- n7: hjn[:bp].count,
46
- n8: hjn[:bk].count,
47
- w2: hjn[:bw].count,
48
- ok: ok?(hjn) ? 'OK' : 'NOK'
49
- )
50
- end
51
-
52
- # @param (see formata_carteira)
53
- # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
54
- def ok?(hjn)
55
- hjn[:bs].round(6) == hjn[:es].round(6) && hjn[:bt].count == hjn[:et].count && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bk].count == hjn[:ek].count && hjn[:bw].count == hjn[:ew].count
56
- end
57
-
58
- # @example ether address inicio..fim
59
- # 0x10f3a0cf0b534c..c033cf32e8a03586
60
- # @param add (see filtrar_tx)
61
- # @param [Integer] max chars a mostrar
62
- # @return [String] endereco formatado
63
- def formata_enderec1(add, max)
64
- return 'erro' if max < 7
65
-
66
- max -= 2
67
- ini = Integer(max / 2) + 3
68
- inf = max % 2
69
- "#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
70
- end
71
-
72
- # @example ether address inicio..fim
73
- # me-app..4b437776403d
74
- # @param add (see filtrar_tx)
75
- # @param [Integer] max chars a mostrar
76
- # @return [String] endereco formatado
77
- def formata_enderec2(add, max)
78
- return 'erro' if max < 7
79
-
80
- max -= 2
81
- ini = Integer(max / 2)
82
- inf = max % 2
83
- hid = bqd[:wb].select { |obj| obj[:ax] == add }.first
84
- ndd = hid ? hid[:id] + '-' + add : add
85
- "#{ndd[0, ini - 3]}..#{ndd[-inf - ini - 3..]}"
86
- end
87
-
88
- # @example (see Apibc#norml_es)
89
- # @param [Hash] htx transacao normal etherscan
90
- # @return [String] texto formatado transacao normal etherscan
91
- def formata_transacao_norml(htx)
92
- format(
93
- '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>17.6f',
94
- bn: htx[:blockNumber],
95
- fr: formata_enderec2(htx[:from], 20),
96
- to: formata_enderec2(htx[:to], 20),
97
- dt: Time.at(Integer(htx[:timeStamp])),
98
- vl: (htx[:value].to_d / 10**18).round(10)
99
- )
100
- end
101
-
102
- # @example (see Apibc#block_es)
103
- # @param [Hash] htx transacao block etherscan
104
- # @return [String] texto formatado transacao block etherscan
105
- def formata_transacao_block(htx)
106
- format(
107
- '%<bn>9i %<fr>-41.41s %<dt>10.10s %<vl>17.6f',
108
- bn: htx[:blockNumber],
109
- fr: formata_enderec2(htx[:iax], 41),
110
- dt: Time.at(Integer(htx[:timeStamp])),
111
- vl: (htx[:blockReward].to_d / 10**18).round(10)
112
- )
113
- end
114
-
115
- # @example (see Apibc#token_es)
116
- # @param [Hash] hkx transacao token etherscan
117
- # @return [String] texto formatado transacao token etherscan
118
- def formata_transacao_token(hkx)
119
- format(
120
- '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>11.3f %<sy>-5.5s',
121
- bn: hkx[:blockNumber],
122
- fr: formata_enderec2(hkx[:from], 20),
123
- to: formata_enderec2(hkx[:to], 20),
124
- dt: Time.at(Integer(hkx[:timeStamp])),
125
- vl: (hkx[:value].to_d / 10**18).round(10),
126
- sy: hkx[:tokenSymbol]
127
- )
128
- end
129
-
130
- # @example (see Apibc#block_es)
131
- # @param [Hash] htx transacao withdrawals etherscan
132
- # @return [String] texto formatado transacao withdrawals etherscan
133
- def formata_transacao_withw(htx)
134
- format(
135
- '%<vi>9i %<bn>9i %<dt>10.10s %<vl>10.6f',
136
- vi: htx[:validatorIndex],
137
- bn: htx[:blockNumber],
138
- dt: Time.at(Integer(htx[:timestamp])),
139
- vl: (htx[:amount].to_d / 10**9).round(10)
140
- )
141
- end
142
-
143
- # @return [String] texto transacoes normais
144
- def mostra_transacao_norml
145
- return unless ops[:v] && novtx.count.positive?
146
-
147
- puts("\ntx normal from to data valor")
148
- sortx.each { |obj| puts(formata_transacao_norml(obj)) }
149
- end
150
-
151
- # @return [String] texto transacoes internas
152
- def mostra_transacao_inter
153
- return unless ops[:v] && novix.count.positive?
154
-
155
- puts("\ntx intern from to data valor")
156
- sorix.each { |obj| puts(formata_transacao_norml(obj)) }
157
- end
158
-
159
- # @return [String] texto transacoes block
160
- def mostra_transacao_block
161
- return unless ops[:v] && novpx.count.positive?
162
-
163
- puts("\ntx block address data valor")
164
- sorpx.each { |obj| puts(formata_transacao_block(obj)) }
165
- end
166
-
167
- # @return [String] texto transacoes token
168
- def mostra_transacao_token
169
- return unless ops[:v] && novkx.count.positive?
170
-
171
- puts("\ntx token from to data valor")
172
- sorkx.each { |obj| puts(formata_transacao_token(obj)) }
173
- end
174
-
175
- # @return [String] texto transacoes withdrawals
176
- def mostra_transacao_withw
177
- return unless ops[:v] && novwx.count.positive?
178
-
179
- puts("\nvalidator block data valor")
180
- sorwx.each { |obj| puts(formata_transacao_withw(obj)) }
181
- end
182
-
183
- # @return [String] texto configuracao ajuste dias das transacoes (normais & token)
184
- def mostra_configuracao_ajuste_dias
185
- return unless (novtx.count + novkx.count).positive?
186
-
187
- puts("\nstring ajuste dias\n-h=#{sorax.map { |obj| "#{obj[:blockNumber]}:0" }.join(' ')}")
188
- end
189
- end
190
- end
data/lib/cns/greymass2.rb DELETED
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @author Hernani Rodrigues Vaz
4
- module Cns
5
- # classe para processar transacoes do greymass
6
- class Greymass
7
- # @return [String] texto carteiras & transacoes & ajuste dias
8
- def mostra_resumo
9
- return unless dados.count.positive?
10
-
11
- puts("\naddress greymass ntx bigquery ntx")
12
- dados.each { |obj| puts(formata_carteira(obj)) }
13
- mostra_transacoes_novas
14
- mostra_configuracao_ajuste_dias
15
- end
16
-
17
- # @param [Hash] hjn dados juntos bigquery & greymass
18
- # @return [String] texto formatado duma carteira
19
- def formata_carteira(hjn)
20
- format(
21
- '%<s1>-12.12s %<v1>14.4f %<n1>4i %<v2>14.4f %<n2>4i %<ok>-3s',
22
- s1: hjn[:ax],
23
- v1: hjn[:es],
24
- n1: hjn[:et].count,
25
- v2: hjn[:bs],
26
- n2: hjn[:bt].count,
27
- ok: ok?(hjn) ? 'OK' : 'NOK'
28
- )
29
- end
30
-
31
- # @param (see formata_carteira)
32
- # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
33
- def ok?(hjn)
34
- hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
35
- end
36
-
37
- # @example (see Apibc#ledger_gm)
38
- # @param [Hash] hlx ledger greymass
39
- # @return [String] texto formatado ledger greymass
40
- def formata_ledger(hlx)
41
- format(
42
- '%<bn>12i %<fr>-12.12s %<to>-12.12s %<ac>-10.10s %<dt>10.10s %<vl>12.4f %<sy>-6.6s',
43
- ac: (act = hlx[:action_trace][:act])[:name],
44
- fr: (adt = act[:data])[:from],
45
- vl: (aqt = adt[:quantity].to_s).to_d,
46
- bn: hlx[:itx],
47
- to: adt[:to],
48
- dt: Date.parse(hlx[:block_time]),
49
- sy: aqt[/[[:upper:]]+/]
50
- )
51
- end
52
-
53
- # @return [String] texto transacoes
54
- def mostra_transacoes_novas
55
- return unless ops[:v] && novax.count.positive?
56
-
57
- puts("\nsequence num from to accao data valor moeda")
58
- sorax.each { |obj| puts(formata_ledger(obj)) }
59
- end
60
-
61
- # @return [String] texto configuracao ajuste dias das transacoes
62
- def mostra_configuracao_ajuste_dias
63
- return unless novax.count.positive?
64
-
65
- puts("\nstring ajuste dias\n-h=#{sorax.map { |obj| "#{obj[:itx]}:0" }.join(' ')}")
66
- end
67
- end
68
- end