cns 0.9.3 → 0.9.4
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 +3 -3
- data/lib/cns/bigquery.rb +42 -20
- data/lib/cns/bitcoinde.rb +15 -14
- data/lib/cns/etherscan.rb +64 -63
- data/lib/cns/greymass.rb +34 -33
- data/lib/cns/kraken.rb +20 -14
- data/lib/cns/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d70ccf3bf3c61dccaf39f5fe5e34b3f629efd8182fbd036f1d1193e2e0d842e4
|
4
|
+
data.tar.gz: 969e4c7d275aa2b14a6e9b1324e007b84d9f61522b099fdbb6c6d8a9bc129708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c406b44bacdf24f32dc6babc0c08d51cf5fe4f88724466e1af7d8770b08ae23da74c8811cc9f0bea0bdb11cf13ffb9fe3d8080de2626f8f3a0d6f22739e1e82f
|
7
|
+
data.tar.gz: 47e0b4e735ac2c3b11a11018ac5a9830ec1cf24c253b4cb7ab0b353bc2c262f55c572938668ccd00618bf367b5d1019381a30037789fecf13dd2a3b5e5a698b9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cns (0.9.
|
4
|
+
cns (0.9.4)
|
5
5
|
curb
|
6
6
|
faraday
|
7
7
|
google-cloud-bigquery
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
google-cloud-errors (~> 1.0)
|
80
80
|
google-cloud-env (2.2.1)
|
81
81
|
faraday (>= 1.0, < 3.a)
|
82
|
-
google-cloud-errors (1.
|
82
|
+
google-cloud-errors (1.5.0)
|
83
83
|
google-logging-utils (0.1.0)
|
84
84
|
googleauth (1.13.1)
|
85
85
|
faraday (>= 1.0, < 3.a)
|
@@ -137,7 +137,7 @@ GEM
|
|
137
137
|
reverse_markdown (3.0.0)
|
138
138
|
nokogiri
|
139
139
|
rexml (3.4.1)
|
140
|
-
rubocop (1.73.
|
140
|
+
rubocop (1.73.2)
|
141
141
|
json (~> 2.3)
|
142
142
|
language_server-protocol (~> 3.17.0.2)
|
143
143
|
lint_roller (~> 1.1.0)
|
data/lib/cns/bigquery.rb
CHANGED
@@ -9,16 +9,16 @@ module Cns
|
|
9
9
|
FO = File.expand_path("~/#{File.basename($PROGRAM_NAME)}.log")
|
10
10
|
EM = %i[EOS XETH ZEUR btc eth]
|
11
11
|
TB = {
|
12
|
-
netht: %w[blocknumber timestamp
|
13
|
-
hetht: %i[blockNumber timeStamp
|
14
|
-
nethi: %w[blocknumber timestamp
|
15
|
-
hethi: %i[blockNumber timeStamp
|
12
|
+
netht: %w[txhash blocknumber timestamp nonce blockhash transactionindex axfrom axto iax value gas gasprice gasused iserror txreceipt_status input contractaddress dias],
|
13
|
+
hetht: %i[hash blockNumber timeStamp nonce blockHash transactionIndex from to iax value gas gasPrice gasUsed isError txreceipt_status input contractAddress],
|
14
|
+
nethi: %w[txhash blocknumber timestamp axfrom axto iax value contractaddress input type gas gasused traceid iserror errcode dias],
|
15
|
+
hethi: %i[hash blockNumber timeStamp from to iax value contractAddress input type gas gasUsed traceId isError errCode],
|
16
16
|
nethp: %w[blocknumber timestamp blockreward iax dias],
|
17
17
|
hethp: %i[blockNumber timeStamp blockReward iax],
|
18
18
|
nethw: %w[withdrawalindex validatorindex address amount blocknumber timestamp dias],
|
19
19
|
hethw: %i[withdrawalIndex validatorIndex address amount blockNumber timeStamp],
|
20
|
-
nethk: %w[blocknumber timestamp
|
21
|
-
hethk: %i[blockNumber timeStamp
|
20
|
+
nethk: %w[txhash blocknumber timestamp nonce blockhash transactionindex axfrom axto iax value tokenname tokensymbol tokendecimal gas gasprice gasused input contractaddress dias],
|
21
|
+
hethk: %i[hash blockNumber timeStamp nonce blockHash transactionIndex from to iax value tokenName tokenSymbol tokenDecimal gas gasPrice gasUsed input contractAddress],
|
22
22
|
neost: %w[gseq aseq bnum time contract action acfrom acto iax amount moeda memo dias],
|
23
23
|
heost: %i[global_action_seq account_action_seq block_num block_time account name from to iax quantity moe memo],
|
24
24
|
cdet: %w[txid time tp user btc eur dtc dias],
|
@@ -30,6 +30,21 @@ module Cns
|
|
30
30
|
cusl: %w[txid refid time type aclass asset amount fee],
|
31
31
|
husl: %i[txid refid time type aclass asset amount fee]
|
32
32
|
}
|
33
|
+
# para testes bigquery
|
34
|
+
TL = {
|
35
|
+
ins: 'INSERT',
|
36
|
+
exo: false,
|
37
|
+
est: '', # ' limit 226',
|
38
|
+
esi: '', # ' limit 22',
|
39
|
+
esp: '', # ' limit 72',
|
40
|
+
esw: '', # ' limit 2299',
|
41
|
+
esk: '', # ' limit 20',
|
42
|
+
gmt: '', # ' limit 1091',
|
43
|
+
ust: '', # ' limit 182',
|
44
|
+
usl: '', # ' limit 448',
|
45
|
+
det: '', # ' limit 27',
|
46
|
+
del: '' # ' limit 16'
|
47
|
+
}
|
33
48
|
|
34
49
|
# classe para processar bigquery
|
35
50
|
class Bigquery
|
@@ -154,11 +169,11 @@ module Cns
|
|
154
169
|
Etherscan.new(
|
155
170
|
{
|
156
171
|
wb: sql("SELECT * FROM #{BD}.wet#{prx[-1]} ORDER BY ax"),
|
157
|
-
|
158
|
-
|
159
|
-
np: sql("SELECT * FROM #{BD}.#{prx}p"),
|
160
|
-
|
161
|
-
|
172
|
+
nt: sql("SELECT * FROM #{BD}.#{prx}t#{TL[:est]}"),
|
173
|
+
ni: sql("SELECT * FROM #{BD}.#{prx}i#{TL[:esi]}"),
|
174
|
+
np: sql("SELECT * FROM #{BD}.#{prx}p#{TL[:esp]}"),
|
175
|
+
nw: sql("SELECT * FROM #{BD}.#{prx}w#{TL[:esw]}"),
|
176
|
+
nk: sql("SELECT * FROM #{BD}.#{prx}k#{TL[:esk]}")
|
162
177
|
},
|
163
178
|
ops
|
164
179
|
)
|
@@ -176,32 +191,39 @@ module Cns
|
|
176
191
|
|
177
192
|
# @return [Greymass] API blockchain EOS
|
178
193
|
def apigm
|
179
|
-
@apigm ||= Greymass.new({wb: sql("select * from #{BD}.weos ORDER BY ax"), nt: sql("select * from #{BD}.neosx")}, ops)
|
194
|
+
@apigm ||= Greymass.new({wb: sql("select * from #{BD}.weos ORDER BY ax"), nt: sql("select * from #{BD}.neosx#{TL[:gmt]}")}, ops)
|
180
195
|
end
|
181
196
|
|
182
197
|
# @return [Kraken] API exchange kraken
|
183
198
|
def apius
|
184
|
-
@apius ||= Kraken.new({sl: sql("select * from #{BD}.cuss").first, nt: sql("select * from #{BD}.cust"), nl: sql("select * from #{BD}.cusl")}, ops)
|
199
|
+
@apius ||= Kraken.new({sl: sql("select * from #{BD}.cuss").first, nt: sql("select * from #{BD}.cust#{TL[:ust]}"), nl: sql("select * from #{BD}.cusl#{TL[:usl]}")}, ops)
|
185
200
|
end
|
186
201
|
|
187
202
|
# @return [Bitcoinde] API exchange bitcoinde
|
188
203
|
def apide
|
189
|
-
@apide ||= Bitcoinde.new({sl: sql("select * from #{BD}.cdes").first, nt: sql("select * from #{BD}.cdet"), nl: sql("select * from #{BD}.cdel")}, ops)
|
204
|
+
@apide ||= Bitcoinde.new({sl: sql("select * from #{BD}.cdes").first, nt: sql("select * from #{BD}.cdet#{TL[:det]}"), nl: sql("select * from #{BD}.cdel#{TL[:del]}")}, ops)
|
190
205
|
end
|
191
206
|
|
192
207
|
# @return [String] comando insert SQL formatado
|
193
208
|
def ins_sql(tbl, lin)
|
194
|
-
|
209
|
+
# para testes bigquery
|
210
|
+
if TL[:exo]
|
211
|
+
exl = lin.map { |i| send("#{tbl}_val", i)[1..-2] }
|
212
|
+
exi = exl.map { |f| f.split(',').first }.join(',')
|
213
|
+
exo = "SELECT #{TB[tbl].join(',')} FROM #{BD}.#{tbl} WHERE #{TB[tbl].first} IN (#{exi}) union all select "
|
214
|
+
puts(exo + exl.join(' union all select ') + ' order by 1')
|
215
|
+
end
|
216
|
+
"#{TL[:ins]} #{BD}.#{tbl} (#{TB[tbl].join(',')}) VALUES #{lin.map { |i| send("#{tbl}_val", i) }.join(',')}"
|
195
217
|
end
|
196
218
|
|
197
219
|
# @return [String] relatorio execucao dml
|
198
220
|
def dml_out(src, str, ltb)
|
199
221
|
str.concat(
|
200
|
-
ltb.filter_map do |
|
201
|
-
novx = src.send("nov#{
|
222
|
+
ltb.filter_map do |i|
|
223
|
+
novx = src.send("nov#{i}")
|
202
224
|
next if novx.empty?
|
203
225
|
|
204
|
-
format(' %<n>i %<t>s', n: dml(ins_sql(
|
226
|
+
format(' %<n>i %<t>s', n: dml(ins_sql(i, %i[cust cusl].include?(i) ? novx.values : novx)), t: "#{i}")
|
205
227
|
end
|
206
228
|
)
|
207
229
|
str.join
|
@@ -290,7 +312,7 @@ module Cns
|
|
290
312
|
# @param [Hash] htx ledger greymass
|
291
313
|
# @return [String] valores formatados neost
|
292
314
|
def neost_val(htx)
|
293
|
-
fvals(htx, TB[:heost], :
|
315
|
+
fvals(htx, TB[:heost], :global_action_seq)
|
294
316
|
end
|
295
317
|
|
296
318
|
# @param [Hash] htx trades bitcoinde
|
@@ -308,7 +330,7 @@ module Cns
|
|
308
330
|
# @param [Hash] htx trades kraken
|
309
331
|
# @return [String] valores formatados cust
|
310
332
|
def cust_val(htx)
|
311
|
-
fvals(htx.merge(ledgers: apius.
|
333
|
+
fvals(htx.merge(ledgers: apius.uskl.select { |_, o| o[:refid] == htx[:txid] }.keys.join(',')), TB[:hust], :txid)
|
312
334
|
end
|
313
335
|
|
314
336
|
# @param [Hash] htx ledger kraken
|
data/lib/cns/bitcoinde.rb
CHANGED
@@ -23,15 +23,10 @@ module Cns
|
|
23
23
|
@ops = pop.transform_keys(&:to_sym)
|
24
24
|
end
|
25
25
|
|
26
|
-
# @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
|
27
|
-
def exd
|
28
|
-
@exd ||= {sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de)}
|
29
|
-
end
|
30
|
-
|
31
26
|
# @return [String] texto saldos & transacoes & ajuste dias
|
32
27
|
def mresumo
|
33
28
|
puts("\nBITCOINDE\ntipo bitcoinde bigquery")
|
34
|
-
|
29
|
+
ded[:sl].sort.each { |k, v| puts(fos(k, v)) }
|
35
30
|
mtotais
|
36
31
|
|
37
32
|
mtrades
|
@@ -45,9 +40,9 @@ module Cns
|
|
45
40
|
|
46
41
|
# mosta contadores transacoes
|
47
42
|
def mtotais
|
48
|
-
vtt =
|
43
|
+
vtt = ded[:tt].count
|
49
44
|
vnt = bqd[:nt].count
|
50
|
-
vtl =
|
45
|
+
vtl = ded[:tl].count
|
51
46
|
vnl = bqd[:nl].count
|
52
47
|
|
53
48
|
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}")
|
@@ -114,6 +109,7 @@ module Cns
|
|
114
109
|
)
|
115
110
|
end
|
116
111
|
|
112
|
+
# @return [Boolean] mostra todas/novas transacoes
|
117
113
|
def show_all?
|
118
114
|
ops[:t] || false
|
119
115
|
end
|
@@ -157,34 +153,39 @@ module Cns
|
|
157
153
|
hlx.map { |t| pdes(:time, t).merge(qtd: (t[:tp] == 'withdrawal' ? -1 : 1) * t[:qt].to_d, nxid: t[:txid], fee: t[:fee].to_d, moe: t[:moe].upcase) }
|
158
154
|
end
|
159
155
|
|
156
|
+
# @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
|
157
|
+
def ded
|
158
|
+
@ded ||= {sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de)}
|
159
|
+
end
|
160
|
+
|
160
161
|
# @return [Array<String>] indices trades bigquery
|
161
162
|
def bqkyt
|
162
|
-
@bqkyt ||= show_all? ? [] :
|
163
|
+
@bqkyt ||= show_all? ? [] : bqd[:nt].map { |t| t[:txid] }
|
163
164
|
end
|
164
165
|
|
165
166
|
# @return [Array<Integer>] indices ledger bigquery
|
166
167
|
def bqkyl
|
167
|
-
@bqkyl ||= show_all? ? [] :
|
168
|
+
@bqkyl ||= show_all? ? [] : bqd[:nl].map { |l| l[:txid] }
|
168
169
|
end
|
169
170
|
|
170
171
|
# @return [Array<String>] lista txid trades novos
|
171
172
|
def kyt
|
172
|
-
@kyt ||=
|
173
|
+
@kyt ||= ded[:tt].map { |t| t[:trade_id] } - bqkyt
|
173
174
|
end
|
174
175
|
|
175
176
|
# @return [Array<Integer>] lista txid ledger novos
|
176
177
|
def kyl
|
177
|
-
@kyl ||=
|
178
|
+
@kyl ||= ded[:tl].map { |t| t[:txid] } - bqkyl
|
178
179
|
end
|
179
180
|
|
180
181
|
# @return [Array<Hash>] lista trades bitcoinde novos
|
181
182
|
def novcdet
|
182
|
-
@novcdet ||=
|
183
|
+
@novcdet ||= ded[:tt].select { |obj| kyt.include?(obj[:trade_id]) }
|
183
184
|
end
|
184
185
|
|
185
186
|
# @return [Array<Hash>] lista ledger (deposits + withdrawals) bitcoinde novos
|
186
187
|
def novcdel
|
187
|
-
@novcdel ||=
|
188
|
+
@novcdel ||= ded[:tl].select { |obj| kyl.include?(obj[:txid]) }
|
188
189
|
end
|
189
190
|
end
|
190
191
|
end
|
data/lib/cns/etherscan.rb
CHANGED
@@ -84,22 +84,22 @@ module Cns
|
|
84
84
|
|
85
85
|
# mosta transacoes novas
|
86
86
|
def mtransacoes_novas
|
87
|
-
TT.each do |_,
|
88
|
-
ntx = send(
|
87
|
+
TT.each do |_, c|
|
88
|
+
ntx = send(c[:new])
|
89
89
|
next unless ops[:v] && ntx.any?
|
90
90
|
|
91
|
-
puts(
|
92
|
-
ntx.sort_by { |s| -s[
|
91
|
+
puts(c[:header])
|
92
|
+
ntx.sort_by { |s| -s[c[:sork]] }.each { |t| puts(send(c[:format], t)) }
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
# mostra configuration text for adjusting days
|
97
97
|
def mconfiguracao_ajuste_dias
|
98
|
-
TT.each do |
|
99
|
-
ntx = send(
|
98
|
+
TT.each do |p, c|
|
99
|
+
ntx = send(c[:new])
|
100
100
|
next unless ntx.any?
|
101
101
|
|
102
|
-
puts("\najuste dias transacoes #{
|
102
|
+
puts("\najuste dias transacoes #{p}\n-h=#{ntx.sort_by { |s| -s[c[:sork]] }.map { |t| "#{t[c[:adjk]]}:0" }.join(' ')}")
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -226,44 +226,7 @@ module Cns
|
|
226
226
|
format('%<bn>10i %<vi>9i %<dt>10.10s %<vl>10.6f', bn: hwx[:withdrawalIndex], vi: hwx[:validatorIndex], dt: hwx[:timeStamp].strftime('%F'), vl: hwx[:amount] / (10**9))
|
227
227
|
end
|
228
228
|
|
229
|
-
# @
|
230
|
-
# @return [Hash] dados etherscan - address, saldo & transacoes
|
231
|
-
def base_bc(abc)
|
232
|
-
acc = abc[:account].downcase
|
233
|
-
{
|
234
|
-
ax: acc,
|
235
|
-
sl: abc[:balance].to_d / (10**18),
|
236
|
-
tx: ftik(acc, api.norml_es(acc)),
|
237
|
-
ix: ftik(acc, api.inter_es(acc)),
|
238
|
-
px: fppp(acc, api.block_es(acc)),
|
239
|
-
wx: fwww(acc, api.withw_es(acc)),
|
240
|
-
kx: ftik(acc, api.token_es(acc))
|
241
|
-
}
|
242
|
-
end
|
243
|
-
|
244
|
-
# @param [Hash] wbq wallet bigquery
|
245
|
-
# @param [Hash] hbc dados etherscan - address, saldo & transacoes
|
246
|
-
# @return [Hash] dados juntos bigquery & etherscan
|
247
|
-
def bq_bc(wbq, hbc)
|
248
|
-
xbq = wbq[:ax]
|
249
|
-
{
|
250
|
-
id: wbq[:id],
|
251
|
-
ax: xbq,
|
252
|
-
bs: wbq[:sl],
|
253
|
-
bt: bqd[:nt].select { |ont| ont[:iax].casecmp?(xbq) },
|
254
|
-
bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
|
255
|
-
bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
|
256
|
-
bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
|
257
|
-
bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
|
258
|
-
es: hbc[:sl],
|
259
|
-
et: hbc[:tx],
|
260
|
-
ei: hbc[:ix],
|
261
|
-
ep: hbc[:px],
|
262
|
-
ew: hbc[:wx],
|
263
|
-
ek: hbc[:kx]
|
264
|
-
}
|
265
|
-
end
|
266
|
-
|
229
|
+
# @return [Boolean] mostra todas/novas transacoes
|
267
230
|
def show_all?
|
268
231
|
ops[:t] || false
|
269
232
|
end
|
@@ -296,94 +259,132 @@ module Cns
|
|
296
259
|
ary.map { |o| o.merge(itx: Integer(o[:withdrawalIndex]), iax: add, amount: o[:amount].to_d, timeStamp: Time.at(Integer(o[:timestamp]))) }
|
297
260
|
end
|
298
261
|
|
262
|
+
# @param [Hash] aes account etherscan
|
263
|
+
# @return [Hash] dados etherscan - address, saldo & transacoes
|
264
|
+
def bses(aes)
|
265
|
+
acc = aes[:account].downcase
|
266
|
+
{
|
267
|
+
ax: acc,
|
268
|
+
sl: aes[:balance].to_d / (10**18),
|
269
|
+
tx: ftik(acc, api.norml_es(acc)),
|
270
|
+
ix: ftik(acc, api.inter_es(acc)),
|
271
|
+
px: fppp(acc, api.block_es(acc)),
|
272
|
+
wx: fwww(acc, api.withw_es(acc)),
|
273
|
+
kx: ftik(acc, api.token_es(acc))
|
274
|
+
}
|
275
|
+
end
|
276
|
+
|
277
|
+
# @param [Hash] wbq wallet bigquery
|
278
|
+
# @param [Hash] hes dados etherscan - address, saldo & transacoes
|
279
|
+
# @return [Hash] dados juntos bigquery & etherscan
|
280
|
+
def bqes(wbq, hes)
|
281
|
+
xbq = wbq[:ax]
|
282
|
+
{
|
283
|
+
id: wbq[:id],
|
284
|
+
ax: xbq,
|
285
|
+
bs: wbq[:sl],
|
286
|
+
bt: bqd[:nt].select { |t| t[:iax].casecmp?(xbq) },
|
287
|
+
bi: bqd[:ni].select { |i| i[:iax].casecmp?(xbq) },
|
288
|
+
bp: bqd[:np].select { |p| p[:iax].casecmp?(xbq) },
|
289
|
+
bw: bqd[:nw].select { |w| w[:iax].casecmp?(xbq) },
|
290
|
+
bk: bqd[:nk].select { |k| k[:iax].casecmp?(xbq) },
|
291
|
+
es: hes[:sl],
|
292
|
+
et: hes[:tx],
|
293
|
+
ei: hes[:ix],
|
294
|
+
ep: hes[:px],
|
295
|
+
ew: hes[:wx],
|
296
|
+
ek: hes[:kx]
|
297
|
+
}
|
298
|
+
end
|
299
|
+
|
299
300
|
# @return [Array<String>] lista enderecos
|
300
301
|
def lax
|
301
302
|
@lax ||= bqd[:wb].map { |o| o[:ax] }
|
302
303
|
end
|
303
304
|
|
304
305
|
# @return [Array<Hash>] todos os dados etherscan - saldos & transacoes
|
305
|
-
def
|
306
|
-
@
|
306
|
+
def esd
|
307
|
+
@esd ||= api.account_es(lax).map { |o| bses(o) }
|
307
308
|
end
|
308
309
|
|
309
310
|
# @return [Array<Hash>] todos os dados juntos bigquery & etherscan
|
310
311
|
def dados
|
311
|
-
@dados ||= bqd[:wb].map { |b|
|
312
|
+
@dados ||= bqd[:wb].map { |b| bqes(b, esd.find { |e| b[:ax] == e[:ax] }) }
|
312
313
|
end
|
313
314
|
|
314
315
|
# @return [Array<Integer>] indices transacoes bigquery
|
315
316
|
def bqidt
|
316
|
-
@bqidt ||= show_all? ? [] :
|
317
|
+
@bqidt ||= show_all? ? [] : bqd[:nt].map { |i| i[:itx] }
|
317
318
|
end
|
318
319
|
|
319
320
|
# @return [Array<Integer>] indices transacoes bigquery
|
320
321
|
def bqidi
|
321
|
-
@bqidi ||= show_all? ? [] :
|
322
|
+
@bqidi ||= show_all? ? [] : bqd[:ni].map { |i| i[:itx] }
|
322
323
|
end
|
323
324
|
|
324
325
|
# @return [Array<Integer>] indices transacoes bigquery
|
325
326
|
def bqidp
|
326
|
-
@bqidp ||= show_all? ? [] :
|
327
|
+
@bqidp ||= show_all? ? [] : bqd[:np].map { |i| i[:itx] }
|
327
328
|
end
|
328
329
|
|
329
330
|
# @return [Array<Integer>] indices transacoes bigquery
|
330
331
|
def bqidw
|
331
|
-
@bqidw ||= show_all? ? [] :
|
332
|
+
@bqidw ||= show_all? ? [] : bqd[:nw].map { |i| i[:itx] }
|
332
333
|
end
|
333
334
|
|
334
335
|
# @return [Array<Integer>] indices transacoes bigquery
|
335
336
|
def bqidk
|
336
|
-
@bqidk ||= show_all? ? [] :
|
337
|
+
@bqidk ||= show_all? ? [] : bqd[:nk].map { |i| i[:itx] }
|
337
338
|
end
|
338
339
|
|
339
340
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
340
341
|
def idt
|
341
|
-
@idt ||=
|
342
|
+
@idt ||= esd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
342
343
|
end
|
343
344
|
|
344
345
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
345
346
|
def idi
|
346
|
-
@idi ||=
|
347
|
+
@idi ||= esd.map { |o| o[:ix].map { |i| i[:itx] } }.flatten - bqidi
|
347
348
|
end
|
348
349
|
|
349
350
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
350
351
|
def idp
|
351
|
-
@idp ||=
|
352
|
+
@idp ||= esd.map { |o| o[:px].map { |i| i[:itx] } }.flatten - bqidp
|
352
353
|
end
|
353
354
|
|
354
355
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
355
356
|
def idw
|
356
|
-
@idw ||=
|
357
|
+
@idw ||= esd.map { |o| o[:wx].map { |i| i[:itx] } }.flatten - bqidw
|
357
358
|
end
|
358
359
|
|
359
360
|
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
360
361
|
def idk
|
361
|
-
@idk ||=
|
362
|
+
@idk ||= esd.map { |o| o[:kx].map { |i| i[:itx] } }.flatten - bqidk
|
362
363
|
end
|
363
364
|
|
364
365
|
# @return [Array<Hash>] lista transacoes normais novas
|
365
366
|
def novnetht
|
366
|
-
@novnetht ||=
|
367
|
+
@novnetht ||= esd.map { |o| o[:tx].select { |t| idt.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
367
368
|
end
|
368
369
|
|
369
370
|
# @return [Array<Hash>] lista transacoes internas novas
|
370
371
|
def novnethi
|
371
|
-
@novnethi ||=
|
372
|
+
@novnethi ||= esd.map { |o| o[:ix].select { |t| idi.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
372
373
|
end
|
373
374
|
|
374
375
|
# @return [Array<Hash>] lista transacoes block novas
|
375
376
|
def novnethp
|
376
|
-
@novnethp ||=
|
377
|
+
@novnethp ||= esd.map { |o| o[:px].select { |t| idp.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
377
378
|
end
|
378
379
|
|
379
380
|
# @return [Array<Hash>] lista transacoes withdrawals novas
|
380
381
|
def novnethw
|
381
|
-
@novnethw ||=
|
382
|
+
@novnethw ||= esd.map { |o| o[:wx].select { |t| idw.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
382
383
|
end
|
383
384
|
|
384
385
|
# @return [Array<Hash>] lista transacoes token novas
|
385
386
|
def novnethk
|
386
|
-
@novnethk ||=
|
387
|
+
@novnethk ||= esd.map { |o| o[:kx].select { |t| idk.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
387
388
|
end
|
388
389
|
end
|
389
390
|
end
|
data/lib/cns/greymass.rb
CHANGED
@@ -95,28 +95,7 @@ module Cns
|
|
95
95
|
)
|
96
96
|
end
|
97
97
|
|
98
|
-
# @
|
99
|
-
# @return [Hash] dados greymass - address, saldo & transacoes
|
100
|
-
def base_bc(wbq)
|
101
|
-
xbq = wbq[:ax]
|
102
|
-
{ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq))}
|
103
|
-
end
|
104
|
-
|
105
|
-
# @param wbq (see base_bc)
|
106
|
-
# @param [Hash] hbc dados greymass - address, saldo & transacoes
|
107
|
-
# @return [Hash] dados juntos bigquery & greymass
|
108
|
-
def bq_bc(wbq, hbc)
|
109
|
-
xbq = wbq[:ax]
|
110
|
-
{
|
111
|
-
id: wbq[:id],
|
112
|
-
ax: xbq,
|
113
|
-
bs: wbq[:sl],
|
114
|
-
bt: bqd[:nt].select { |o| o[:iax] == xbq },
|
115
|
-
es: hbc[:sl],
|
116
|
-
et: hbc[:tx]
|
117
|
-
}
|
118
|
-
end
|
119
|
-
|
98
|
+
# @return [Boolean] mostra todas/novas transacoes
|
120
99
|
def show_all?
|
121
100
|
ops[:t] || false
|
122
101
|
end
|
@@ -133,11 +112,11 @@ module Cns
|
|
133
112
|
# @param [Array<Hash>] ary lista transacoes
|
134
113
|
# @return [Array<Hash>] lista transacoes filtrada
|
135
114
|
def peost(add, ary)
|
136
|
-
ary.map do |
|
137
|
-
act =
|
115
|
+
ary.map do |t|
|
116
|
+
act = t[:action_trace][:act]
|
138
117
|
adt = act[:data]
|
139
118
|
qtd = adt[:quantity].to_s
|
140
|
-
|
119
|
+
t.merge(
|
141
120
|
name: act[:name],
|
142
121
|
from: adt[:from],
|
143
122
|
quantity: qtd.to_d,
|
@@ -145,36 +124,58 @@ module Cns
|
|
145
124
|
to: adt[:to],
|
146
125
|
memo: String(adt[:memo]).gsub(/\p{C}/, ''), # remove Non-Printable Characters
|
147
126
|
moe: qtd[/[[:upper:]]+/],
|
148
|
-
itx:
|
127
|
+
itx: t[:global_action_seq],
|
149
128
|
iax: add,
|
150
|
-
block_time: Time.parse(
|
129
|
+
block_time: Time.parse(t[:block_time])
|
151
130
|
)
|
152
131
|
end
|
153
132
|
end
|
154
133
|
|
134
|
+
# @param [Hash] wbq wallet bigquery
|
135
|
+
# @return [Hash] dados greymass - address, saldo & transacoes
|
136
|
+
def bsgm(wbq)
|
137
|
+
xbq = wbq[:ax]
|
138
|
+
{ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq))}
|
139
|
+
end
|
140
|
+
|
141
|
+
# @param wbq (see bsgm)
|
142
|
+
# @param [Hash] hgm dados greymass - address, saldo & transacoes
|
143
|
+
# @return [Hash] dados juntos bigquery & greymass
|
144
|
+
def bqgm(wbq, hgm)
|
145
|
+
xbq = wbq[:ax]
|
146
|
+
{
|
147
|
+
id: wbq[:id],
|
148
|
+
ax: xbq,
|
149
|
+
bs: wbq[:sl],
|
150
|
+
bt: bqd[:nt].select { |o| o[:iax] == xbq },
|
151
|
+
es: hgm[:sl],
|
152
|
+
et: hgm[:tx]
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
155
156
|
# @return [Array<Hash>] todos os dados greymass - saldos & transacoes
|
156
|
-
def
|
157
|
-
@
|
157
|
+
def gmd
|
158
|
+
@gmd ||= bqd[:wb].map { |o| bsgm(o) }
|
158
159
|
end
|
159
160
|
|
160
161
|
# @return [Array<Hash>] todos os dados juntos bigquery & greymass
|
161
162
|
def dados
|
162
|
-
@dados ||= bqd[:wb].map { |b|
|
163
|
+
@dados ||= bqd[:wb].map { |b| bqgm(b, gmd.find { |g| b[:ax] == g[:ax] }) }
|
163
164
|
end
|
164
165
|
|
165
166
|
# @return [Array<Integer>] indices transacoes bigquery
|
166
167
|
def bqidt
|
167
|
-
@bqidt ||= show_all? ? [] :
|
168
|
+
@bqidt ||= show_all? ? [] : bqd[:nt].map { |i| i[:itx] }
|
168
169
|
end
|
169
170
|
|
170
171
|
# @return [Array<Integer>] indices transacoes novas (greymass - bigquery)
|
171
172
|
def idt
|
172
|
-
@idt ||=
|
173
|
+
@idt ||= gmd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
173
174
|
end
|
174
175
|
|
175
176
|
# @return [Array<Hash>] lista transacoes novas
|
176
177
|
def novneost
|
177
|
-
@novneost ||=
|
178
|
+
@novneost ||= gmd.map { |t| t[:tx].select { |o| idt.include?(o[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
178
179
|
end
|
179
180
|
end
|
180
181
|
end
|
data/lib/cns/kraken.rb
CHANGED
@@ -23,15 +23,10 @@ module Cns
|
|
23
23
|
@ops = pop.transform_keys(&:to_sym)
|
24
24
|
end
|
25
25
|
|
26
|
-
# @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
|
27
|
-
def exd
|
28
|
-
@exd ||= {sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us)}
|
29
|
-
end
|
30
|
-
|
31
26
|
# @return [String] texto saldos & transacoes & ajuste dias
|
32
27
|
def mresumo
|
33
28
|
puts("\nKRAKEN\ntipo kraken bigquery")
|
34
|
-
|
29
|
+
usd[:sl].sort.each { |key, val| puts(fos(key, val)) }
|
35
30
|
mtotais
|
36
31
|
|
37
32
|
mtrades
|
@@ -41,13 +36,18 @@ module Cns
|
|
41
36
|
puts("\nstring ajuste dias dos trades\n-h=#{novcust.sort_by { |_, v| -v[:srx] }.map { |k, _v| "#{k}:0" }.join(' ')}")
|
42
37
|
end
|
43
38
|
|
39
|
+
# @return [Hash] ledgers exchange kraken
|
40
|
+
def uskl
|
41
|
+
usd[:kl]
|
42
|
+
end
|
43
|
+
|
44
44
|
private
|
45
45
|
|
46
46
|
# mosta contadores transacoes
|
47
47
|
def mtotais
|
48
|
-
vkt =
|
48
|
+
vkt = usd[:kt].count
|
49
49
|
vnt = bqd[:nt].count
|
50
|
-
vkl =
|
50
|
+
vkl = usd[:kl].count
|
51
51
|
vnl = bqd[:nl].count
|
52
52
|
|
53
53
|
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vkt, b: vnt, o: vkt == vnt ? 'OK' : 'NOK')}")
|
@@ -115,6 +115,7 @@ module Cns
|
|
115
115
|
)
|
116
116
|
end
|
117
117
|
|
118
|
+
# @return [Boolean] mostra todas/novas transacoes
|
118
119
|
def show_all?
|
119
120
|
ops[:t] || false
|
120
121
|
end
|
@@ -146,34 +147,39 @@ module Cns
|
|
146
147
|
pusk(hlx).transform_values { |t| t.merge(asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
|
147
148
|
end
|
148
149
|
|
150
|
+
# @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
|
151
|
+
def usd
|
152
|
+
@usd ||= {sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us)}
|
153
|
+
end
|
154
|
+
|
149
155
|
# @return [Array<Symbol>] indices trades bigquery
|
150
156
|
def bqkyt
|
151
|
-
@bqkyt ||= show_all? ? [] :
|
157
|
+
@bqkyt ||= show_all? ? [] : bqd[:nt].map { |t| t[:txid].to_sym }
|
152
158
|
end
|
153
159
|
|
154
160
|
# @return [Array<Symbol>] indices ledger bigquery
|
155
161
|
def bqkyl
|
156
|
-
@bqkyl ||= show_all? ? [] :
|
162
|
+
@bqkyl ||= show_all? ? [] : bqd[:nl].map { |l| l[:txid].to_sym }
|
157
163
|
end
|
158
164
|
|
159
165
|
# @return [Array<Symbol>] lista txid trades novos
|
160
166
|
def kyt
|
161
|
-
@kyt ||=
|
167
|
+
@kyt ||= usd[:kt].keys - bqkyt
|
162
168
|
end
|
163
169
|
|
164
170
|
# @return [Array<Symbol>] lista txid ledger novos
|
165
171
|
def kyl
|
166
|
-
@kyl ||=
|
172
|
+
@kyl ||= usd[:kl].keys - bqkyl
|
167
173
|
end
|
168
174
|
|
169
175
|
# @return [Hash] trades kraken novos
|
170
176
|
def novcust
|
171
|
-
@novcust ||=
|
177
|
+
@novcust ||= usd[:kt].slice(*kyt)
|
172
178
|
end
|
173
179
|
|
174
180
|
# @return [Hash] ledger kraken novos
|
175
181
|
def novcusl
|
176
|
-
@novcusl ||=
|
182
|
+
@novcusl ||= usd[:kl].slice(*kyl)
|
177
183
|
end
|
178
184
|
end
|
179
185
|
end
|
data/lib/cns/version.rb
CHANGED