cns 0.9.7 → 0.9.8
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 +4 -1
- data/cns.gemspec +1 -0
- data/lib/cns/apibc.rb +8 -3
- data/lib/cns/apice.rb +2 -2
- data/lib/cns/etherscan.rb +94 -61
- data/lib/cns/greymass.rb +35 -24
- data/lib/cns/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f44706093bb37569dad944e52da3becb0d1bb8ab34e48c9dd30c2f2cd6599f3c
|
4
|
+
data.tar.gz: 1cb9e471623d4abbf526a77278e5ff27614e52093d3a79a56229a9c9bf39783f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99c1e87bc81a61b9c8e572807b133daf02e54b42bbdea7b2d1997711fc4a98984eae1320ebc6764ce15cd586dee29f88716fa49bc07bb91f136f9a4dd4bf3d55
|
7
|
+
data.tar.gz: 0ed7c0a9c0b40fcb5d18cf7271a5208ddd62e2e0643c0ae2134d74538fb6993c6756ba962e7de754751feae71873e2cb22644c74d5e6b999f78bda6336714e94
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cns (0.9.
|
4
|
+
cns (0.9.8)
|
5
5
|
curb
|
6
6
|
faraday
|
7
|
+
faraday-retry
|
7
8
|
google-cloud-bigquery
|
8
9
|
thor
|
9
10
|
|
@@ -56,6 +57,8 @@ GEM
|
|
56
57
|
logger
|
57
58
|
faraday-net_http (3.4.0)
|
58
59
|
net-http (>= 0.5.0)
|
60
|
+
faraday-retry (2.2.1)
|
61
|
+
faraday (~> 2.0)
|
59
62
|
google-apis-bigquery_v2 (0.84.0)
|
60
63
|
google-apis-core (>= 0.15.0, < 2.a)
|
61
64
|
google-apis-core (0.16.0)
|
data/cns.gemspec
CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
|
37
37
|
spec.add_dependency('curb')
|
38
38
|
spec.add_dependency('faraday')
|
39
|
+
spec.add_dependency('faraday-retry')
|
39
40
|
spec.add_dependency('google-cloud-bigquery')
|
40
41
|
spec.add_dependency('thor')
|
41
42
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
data/lib/cns/apibc.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require('faraday')
|
4
|
+
require 'faraday/retry'
|
4
5
|
require('json')
|
5
6
|
|
6
7
|
# @author Hernani Rodrigues Vaz
|
@@ -22,8 +23,11 @@ module Cns
|
|
22
23
|
def account_es(addresses)
|
23
24
|
return [] if addresses.empty?
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
# Batch addresses into groups of 20 (Etherscan limit) and fetch balances
|
27
|
+
addresses.each_slice(20).flat_map do |b|
|
28
|
+
res = es_req('balancemulti', b.join(','), 1, tag: 'latest')
|
29
|
+
res[:status] == '1' ? res[:result] || [] : []
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
# Get normal transactions for ETH address
|
@@ -149,7 +153,7 @@ module Cns
|
|
149
153
|
{}
|
150
154
|
end
|
151
155
|
|
152
|
-
# Create a Faraday connection with JSON configuration
|
156
|
+
# Create a Faraday connection with JSON configuration and retry logic
|
153
157
|
# @param [String] url Base URL for the API
|
154
158
|
# @return [Faraday::Connection] Configured Faraday connection
|
155
159
|
def connection(url)
|
@@ -158,6 +162,7 @@ module Cns
|
|
158
162
|
c.headers = {accept: 'application/json', user_agent: 'blockchain-api-client'}
|
159
163
|
c.options.timeout = 30
|
160
164
|
c.options.open_timeout = 10
|
165
|
+
c.use(Faraday::Retry::Middleware, max: 3, interval: 1)
|
161
166
|
c.adapter(Faraday.default_adapter)
|
162
167
|
end
|
163
168
|
end
|
data/lib/cns/apice.rb
CHANGED
@@ -203,7 +203,7 @@ module Cns
|
|
203
203
|
mac = OpenSSL::HMAC.hexdigest('sha256', @desc, md5)
|
204
204
|
{'X-API-KEY' => @deky, 'X-API-NONCE' => non.to_s, 'X-API-SIGNATURE' => mac}
|
205
205
|
rescue OpenSSL::HMACError => e
|
206
|
-
raise("HMAC generation failed: #{e.message}")
|
206
|
+
raise("HMAC bitcoinde generation failed: #{e.message}")
|
207
207
|
end
|
208
208
|
|
209
209
|
# Generate headers for Kraken HTTP requests
|
@@ -216,7 +216,7 @@ module Cns
|
|
216
216
|
mac = OpenSSL::HMAC.digest('sha512', Base64.decode64(@ussc), sha)
|
217
217
|
{'api-key' => @usky, 'api-sign' => Base64.strict_encode64(mac)}
|
218
218
|
rescue OpenSSL::HMACError => e
|
219
|
-
raise("HMAC generation failed: #{e.message}")
|
219
|
+
raise("HMAC kraken generation failed: #{e.message}")
|
220
220
|
end
|
221
221
|
end
|
222
222
|
end
|
data/lib/cns/etherscan.rb
CHANGED
@@ -101,42 +101,45 @@ module Cns
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
# Format simple wallet summary
|
104
105
|
# @param [Hash] hjn dados juntos bigquery & etherscan
|
105
106
|
# @return [String] texto formatado duma carteira
|
106
107
|
def focs(hjn)
|
107
108
|
format(
|
108
|
-
'%<
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
'%<id>-6.6s %<address>-42.42s %<etherscan_value>13.6f %<bigquery_value>13.6f %<status>-3s',
|
110
|
+
id: hjn[:id],
|
111
|
+
address: hjn[:ax],
|
112
|
+
etherscan_value: hjn[:es],
|
113
|
+
bigquery_value: hjn[:bs],
|
114
|
+
status: ok?(hjn) ? 'OK' : 'NOK'
|
114
115
|
)
|
115
116
|
end
|
116
117
|
|
118
|
+
# Format detailed wallet summary with counters
|
117
119
|
# @param (see focs)
|
118
120
|
# @return [String] texto formatado duma carteira (com contadores)
|
119
121
|
def foct(hjn)
|
120
122
|
format(
|
121
|
-
'%<
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
123
|
+
'%<id>-6.6s %<ax>-10.10s %<es>11.4f %<et>3i %<ei>2i %<ep>2i %<ek>2i %<ew>4i %<bs>11.4f %<bt>3i %<bi>2i %<bp>2i %<bk>2i %<bw>4i %<ok>-3s',
|
124
|
+
id: hjn[:id],
|
125
|
+
ax: foe1(hjn[:ax], 10),
|
126
|
+
es: hjn[:es],
|
127
|
+
et: hjn[:et].count,
|
128
|
+
ei: hjn[:ei].count,
|
129
|
+
ep: hjn[:ep].count,
|
130
|
+
ek: hjn[:ek].count,
|
131
|
+
ew: hjn[:ew].count,
|
132
|
+
bs: hjn[:bs],
|
133
|
+
bt: hjn[:bt].count,
|
134
|
+
bi: hjn[:bi].count,
|
135
|
+
bp: hjn[:bp].count,
|
136
|
+
bk: hjn[:bk].count,
|
137
|
+
bw: hjn[:bw].count,
|
136
138
|
ok: ok?(hjn) ? 'OK' : 'NOK'
|
137
139
|
)
|
138
140
|
end
|
139
141
|
|
142
|
+
# Check if wallet has new transactions
|
140
143
|
# @param (see focs)
|
141
144
|
# @return [Boolean] check saldo & contadores ipwtk
|
142
145
|
def ok?(hjn)
|
@@ -185,50 +188,68 @@ module Cns
|
|
185
188
|
"#{ndd[0, ini]}..#{ndd[-inf - ini..]}"
|
186
189
|
end
|
187
190
|
|
188
|
-
#
|
191
|
+
# Format normal(t)/(i)nternal transaction
|
192
|
+
# @param [Hash] htx transacao etherscan
|
189
193
|
# @return [String] texto formatado
|
190
194
|
def foti(htx)
|
191
195
|
format(
|
192
|
-
'%<
|
193
|
-
|
194
|
-
|
196
|
+
'%<hash>-29.29s %<from>-15.15s %<to>-15.15s %<date>10.10s %<value>7.3f',
|
197
|
+
hash: foe1(htx[:hash], 29),
|
198
|
+
from: foe2(htx[:from], 15),
|
195
199
|
to: foe2(htx[:to], 15),
|
196
|
-
|
197
|
-
|
200
|
+
date: htx[:timeStamp].strftime('%F'),
|
201
|
+
value: htx[:value] / (10**18)
|
198
202
|
)
|
199
203
|
end
|
200
204
|
|
201
|
-
#
|
205
|
+
# Format to(k)en transaction
|
206
|
+
# @param [Hash] hkx transacao etherscan
|
202
207
|
# @return [String] texto formatado
|
203
208
|
def fok(hkx)
|
204
209
|
format(
|
205
|
-
'%<
|
206
|
-
|
207
|
-
|
210
|
+
'%<hash>-20.20s %<from>-15.15s %<to>-15.15s %<date>10.10s %<value>10.3f %<symbol>-5.5s',
|
211
|
+
hash: foe1(hkx[:hash], 20),
|
212
|
+
from: foe2(hkx[:from], 15),
|
208
213
|
to: foe2(hkx[:to], 15),
|
209
|
-
|
210
|
-
|
211
|
-
|
214
|
+
date: hkx[:timeStamp].strftime('%F'),
|
215
|
+
value: hkx[:value] / (10**18),
|
216
|
+
symbol: hkx[:tokenSymbol]
|
212
217
|
)
|
213
218
|
end
|
214
219
|
|
215
|
-
#
|
220
|
+
# Format (p)roduced block transaction
|
221
|
+
# @param [Hash] hpx transacao etherscan
|
216
222
|
# @return [String] texto formatado
|
217
223
|
def fop(hpx)
|
218
|
-
format(
|
224
|
+
format(
|
225
|
+
'%<block_number>9i %<address>-41.41s %<date>10.10s %<reward>17.6f',
|
226
|
+
block_number: hpx[:blockNumber],
|
227
|
+
address: foe2(hpx[:iax], 41),
|
228
|
+
date: hpx[:timeStamp].strftime('%F'),
|
229
|
+
reward: hpx[:blockReward] / (10**18)
|
230
|
+
)
|
219
231
|
end
|
220
232
|
|
221
|
-
#
|
222
|
-
# @
|
233
|
+
# Format (w)ithdrawal transaction
|
234
|
+
# @param [Hash] hwx transacao etherscan
|
235
|
+
# @return [String] texto formatado
|
223
236
|
def fow(hwx)
|
224
|
-
format(
|
237
|
+
format(
|
238
|
+
'%<index>10i %<validator>9i %<date>10.10s %<amount>10.6f',
|
239
|
+
index: hwx[:withdrawalIndex],
|
240
|
+
validator: hwx[:validatorIndex],
|
241
|
+
date: hwx[:timeStamp].strftime('%F'),
|
242
|
+
amount: hwx[:amount] / (10**9)
|
243
|
+
)
|
225
244
|
end
|
226
245
|
|
246
|
+
# Determine if all transactions should be shown
|
227
247
|
# @return [Boolean] mostra todas/novas transacoes
|
228
248
|
def show_all?
|
229
249
|
ops[:t] || false
|
230
250
|
end
|
231
251
|
|
252
|
+
# Process timestamp
|
232
253
|
# @param [Hash] htx transacao
|
233
254
|
# @return [Hash] transaccao filtrada
|
234
255
|
def pess(htx)
|
@@ -238,27 +259,31 @@ module Cns
|
|
238
259
|
htx.merge(srx: 0, timeStamp: Time.at(0))
|
239
260
|
end
|
240
261
|
|
262
|
+
# Filter normal(t)/(i)nternal/to(k)en transactions
|
241
263
|
# @param add (see foe1)
|
242
|
-
# @param [Array<Hash>] ary lista transacoes
|
264
|
+
# @param [Array<Hash>] ary lista transacoes
|
243
265
|
# @return [Array<Hash>] lista transacoes filtrada
|
244
266
|
def ftik(add, ary)
|
245
267
|
ary.map { |o| pess(o).merge(itx: o[:hash].to_s, iax: add, value: o[:value].to_d) }
|
246
268
|
end
|
247
269
|
|
270
|
+
# Filter (p)roduced blocks transactions
|
248
271
|
# @param add (see foe1)
|
249
|
-
# @param [Array<Hash>] ary lista transacoes
|
272
|
+
# @param [Array<Hash>] ary lista transacoes
|
250
273
|
# @return [Array<Hash>] lista transacoes filtrada
|
251
274
|
def fppp(add, ary)
|
252
275
|
ary.map { |o| o.merge(itx: o[:blockNumber].to_i, iax: add, blockReward: o[:blockReward].to_d, timeStamp: Time.at(o[:timeStamp].to_i)) }
|
253
276
|
end
|
254
277
|
|
278
|
+
# Filter (w)ithdrawals transactions
|
255
279
|
# @param add (see foe1)
|
256
|
-
# @param [Array<Hash>] ary lista transacoes
|
280
|
+
# @param [Array<Hash>] ary lista transacoes
|
257
281
|
# @return [Array<Hash>] lista transacoes filtrada
|
258
282
|
def fwww(add, ary)
|
259
283
|
ary.map { |o| o.merge(itx: o[:withdrawalIndex].to_i, iax: add, amount: o[:amount].to_d, timeStamp: Time.at(o[:timestamp].to_i)) }
|
260
284
|
end
|
261
285
|
|
286
|
+
# Fetch Etherscan data for an account
|
262
287
|
# @param [Hash] aes account etherscan
|
263
288
|
# @return [Hash] dados etherscan - address, saldo & transacoes
|
264
289
|
def bses(aes)
|
@@ -274,6 +299,7 @@ module Cns
|
|
274
299
|
}
|
275
300
|
end
|
276
301
|
|
302
|
+
# Combine BigQuery and Etherscan data
|
277
303
|
# @param [Hash] wbq wallet bigquery
|
278
304
|
# @param [Hash] hes dados etherscan - address, saldo & transacoes
|
279
305
|
# @return [Hash] dados juntos bigquery & etherscan
|
@@ -298,7 +324,7 @@ module Cns
|
|
298
324
|
end
|
299
325
|
|
300
326
|
# Lazy Etherscan API Initialization
|
301
|
-
# @return [
|
327
|
+
# @return [Apibc] API instance
|
302
328
|
def api
|
303
329
|
@api ||= Apibc.new
|
304
330
|
end
|
@@ -308,14 +334,16 @@ module Cns
|
|
308
334
|
@lax ||= bqd[:wb].map { |o| o[:ax] }
|
309
335
|
end
|
310
336
|
|
311
|
-
#
|
337
|
+
# Fetch all Etherscan data
|
338
|
+
# @return [Hash] saldos & transacoes, indexed by address
|
312
339
|
def esd
|
313
|
-
@esd ||= api.account_es(lax).map { |o| bses(o) }
|
340
|
+
@esd ||= api.account_es(lax).map { |o| bses(o) }.each_with_object({}) { |h, a| a[h[:ax]] = h }
|
314
341
|
end
|
315
342
|
|
343
|
+
# Fetch combined data
|
316
344
|
# @return [Array<Hash>] todos os dados juntos bigquery & etherscan
|
317
345
|
def dados
|
318
|
-
@dados ||= bqd[:wb].map { |b| bqes(b, esd
|
346
|
+
@dados ||= bqd[:wb].map { |b| bqes(b, esd[b[:ax]]) }
|
319
347
|
end
|
320
348
|
|
321
349
|
# @return [Array<Integer>] indices transacoes bigquery
|
@@ -345,52 +373,57 @@ module Cns
|
|
345
373
|
|
346
374
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
347
375
|
def idt
|
348
|
-
@idt ||= esd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
376
|
+
@idt ||= esd.values.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
349
377
|
end
|
350
378
|
|
351
379
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
352
380
|
def idi
|
353
|
-
@idi ||= esd.map { |o| o[:ix].map { |i| i[:itx] } }.flatten - bqidi
|
381
|
+
@idi ||= esd.values.map { |o| o[:ix].map { |i| i[:itx] } }.flatten - bqidi
|
354
382
|
end
|
355
383
|
|
356
384
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
357
385
|
def idp
|
358
|
-
@idp ||= esd.map { |o| o[:px].map { |i| i[:itx] } }.flatten - bqidp
|
386
|
+
@idp ||= esd.values.map { |o| o[:px].map { |i| i[:itx] } }.flatten - bqidp
|
359
387
|
end
|
360
388
|
|
361
389
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
362
390
|
def idw
|
363
|
-
@idw ||= esd.map { |o| o[:wx].map { |i| i[:itx] } }.flatten - bqidw
|
391
|
+
@idw ||= esd.values.map { |o| o[:wx].map { |i| i[:itx] } }.flatten - bqidw
|
364
392
|
end
|
365
393
|
|
366
394
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
367
395
|
def idk
|
368
|
-
@idk ||= esd.map { |o| o[:kx].map { |i| i[:itx] } }.flatten - bqidk
|
396
|
+
@idk ||= esd.values.map { |o| o[:kx].map { |i| i[:itx] } }.flatten - bqidk
|
369
397
|
end
|
370
398
|
|
371
|
-
#
|
399
|
+
# Get new normal transactions
|
400
|
+
# @return [Array<Hash>] List of new transactions
|
372
401
|
def novnetht
|
373
|
-
@novnetht ||= esd.map { |o| o[:tx].select { |t| idt.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
402
|
+
@novnetht ||= esd.values.map { |o| o[:tx].select { |t| idt.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
374
403
|
end
|
375
404
|
|
376
|
-
#
|
405
|
+
# Get new internal transactions
|
406
|
+
# @return [Array<Hash>] List of new transactions
|
377
407
|
def novnethi
|
378
|
-
@novnethi ||= esd.map { |o| o[:ix].select { |t| idi.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
408
|
+
@novnethi ||= esd.values.map { |o| o[:ix].select { |t| idi.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
379
409
|
end
|
380
410
|
|
381
|
-
#
|
411
|
+
# Get new produced block transactions
|
412
|
+
# @return [Array<Hash>] List of new transactions
|
382
413
|
def novnethp
|
383
|
-
@novnethp ||= esd.map { |o| o[:px].select { |t| idp.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
414
|
+
@novnethp ||= esd.values.map { |o| o[:px].select { |t| idp.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
384
415
|
end
|
385
416
|
|
386
|
-
#
|
417
|
+
# Get new withdrawal transactions
|
418
|
+
# @return [Array<Hash>] List of new transactions
|
387
419
|
def novnethw
|
388
|
-
@novnethw ||= esd.map { |o| o[:wx].select { |t| idw.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
420
|
+
@novnethw ||= esd.values.map { |o| o[:wx].select { |t| idw.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
389
421
|
end
|
390
422
|
|
391
|
-
#
|
423
|
+
# Get new token transactions
|
424
|
+
# @return [Array<Hash>] List of new transactions
|
392
425
|
def novnethk
|
393
|
-
@novnethk ||= esd.map { |o| o[:kx].select { |t| idk.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
426
|
+
@novnethk ||= esd.values.map { |o| o[:kx].select { |t| idk.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
394
427
|
end
|
395
428
|
end
|
396
429
|
end
|
data/lib/cns/greymass.rb
CHANGED
@@ -23,12 +23,12 @@ module Cns
|
|
23
23
|
@ops = pop.transform_keys(&:to_sym)
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
26
|
+
# Display summary of wallets, transactions, and adjustment days configuration
|
27
27
|
def mresumo
|
28
28
|
return unless dados.any?
|
29
29
|
|
30
30
|
puts("\naddress greymass ntx bigquery ntx")
|
31
|
-
dados.each { |
|
31
|
+
dados.each { |e| puts(foct(e)) }
|
32
32
|
mtransacoes_novas
|
33
33
|
mconfiguracao_ajuste_dias
|
34
34
|
end
|
@@ -50,46 +50,51 @@ module Cns
|
|
50
50
|
puts("\nstring ajuste dias\n-h=#{novneost.sort_by { |s| -s[TT[:sork]] }.map { |t| "#{t[TT[:adjk]]}:0" }.join(' ')}")
|
51
51
|
end
|
52
52
|
|
53
|
+
# Format wallet summary text
|
53
54
|
# @param [Hash] hjn dados juntos bigquery & greymass
|
54
55
|
# @return [String] texto formatado duma carteira
|
55
56
|
def foct(hjn)
|
56
57
|
format(
|
57
|
-
'%<
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
'%<address>-12.12s %<greymass_value>14.4f %<greymass_tx_count>4i %<bigquery_value>14.4f %<bigquery_tx_count>4i %<status>-3s',
|
59
|
+
address: hjn[:ax],
|
60
|
+
greymass_value: hjn[:es],
|
61
|
+
greymass_tx_count: hjn[:et].count,
|
62
|
+
bigquery_value: hjn[:bs],
|
63
|
+
bigquery_tx_count: hjn[:bt].count,
|
64
|
+
status: ok?(hjn) ? 'OK' : 'NOK'
|
64
65
|
)
|
65
66
|
end
|
66
67
|
|
68
|
+
# Check if wallet has new transactions
|
67
69
|
# @param (see foct)
|
68
70
|
# @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
|
69
71
|
def ok?(hjn)
|
70
72
|
hjn[:bs].round(6) == hjn[:es].round(6) && hjn[:bt].count == hjn[:et].count
|
71
73
|
end
|
72
74
|
|
75
|
+
# Format transaction text
|
73
76
|
# @param [Hash] hlx ledger greymass
|
74
77
|
# @return [String] texto formatado
|
75
78
|
def fol(hlx)
|
76
79
|
format(
|
77
|
-
'%<
|
78
|
-
|
79
|
-
|
80
|
-
vl: hlx[:quantity],
|
81
|
-
bn: hlx[:itx],
|
80
|
+
'%<sequence>12i %<from>-12.12s %<to>-12.12s %<action>-10.10s %<date>10.10s %<value>12.4f %<symbol>-6.6s',
|
81
|
+
sequence: hlx[:itx],
|
82
|
+
from: hlx[:from],
|
82
83
|
to: hlx[:to],
|
83
|
-
|
84
|
-
|
84
|
+
action: hlx[:name],
|
85
|
+
date: hlx[:block_time].strftime('%F'),
|
86
|
+
value: hlx[:quantity],
|
87
|
+
symbol: hlx[:moe]
|
85
88
|
)
|
86
89
|
end
|
87
90
|
|
91
|
+
# Determine if all transactions should be shown
|
88
92
|
# @return [Boolean] mostra todas/novas transacoes
|
89
93
|
def show_all?
|
90
94
|
ops[:t] || false
|
91
95
|
end
|
92
96
|
|
97
|
+
# Fetch EOS account resources
|
93
98
|
# @param [String] add EOS account name
|
94
99
|
# @return [Array<BigDecimal>] lista recursos - liquido, net, spu
|
95
100
|
def peosa(add)
|
@@ -98,6 +103,7 @@ module Cns
|
|
98
103
|
[hac[:core_liquid_balance]&.to_d || 0.to_d, htr[:net_weight]&.to_d || 0.to_d, htr[:cpu_weight]&.to_d || 0.to_d]
|
99
104
|
end
|
100
105
|
|
106
|
+
# Process and filter EOS transactions
|
101
107
|
# @param add (see peosa)
|
102
108
|
# @param [Array<Hash>] ary lista transacoes
|
103
109
|
# @return [Array<Hash>] lista transacoes filtrada
|
@@ -121,6 +127,7 @@ module Cns
|
|
121
127
|
end
|
122
128
|
end
|
123
129
|
|
130
|
+
# Fetch Greymass data for a wallet
|
124
131
|
# @param [Hash] wbq wallet bigquery
|
125
132
|
# @return [Hash] dados greymass - address, saldo & transacoes
|
126
133
|
def bsgm(wbq)
|
@@ -128,6 +135,7 @@ module Cns
|
|
128
135
|
{ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq))}
|
129
136
|
end
|
130
137
|
|
138
|
+
# Combine BigQuery and Greymass data
|
131
139
|
# @param wbq (see bsgm)
|
132
140
|
# @param [Hash] hgm dados greymass - address, saldo & transacoes
|
133
141
|
# @return [Hash] dados juntos bigquery & greymass
|
@@ -144,19 +152,21 @@ module Cns
|
|
144
152
|
end
|
145
153
|
|
146
154
|
# Lazy Greymass API Initialization
|
147
|
-
# @return [
|
155
|
+
# @return [Apibc] API instance
|
148
156
|
def api
|
149
157
|
@api ||= Apibc.new
|
150
158
|
end
|
151
159
|
|
152
|
-
#
|
160
|
+
# Fetch all Greymass data
|
161
|
+
# @return [Hash] Hash of Greymass data indexed by address
|
153
162
|
def gmd
|
154
|
-
@gmd ||= bqd[:wb].map { |o| bsgm(o) }
|
163
|
+
@gmd ||= bqd[:wb].map { |o| bsgm(o) }.each_with_object({}) { |h, a| a[h[:ax]] = h }
|
155
164
|
end
|
156
165
|
|
157
|
-
#
|
166
|
+
# Fetch combined BigQuery and Greymass data
|
167
|
+
# @return [Array<Hash>] Combined data list
|
158
168
|
def dados
|
159
|
-
@dados ||= bqd[:wb].map { |b| bqgm(b, gmd
|
169
|
+
@dados ||= bqd[:wb].map { |b| bqgm(b, gmd[b[:ax]]) }
|
160
170
|
end
|
161
171
|
|
162
172
|
# @return [Array<Integer>] indices transacoes bigquery
|
@@ -166,12 +176,13 @@ module Cns
|
|
166
176
|
|
167
177
|
# @return [Array<Integer>] indices transacoes novas (greymass - bigquery)
|
168
178
|
def idt
|
169
|
-
@idt ||= gmd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
179
|
+
@idt ||= gmd.values.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
170
180
|
end
|
171
181
|
|
172
|
-
#
|
182
|
+
# Get new transactions
|
183
|
+
# @return [Array<Hash>] List of new transactions
|
173
184
|
def novneost
|
174
|
-
@novneost ||= gmd.map { |t| t[:tx].select { |o| idt.include?(o[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
185
|
+
@novneost ||= gmd.values.map { |t| t[:tx].select { |o| idt.include?(o[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
175
186
|
end
|
176
187
|
end
|
177
188
|
end
|
data/lib/cns/version.rb
CHANGED
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.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hernâni Rodrigues Vaz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|
@@ -135,6 +135,20 @@ dependencies:
|
|
135
135
|
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: faraday-retry
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
type: :runtime
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
138
152
|
- !ruby/object:Gem::Dependency
|
139
153
|
name: google-cloud-bigquery
|
140
154
|
requirement: !ruby/object:Gem::Requirement
|