cns 0.3.5 → 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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cns/{apice2.rb → apice.rb} +165 -0
- data/lib/cns/{beaconchain1.rb → beaconchain.rb} +84 -1
- data/lib/cns/bigquery.rb +620 -0
- data/lib/cns/{etherscan1.rb → etherscan.rb} +184 -1
- data/lib/cns/{greymass1.rb → greymass.rb} +62 -1
- data/lib/cns/version.rb +1 -1
- data/lib/cns.rb +5 -12
- metadata +7 -14
- data/lib/cns/apice1.rb +0 -177
- data/lib/cns/beaconchain2.rb +0 -90
- data/lib/cns/bigquery1.rb +0 -124
- data/lib/cns/bigquery2.rb +0 -104
- data/lib/cns/bigquery3.rb +0 -268
- data/lib/cns/bigquery4.rb +0 -154
- data/lib/cns/etherscan2.rb +0 -190
- data/lib/cns/greymass2.rb +0 -68
@@ -7,7 +7,7 @@ module Cns
|
|
7
7
|
# chaves a eliminar da API - resultado deve ser ignirado pois muda a cada pedido API feito
|
8
8
|
DL = %i[cumulativeGasUsed confirmations].freeze
|
9
9
|
|
10
|
-
#
|
10
|
+
# classe para processar transacoes do etherscan
|
11
11
|
class Etherscan
|
12
12
|
# @return [Apibc] API blockchains
|
13
13
|
attr_reader :api
|
@@ -182,5 +182,188 @@ module Cns
|
|
182
182
|
def sorax
|
183
183
|
(novtx + novkx).sort { |ant, prx| ant[:itx] <=> prx[:itx] }
|
184
184
|
end
|
185
|
+
|
186
|
+
# @return [String] texto carteiras & transacoes & ajuste dias
|
187
|
+
def mostra_resumo
|
188
|
+
return unless dados.count.positive?
|
189
|
+
|
190
|
+
puts("\nid address etherscan tn ti tb tk tw bigquery tn ti tb tk tw")
|
191
|
+
dados.each { |obj| puts(formata_carteira(obj)) }
|
192
|
+
mostra_transacao_norml
|
193
|
+
mostra_transacao_inter
|
194
|
+
mostra_transacao_block
|
195
|
+
mostra_transacao_token
|
196
|
+
mostra_transacao_withw
|
197
|
+
mostra_configuracao_ajuste_dias
|
198
|
+
end
|
199
|
+
|
200
|
+
# @param [Hash] hjn dados juntos bigquery & etherscan
|
201
|
+
# @return [String] texto formatado duma carteira
|
202
|
+
def formata_carteira(hjn)
|
203
|
+
format(
|
204
|
+
'%<s1>-6.6s %<s2>-16.16s ',
|
205
|
+
s1: hjn[:id],
|
206
|
+
s2: formata_enderec1(hjn[:ax], 16)
|
207
|
+
) + formata_valores(hjn)
|
208
|
+
end
|
209
|
+
|
210
|
+
# @param (see formata_carteira)
|
211
|
+
# @return [String] texto formatado valores duma carteira
|
212
|
+
def formata_valores(hjn)
|
213
|
+
format(
|
214
|
+
'%<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',
|
215
|
+
v1: hjn[:es],
|
216
|
+
n1: hjn[:et].count,
|
217
|
+
n2: hjn[:ei].count,
|
218
|
+
n3: hjn[:ep].count,
|
219
|
+
n4: hjn[:ek].count,
|
220
|
+
w1: hjn[:ew].count,
|
221
|
+
v2: hjn[:bs],
|
222
|
+
n5: hjn[:bt].count,
|
223
|
+
n6: hjn[:bi].count,
|
224
|
+
n7: hjn[:bp].count,
|
225
|
+
n8: hjn[:bk].count,
|
226
|
+
w2: hjn[:bw].count,
|
227
|
+
ok: ok?(hjn) ? 'OK' : 'NOK'
|
228
|
+
)
|
229
|
+
end
|
230
|
+
|
231
|
+
# @param (see formata_carteira)
|
232
|
+
# @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
|
233
|
+
def ok?(hjn)
|
234
|
+
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
|
235
|
+
end
|
236
|
+
|
237
|
+
# @example ether address inicio..fim
|
238
|
+
# 0x10f3a0cf0b534c..c033cf32e8a03586
|
239
|
+
# @param add (see filtrar_tx)
|
240
|
+
# @param [Integer] max chars a mostrar
|
241
|
+
# @return [String] endereco formatado
|
242
|
+
def formata_enderec1(add, max)
|
243
|
+
return 'erro' if max < 7
|
244
|
+
|
245
|
+
max -= 2
|
246
|
+
ini = Integer(max / 2) + 3
|
247
|
+
inf = max % 2
|
248
|
+
"#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
|
249
|
+
end
|
250
|
+
|
251
|
+
# @example ether address inicio..fim
|
252
|
+
# me-app..4b437776403d
|
253
|
+
# @param add (see filtrar_tx)
|
254
|
+
# @param [Integer] max chars a mostrar
|
255
|
+
# @return [String] endereco formatado
|
256
|
+
def formata_enderec2(add, max)
|
257
|
+
return 'erro' if max < 7
|
258
|
+
|
259
|
+
max -= 2
|
260
|
+
ini = Integer(max / 2)
|
261
|
+
inf = max % 2
|
262
|
+
hid = bqd[:wb].select { |obj| obj[:ax] == add }.first
|
263
|
+
ndd = hid ? hid[:id] + '-' + add : add
|
264
|
+
"#{ndd[0, ini - 3]}..#{ndd[-inf - ini - 3..]}"
|
265
|
+
end
|
266
|
+
|
267
|
+
# @example (see Apibc#norml_es)
|
268
|
+
# @param [Hash] htx transacao normal etherscan
|
269
|
+
# @return [String] texto formatado transacao normal etherscan
|
270
|
+
def formata_transacao_norml(htx)
|
271
|
+
format(
|
272
|
+
'%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>17.6f',
|
273
|
+
bn: htx[:blockNumber],
|
274
|
+
fr: formata_enderec2(htx[:from], 20),
|
275
|
+
to: formata_enderec2(htx[:to], 20),
|
276
|
+
dt: Time.at(Integer(htx[:timeStamp])),
|
277
|
+
vl: (htx[:value].to_d / 10**18).round(10)
|
278
|
+
)
|
279
|
+
end
|
280
|
+
|
281
|
+
# @example (see Apibc#block_es)
|
282
|
+
# @param [Hash] htx transacao block etherscan
|
283
|
+
# @return [String] texto formatado transacao block etherscan
|
284
|
+
def formata_transacao_block(htx)
|
285
|
+
format(
|
286
|
+
'%<bn>9i %<fr>-41.41s %<dt>10.10s %<vl>17.6f',
|
287
|
+
bn: htx[:blockNumber],
|
288
|
+
fr: formata_enderec2(htx[:iax], 41),
|
289
|
+
dt: Time.at(Integer(htx[:timeStamp])),
|
290
|
+
vl: (htx[:blockReward].to_d / 10**18).round(10)
|
291
|
+
)
|
292
|
+
end
|
293
|
+
|
294
|
+
# @example (see Apibc#token_es)
|
295
|
+
# @param [Hash] hkx transacao token etherscan
|
296
|
+
# @return [String] texto formatado transacao token etherscan
|
297
|
+
def formata_transacao_token(hkx)
|
298
|
+
format(
|
299
|
+
'%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>11.3f %<sy>-5.5s',
|
300
|
+
bn: hkx[:blockNumber],
|
301
|
+
fr: formata_enderec2(hkx[:from], 20),
|
302
|
+
to: formata_enderec2(hkx[:to], 20),
|
303
|
+
dt: Time.at(Integer(hkx[:timeStamp])),
|
304
|
+
vl: (hkx[:value].to_d / 10**18).round(10),
|
305
|
+
sy: hkx[:tokenSymbol]
|
306
|
+
)
|
307
|
+
end
|
308
|
+
|
309
|
+
# @example (see Apibc#block_es)
|
310
|
+
# @param [Hash] htx transacao withdrawals etherscan
|
311
|
+
# @return [String] texto formatado transacao withdrawals etherscan
|
312
|
+
def formata_transacao_withw(htx)
|
313
|
+
format(
|
314
|
+
'%<vi>9i %<bn>9i %<dt>10.10s %<vl>10.6f',
|
315
|
+
vi: htx[:validatorIndex],
|
316
|
+
bn: htx[:blockNumber],
|
317
|
+
dt: Time.at(Integer(htx[:timestamp])),
|
318
|
+
vl: (htx[:amount].to_d / 10**9).round(10)
|
319
|
+
)
|
320
|
+
end
|
321
|
+
|
322
|
+
# @return [String] texto transacoes normais
|
323
|
+
def mostra_transacao_norml
|
324
|
+
return unless ops[:v] && novtx.count.positive?
|
325
|
+
|
326
|
+
puts("\ntx normal from to data valor")
|
327
|
+
sortx.each { |obj| puts(formata_transacao_norml(obj)) }
|
328
|
+
end
|
329
|
+
|
330
|
+
# @return [String] texto transacoes internas
|
331
|
+
def mostra_transacao_inter
|
332
|
+
return unless ops[:v] && novix.count.positive?
|
333
|
+
|
334
|
+
puts("\ntx intern from to data valor")
|
335
|
+
sorix.each { |obj| puts(formata_transacao_norml(obj)) }
|
336
|
+
end
|
337
|
+
|
338
|
+
# @return [String] texto transacoes block
|
339
|
+
def mostra_transacao_block
|
340
|
+
return unless ops[:v] && novpx.count.positive?
|
341
|
+
|
342
|
+
puts("\ntx block address data valor")
|
343
|
+
sorpx.each { |obj| puts(formata_transacao_block(obj)) }
|
344
|
+
end
|
345
|
+
|
346
|
+
# @return [String] texto transacoes token
|
347
|
+
def mostra_transacao_token
|
348
|
+
return unless ops[:v] && novkx.count.positive?
|
349
|
+
|
350
|
+
puts("\ntx token from to data valor")
|
351
|
+
sorkx.each { |obj| puts(formata_transacao_token(obj)) }
|
352
|
+
end
|
353
|
+
|
354
|
+
# @return [String] texto transacoes withdrawals
|
355
|
+
def mostra_transacao_withw
|
356
|
+
return unless ops[:v] && novwx.count.positive?
|
357
|
+
|
358
|
+
puts("\nvalidator block data valor")
|
359
|
+
sorwx.each { |obj| puts(formata_transacao_withw(obj)) }
|
360
|
+
end
|
361
|
+
|
362
|
+
# @return [String] texto configuracao ajuste dias das transacoes (normais & token)
|
363
|
+
def mostra_configuracao_ajuste_dias
|
364
|
+
return unless (novtx.count + novkx.count).positive?
|
365
|
+
|
366
|
+
puts("\nstring ajuste dias\n-h=#{sorax.map { |obj| "#{obj[:blockNumber]}:0" }.join(' ')}")
|
367
|
+
end
|
185
368
|
end
|
186
369
|
end
|
@@ -4,7 +4,7 @@ require('bigdecimal/util')
|
|
4
4
|
|
5
5
|
# @author Hernani Rodrigues Vaz
|
6
6
|
module Cns
|
7
|
-
#
|
7
|
+
# classe para processar transacoes do greymass
|
8
8
|
class Greymass
|
9
9
|
# @return [Apibc] API blockchains
|
10
10
|
attr_reader :api
|
@@ -106,5 +106,66 @@ module Cns
|
|
106
106
|
def sorax
|
107
107
|
novax.sort { |ant, prx| prx[:itx] <=> ant[:itx] }
|
108
108
|
end
|
109
|
+
|
110
|
+
# @return [String] texto carteiras & transacoes & ajuste dias
|
111
|
+
def mostra_resumo
|
112
|
+
return unless dados.count.positive?
|
113
|
+
|
114
|
+
puts("\naddress greymass ntx bigquery ntx")
|
115
|
+
dados.each { |obj| puts(formata_carteira(obj)) }
|
116
|
+
mostra_transacoes_novas
|
117
|
+
mostra_configuracao_ajuste_dias
|
118
|
+
end
|
119
|
+
|
120
|
+
# @param [Hash] hjn dados juntos bigquery & greymass
|
121
|
+
# @return [String] texto formatado duma carteira
|
122
|
+
def formata_carteira(hjn)
|
123
|
+
format(
|
124
|
+
'%<s1>-12.12s %<v1>14.4f %<n1>4i %<v2>14.4f %<n2>4i %<ok>-3s',
|
125
|
+
s1: hjn[:ax],
|
126
|
+
v1: hjn[:es],
|
127
|
+
n1: hjn[:et].count,
|
128
|
+
v2: hjn[:bs],
|
129
|
+
n2: hjn[:bt].count,
|
130
|
+
ok: ok?(hjn) ? 'OK' : 'NOK'
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
# @param (see formata_carteira)
|
135
|
+
# @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
|
136
|
+
def ok?(hjn)
|
137
|
+
hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
|
138
|
+
end
|
139
|
+
|
140
|
+
# @example (see Apibc#ledger_gm)
|
141
|
+
# @param [Hash] hlx ledger greymass
|
142
|
+
# @return [String] texto formatado ledger greymass
|
143
|
+
def formata_ledger(hlx)
|
144
|
+
format(
|
145
|
+
'%<bn>12i %<fr>-12.12s %<to>-12.12s %<ac>-10.10s %<dt>10.10s %<vl>12.4f %<sy>-6.6s',
|
146
|
+
ac: (act = hlx[:action_trace][:act])[:name],
|
147
|
+
fr: (adt = act[:data])[:from],
|
148
|
+
vl: (aqt = adt[:quantity].to_s).to_d,
|
149
|
+
bn: hlx[:itx],
|
150
|
+
to: adt[:to],
|
151
|
+
dt: Date.parse(hlx[:block_time]),
|
152
|
+
sy: aqt[/[[:upper:]]+/]
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
# @return [String] texto transacoes
|
157
|
+
def mostra_transacoes_novas
|
158
|
+
return unless ops[:v] && novax.count.positive?
|
159
|
+
|
160
|
+
puts("\nsequence num from to accao data valor moeda")
|
161
|
+
sorax.each { |obj| puts(formata_ledger(obj)) }
|
162
|
+
end
|
163
|
+
|
164
|
+
# @return [String] texto configuracao ajuste dias das transacoes
|
165
|
+
def mostra_configuracao_ajuste_dias
|
166
|
+
return unless novax.count.positive?
|
167
|
+
|
168
|
+
puts("\nstring ajuste dias\n-h=#{sorax.map { |obj| "#{obj[:itx]}:0" }.join(' ')}")
|
169
|
+
end
|
109
170
|
end
|
110
171
|
end
|
data/lib/cns/version.rb
CHANGED
data/lib/cns.rb
CHANGED
@@ -2,18 +2,11 @@
|
|
2
2
|
|
3
3
|
require('thor')
|
4
4
|
require('cns/apibc')
|
5
|
-
require('cns/
|
6
|
-
require('cns/
|
7
|
-
require('cns/
|
8
|
-
require('cns/
|
9
|
-
require('cns/
|
10
|
-
require('cns/bigquery4')
|
11
|
-
require('cns/etherscan1')
|
12
|
-
require('cns/etherscan2')
|
13
|
-
require('cns/greymass1')
|
14
|
-
require('cns/greymass2')
|
15
|
-
require('cns/beaconchain1')
|
16
|
-
require('cns/beaconchain2')
|
5
|
+
require('cns/apice')
|
6
|
+
require('cns/bigquery')
|
7
|
+
require('cns/etherscan')
|
8
|
+
require('cns/greymass')
|
9
|
+
require('cns/beaconchain')
|
17
10
|
require('cns/bitcoinde')
|
18
11
|
require('cns/kraken')
|
19
12
|
require('cns/paymium')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.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: 2023-07-
|
11
|
+
date: 2023-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -203,19 +203,12 @@ files:
|
|
203
203
|
- exe/cns
|
204
204
|
- lib/cns.rb
|
205
205
|
- lib/cns/apibc.rb
|
206
|
-
- lib/cns/
|
207
|
-
- lib/cns/
|
208
|
-
- lib/cns/
|
209
|
-
- lib/cns/beaconchain2.rb
|
210
|
-
- lib/cns/bigquery1.rb
|
211
|
-
- lib/cns/bigquery2.rb
|
212
|
-
- lib/cns/bigquery3.rb
|
213
|
-
- lib/cns/bigquery4.rb
|
206
|
+
- lib/cns/apice.rb
|
207
|
+
- lib/cns/beaconchain.rb
|
208
|
+
- lib/cns/bigquery.rb
|
214
209
|
- lib/cns/bitcoinde.rb
|
215
|
-
- lib/cns/
|
216
|
-
- lib/cns/
|
217
|
-
- lib/cns/greymass1.rb
|
218
|
-
- lib/cns/greymass2.rb
|
210
|
+
- lib/cns/etherscan.rb
|
211
|
+
- lib/cns/greymass.rb
|
219
212
|
- lib/cns/kraken.rb
|
220
213
|
- lib/cns/paymium.rb
|
221
214
|
- lib/cns/therock.rb
|
data/lib/cns/apice1.rb
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require('openssl')
|
4
|
-
require('base64')
|
5
|
-
require('curb')
|
6
|
-
require('json')
|
7
|
-
|
8
|
-
# @author Hernani Rodrigues Vaz
|
9
|
-
module Cns
|
10
|
-
DC = %w[LTC NMC PPC DOGE XRP Linden USD CAD GBP ZEC BCH EURN NOKU FDZ GUSD SEED USDC].freeze
|
11
|
-
|
12
|
-
# (see Apice)
|
13
|
-
class Apice
|
14
|
-
# @example account_de
|
15
|
-
# {
|
16
|
-
# data: {
|
17
|
-
# balances: {
|
18
|
-
# btc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
19
|
-
# bch: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
20
|
-
# btg: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
21
|
-
# eth: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
22
|
-
# bsv: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
23
|
-
# ltc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' }
|
24
|
-
# },
|
25
|
-
# encrypted_information: { uid: '0y...', bic_short: '0y...', bic_full: '0y...' }
|
26
|
-
# },
|
27
|
-
# errors: [],
|
28
|
-
# credits: 23
|
29
|
-
# }
|
30
|
-
# @param [String] uri Uniform Resource Identifier do pedido HTTP
|
31
|
-
# @return [Hash] saldos no bitcoinde
|
32
|
-
def account_de(uri = 'https://api.bitcoin.de/v4/account')
|
33
|
-
JSON.parse(
|
34
|
-
Curl.get(uri) { |obj| obj.headers = hde(uri) }.body,
|
35
|
-
symbolize_names: true
|
36
|
-
)[:data][:balances]
|
37
|
-
rescue StandardError
|
38
|
-
{}
|
39
|
-
end
|
40
|
-
|
41
|
-
# @example account_fr
|
42
|
-
# {
|
43
|
-
# name: '...',
|
44
|
-
# email: '...',
|
45
|
-
# locale: 'en',
|
46
|
-
# channel_id: '...',
|
47
|
-
# meta_state: 'approved',
|
48
|
-
# balance_eur: '0.0',
|
49
|
-
# locked_eur: '0.0',
|
50
|
-
# balance_btc: '0.0',
|
51
|
-
# locked_btc: '0.0',
|
52
|
-
# balance_lbtc: '0.0',
|
53
|
-
# locked_lbtc: '0.0'
|
54
|
-
# }
|
55
|
-
# @param (see account_de)
|
56
|
-
# @return [Hash] saldos no paymium
|
57
|
-
def account_fr(uri = 'https://paymium.com/api/v1/user')
|
58
|
-
JSON.parse(
|
59
|
-
Curl.get(uri) { |obj| obj.headers = hfr(uri) }.body,
|
60
|
-
symbolize_names: true
|
61
|
-
)
|
62
|
-
rescue StandardError
|
63
|
-
{}
|
64
|
-
end
|
65
|
-
|
66
|
-
# @example account_mt
|
67
|
-
# {
|
68
|
-
# balances: [
|
69
|
-
# { currency: 'BTC', balance: 0.0, trading_balance: 0.0 },
|
70
|
-
# { currency: 'ETH', balance: 0.0, trading_balance: 0.0 },
|
71
|
-
# { currency: 'EUR', balance: 0.0, trading_balance: 0.0 },
|
72
|
-
# { currency: 'DAI', balance: 0.0, trading_balance: 0.0 },
|
73
|
-
# ]
|
74
|
-
# }
|
75
|
-
# @param (see account_de)
|
76
|
-
# @return [Array<Hash>] lista saldos no therock
|
77
|
-
def account_mt(uri = 'https://api.therocktrading.com/v1/balances')
|
78
|
-
JSON.parse(
|
79
|
-
Curl.get(uri) { |obj| obj.headers = hmt(uri) }.body,
|
80
|
-
symbolize_names: true
|
81
|
-
)[:balances]
|
82
|
-
.delete_if { |del| DC.include?(del[:currency]) }
|
83
|
-
.sort { |oba, obb| oba[:currency] <=> obb[:currency] }
|
84
|
-
rescue StandardError
|
85
|
-
[]
|
86
|
-
end
|
87
|
-
|
88
|
-
# @example account_us
|
89
|
-
# {
|
90
|
-
# error: [],
|
91
|
-
# result: {
|
92
|
-
# ZEUR: '0.0038',
|
93
|
-
# XXBT: '0.0000000000',
|
94
|
-
# XETH: '1.0000000000',
|
95
|
-
# XETC: '0.0000000000',
|
96
|
-
# EOS: '0.0000001700',
|
97
|
-
# BCH: '0.0000000000'
|
98
|
-
# }
|
99
|
-
# }
|
100
|
-
# @param [String] urb Uniform Resource Base do pedido HTTP
|
101
|
-
# @param uri (see account_de)
|
102
|
-
# @param non (see hde)
|
103
|
-
# @return [Hash] saldos no kraken
|
104
|
-
def account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc)
|
105
|
-
JSON.parse(
|
106
|
-
Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body,
|
107
|
-
symbolize_names: true
|
108
|
-
)[:result]
|
109
|
-
rescue StandardError
|
110
|
-
{}
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
# @return [Integer] continually-increasing unsigned integer nonce from the current Unix Time
|
116
|
-
def nnc
|
117
|
-
Integer(Float(Time.now) * 1e6)
|
118
|
-
end
|
119
|
-
|
120
|
-
# @param [String] qde query a incluir no pedido HTTP
|
121
|
-
# @param [Integer] non continually-increasing unsigned integer
|
122
|
-
# @return [Hash] headers necessarios para pedido HTTP da exchange bitcoinde
|
123
|
-
def hde(qde, non = nnc)
|
124
|
-
key = ENV['BITCOINDE_API_KEY']
|
125
|
-
{
|
126
|
-
'X-API-KEY': key,
|
127
|
-
'X-API-NONCE': non,
|
128
|
-
'X-API-SIGNATURE': OpenSSL::HMAC.hexdigest(
|
129
|
-
'sha256',
|
130
|
-
ENV['BITCOINDE_API_SECRET'],
|
131
|
-
['GET', qde, key, non, Digest::MD5.hexdigest('')].join('#')
|
132
|
-
)
|
133
|
-
}
|
134
|
-
end
|
135
|
-
|
136
|
-
# @param [String] qfr query a incluir no pedido HTTP
|
137
|
-
# @param non (see hde)
|
138
|
-
# @return [Hash] headers necessarios para pedido HTTP da exchange paymium
|
139
|
-
def hfr(qfr, non = nnc)
|
140
|
-
{
|
141
|
-
content_type: 'application/json',
|
142
|
-
'Api-Key': ENV['PAYMIUM_API_KEY'],
|
143
|
-
'Api-Nonce': non,
|
144
|
-
'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non, qfr].join)
|
145
|
-
}
|
146
|
-
end
|
147
|
-
|
148
|
-
# @param [String] qmt query a incluir no pedido HTTP
|
149
|
-
# @param non (see hde)
|
150
|
-
# @return [Hash] headers necessarios para pedido HTTP da exchange therock
|
151
|
-
def hmt(qmt, non = nnc)
|
152
|
-
{
|
153
|
-
content_type: 'application/json',
|
154
|
-
'X-TRT-KEY': ENV['THEROCK_API_KEY'],
|
155
|
-
'X-TRT-NONCE': non,
|
156
|
-
'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non, qmt].join)
|
157
|
-
}
|
158
|
-
end
|
159
|
-
|
160
|
-
# @param [String] qus query a incluir no pedido HTTP
|
161
|
-
# @param [Hash] ops opcoes trabalho
|
162
|
-
# @option ops [Hash] :nonce continually-increasing unsigned integer
|
163
|
-
# @return [Hash] headers necessarios para pedido HTTP da exchange kraken
|
164
|
-
def hus(qus, ops)
|
165
|
-
{
|
166
|
-
'api-key': ENV['KRAKEN_API_KEY'],
|
167
|
-
'api-sign': Base64.strict_encode64(
|
168
|
-
OpenSSL::HMAC.digest(
|
169
|
-
'sha512',
|
170
|
-
Base64.decode64(ENV['KRAKEN_API_SECRET']),
|
171
|
-
['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
|
172
|
-
)
|
173
|
-
)
|
174
|
-
}
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
data/lib/cns/beaconchain2.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @author Hernani Rodrigues Vaz
|
4
|
-
module Cns
|
5
|
-
# classe para processar historicos da beaconchain
|
6
|
-
class Beaconchain
|
7
|
-
# @return [String] texto validadores & saldos historicos
|
8
|
-
def mostra_resumo
|
9
|
-
return unless dados.count.positive?
|
10
|
-
|
11
|
-
puts("\nindex address beaconchain blh bigquery blh")
|
12
|
-
dados.each { |obj| puts(formata_validador(obj)) }
|
13
|
-
mostra_saldos
|
14
|
-
end
|
15
|
-
|
16
|
-
# @param [Hash] hjn dados juntos bigquery & beaconchain
|
17
|
-
# @return [String] texto formatado dum validador
|
18
|
-
def formata_validador(hjn)
|
19
|
-
format('%<s1>-5.5s %<s2>-34.34s ', s1: hjn[:id], s2: formata_endereco(hjn[:ax], 34)) + formata_valores(hjn)
|
20
|
-
end
|
21
|
-
|
22
|
-
# @param (see formata_validador)
|
23
|
-
# @return [String] texto formatado valores dum validador
|
24
|
-
def formata_valores(hjn)
|
25
|
-
format(
|
26
|
-
'%<v1>11.6f %<n1>3i %<v2>12.6f %<n2>6i %<ok>-3s',
|
27
|
-
v1: hjn[:es],
|
28
|
-
n1: hjn[:eb].count,
|
29
|
-
v2: hjn[:bs],
|
30
|
-
n2: hjn[:bb].count,
|
31
|
-
ok: ok?(hjn) ? 'OK' : 'NOK'
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
# @param (see formata_validador)
|
36
|
-
# @return [Boolean] validador tem historicos novos(sim=NOK, nao=OK)?
|
37
|
-
def ok?(hjn)
|
38
|
-
hjn[:bs] == hjn[:es]
|
39
|
-
end
|
40
|
-
|
41
|
-
# @example pubkey inicio..fim
|
42
|
-
# 0x10f3a0cf0b534c..c033cf32e8a03586
|
43
|
-
# @param [String] add chave publica validador
|
44
|
-
# @param [Integer] max chars a mostrar
|
45
|
-
# @return [String] pubkey formatada
|
46
|
-
def formata_endereco(add, max)
|
47
|
-
return 'erro' if max < 7
|
48
|
-
|
49
|
-
max -= 2
|
50
|
-
ini = Integer(max / 2)
|
51
|
-
inf = max % 2
|
52
|
-
"#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
|
53
|
-
end
|
54
|
-
|
55
|
-
# @example
|
56
|
-
# {
|
57
|
-
# balance: 32_489_497_108,
|
58
|
-
# effectivebalance: 32_000_000_000,
|
59
|
-
# epoch: 8296,
|
60
|
-
# validatorindex: 11_766,
|
61
|
-
# week: 5
|
62
|
-
# }
|
63
|
-
# @param [Hash] hbh historico beaconchain
|
64
|
-
# @return [String] texto formatado historico beaconchain
|
65
|
-
def formata_saldos(hbh)
|
66
|
-
idx = hbh[:validatorindex]
|
67
|
-
epc = hbh[:epoch]
|
68
|
-
format(
|
69
|
-
'%<vi>5i %<vl>17.6f %<ep>6i %<id>9i',
|
70
|
-
vi: idx,
|
71
|
-
vl: (hbh[:balance].to_d / (10**9)).round(10),
|
72
|
-
ep: epc,
|
73
|
-
id: itx(epc, idx)
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
# @return [String] texto historico saldos
|
78
|
-
def mostra_saldos
|
79
|
-
return unless ops[:v] && nov.count.positive?
|
80
|
-
|
81
|
-
puts("\nindex saldo epoch itx")
|
82
|
-
sorbx.each { |obj| puts(formata_saldos(obj)) }
|
83
|
-
end
|
84
|
-
|
85
|
-
# @return [Array<Hash>] lista ordenada historico saldos
|
86
|
-
def sorbx
|
87
|
-
nov.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|