cns 0.7.8 → 0.8.0
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/.rubocop.yml +55 -1
- data/Gemfile.lock +79 -43
- data/cns.gemspec +1 -2
- data/lib/cns/apibc.rb +3 -13
- data/lib/cns/apice.rb +12 -24
- data/lib/cns/bigquery.rb +163 -370
- data/lib/cns/bitcoinde.rb +1 -5
- data/lib/cns/etherscan.rb +15 -23
- data/lib/cns/greymass.rb +1 -1
- data/lib/cns/kraken.rb +3 -7
- data/lib/cns/version.rb +1 -1
- metadata +4 -35
- data/ruby-lint.yml +0 -10
data/lib/cns/bigquery.rb
CHANGED
@@ -6,7 +6,7 @@ require('bigdecimal/util')
|
|
6
6
|
# @author Hernani Rodrigues Vaz
|
7
7
|
module Cns
|
8
8
|
BD = 'hernanirvaz.coins'
|
9
|
-
FO = File.expand_path(
|
9
|
+
FO = File.expand_path("~/#{File.basename($PROGRAM_NAME)}.log")
|
10
10
|
|
11
11
|
# classe para processar bigquery
|
12
12
|
class Bigquery
|
@@ -52,18 +52,18 @@ module Cns
|
|
52
52
|
|
53
53
|
# @return [String] texto inicial transacoes
|
54
54
|
def trs_ini
|
55
|
-
Time.now.strftime(
|
55
|
+
Time.now.strftime('TRANSACOES %Y-%m-%d %H:%M:%S ')
|
56
56
|
end
|
57
57
|
|
58
58
|
# insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass no bigquery
|
59
59
|
def processa_tudo
|
60
|
-
str = processa_us
|
60
|
+
str = "#{processa_us}, #{processa_de}, #{processa_eth}, #{processa_eos}"
|
61
61
|
puts(trs_ini + str)
|
62
62
|
end
|
63
63
|
|
64
64
|
# insere (caso existam) dados novos kraken/etherscan no bigquery
|
65
65
|
def processa_wkrk
|
66
|
-
str = processa_us
|
66
|
+
str = "#{processa_us}, #{processa_eth}"
|
67
67
|
puts(trs_ini + str)
|
68
68
|
end
|
69
69
|
|
@@ -85,12 +85,12 @@ module Cns
|
|
85
85
|
#
|
86
86
|
# @return [String] linhas & tabelas afetadas
|
87
87
|
def processa_eth
|
88
|
-
str =
|
89
|
-
str += format(
|
90
|
-
str += format(
|
91
|
-
str += format(
|
92
|
-
str += format(
|
93
|
-
str += format(
|
88
|
+
str = 'ETH'
|
89
|
+
str += format(' %<n>i netht', n: dml(netht_ins)) if apies.novtx.count.positive?
|
90
|
+
str += format(' %<n>i nethi', n: dml(nethi_ins)) if apies.novix.count.positive?
|
91
|
+
str += format(' %<n>i nethp', n: dml(nethp_ins)) if apies.novpx.count.positive?
|
92
|
+
str += format(' %<n>i nethw', n: dml(nethw_ins)) if apies.novwx.count.positive?
|
93
|
+
str += format(' %<n>i nethk', n: dml(nethk_ins)) if apies.novkx.count.positive?
|
94
94
|
str
|
95
95
|
end
|
96
96
|
|
@@ -98,12 +98,12 @@ module Cns
|
|
98
98
|
#
|
99
99
|
# @return [String] linhas & tabelas afetadas
|
100
100
|
def processa_ethc
|
101
|
-
str =
|
102
|
-
str += format(
|
103
|
-
str += format(
|
104
|
-
str += format(
|
105
|
-
str += format(
|
106
|
-
str += format(
|
101
|
+
str = 'ETH'
|
102
|
+
str += format(' %<n>i netht', n: dml(netbt_ins)) if apiesc.novtx.count.positive?
|
103
|
+
str += format(' %<n>i nethi', n: dml(netbi_ins)) if apiesc.novix.count.positive?
|
104
|
+
str += format(' %<n>i nethp', n: dml(netbp_ins)) if apiesc.novpx.count.positive?
|
105
|
+
str += format(' %<n>i nethw', n: dml(netbw_ins)) if apiesc.novwx.count.positive?
|
106
|
+
str += format(' %<n>i nethk', n: dml(netbk_ins)) if apiesc.novkx.count.positive?
|
107
107
|
str
|
108
108
|
end
|
109
109
|
|
@@ -111,9 +111,9 @@ module Cns
|
|
111
111
|
#
|
112
112
|
# @return [String] linhas & tabelas afetadas
|
113
113
|
def processa_us
|
114
|
-
str =
|
115
|
-
str += format(
|
116
|
-
str += format(
|
114
|
+
str = 'KRAKEN'
|
115
|
+
str += format(' %<n>i ust', n: dml(ust_ins)) if apius.trades.count.positive?
|
116
|
+
str += format(' %<n>i usl', n: dml(usl_ins)) if apius.ledger.count.positive?
|
117
117
|
str
|
118
118
|
end
|
119
119
|
|
@@ -121,9 +121,9 @@ module Cns
|
|
121
121
|
#
|
122
122
|
# @return [String] linhas & tabelas afetadas
|
123
123
|
def processa_de
|
124
|
-
str =
|
125
|
-
str += format(
|
126
|
-
str += format(
|
124
|
+
str = 'BITCOINDE'
|
125
|
+
str += format(' %<n>i det', n: dml(det_ins)) if apide.trades.count.positive?
|
126
|
+
str += format(' %<n>i del', n: dml(del_ins)) if apide.ledger.count.positive?
|
127
127
|
str
|
128
128
|
end
|
129
129
|
|
@@ -131,8 +131,8 @@ module Cns
|
|
131
131
|
#
|
132
132
|
# @return [String] linhas & tabelas afetadas
|
133
133
|
def processa_eos
|
134
|
-
str =
|
135
|
-
str += format(
|
134
|
+
str = 'EOS'
|
135
|
+
str += format(' %<n>i eos ', n: dml(eost_ins)) if apigm.novax.count.positive?
|
136
136
|
str
|
137
137
|
end
|
138
138
|
|
@@ -182,7 +182,7 @@ module Cns
|
|
182
182
|
|
183
183
|
# @return [Etherscan] API blockchain ETH
|
184
184
|
def apiesc
|
185
|
-
@
|
185
|
+
@apiesc ||= Etherscan.new(
|
186
186
|
{
|
187
187
|
wb: sql("select * from #{BD}.wetc order by ax"),
|
188
188
|
ni: sql("select * from #{BD}.netci"),
|
@@ -197,20 +197,14 @@ module Cns
|
|
197
197
|
|
198
198
|
# @return [Greymass] API blockchain EOS
|
199
199
|
def apigm
|
200
|
-
@apigm ||= Greymass.new(
|
201
|
-
{
|
202
|
-
wb: sql("select * from #{BD}.weos order by ax"),
|
203
|
-
nt: sql("select * from #{BD}.neosx")
|
204
|
-
},
|
205
|
-
ops
|
206
|
-
)
|
200
|
+
@apigm ||= Greymass.new({ wb: sql("select * from #{BD}.weos order by ax"), nt: sql("select * from #{BD}.neosx") }, ops)
|
207
201
|
end
|
208
202
|
|
209
203
|
# @return [Kraken] API exchange kraken
|
210
204
|
def apius
|
211
205
|
@apius ||= Kraken.new(
|
212
206
|
{
|
213
|
-
sl: sql("select * from #{BD}.cuss")
|
207
|
+
sl: sql("select * from #{BD}.cuss").first,
|
214
208
|
nt: sql("select * from #{BD}.cust order by time,txid"),
|
215
209
|
nl: sql("select * from #{BD}.cusl order by time,txid")
|
216
210
|
},
|
@@ -222,7 +216,7 @@ module Cns
|
|
222
216
|
def apide
|
223
217
|
@apide ||= Bitcoinde.new(
|
224
218
|
{
|
225
|
-
sl: sql("select * from #{BD}.cdes")
|
219
|
+
sl: sql("select * from #{BD}.cdes").first,
|
226
220
|
nt: sql("select * from #{BD}.cdet order by time,txid"),
|
227
221
|
nl: sql("select * from #{BD}.cdel order by time,txid")
|
228
222
|
},
|
@@ -233,13 +227,13 @@ module Cns
|
|
233
227
|
# @return [String] comando insert SQL formatado netht (norml)
|
234
228
|
def bnetht_ins
|
235
229
|
"insert #{BD}.netht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
236
|
-
|
230
|
+
'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias) VALUES'
|
237
231
|
end
|
238
232
|
|
239
233
|
# @return [String] comando insert SQL formatado nethi (internas)
|
240
234
|
def bnethi_ins
|
241
235
|
"insert #{BD}.nethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
|
242
|
-
|
236
|
+
'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode) VALUES'
|
243
237
|
end
|
244
238
|
|
245
239
|
# @return [String] comando insert SQL formatado nethp (block)
|
@@ -255,68 +249,68 @@ module Cns
|
|
255
249
|
# @return [String] comando insert SQL formatado nethk (token)
|
256
250
|
def bnethk_ins
|
257
251
|
"insert #{BD}.nethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
258
|
-
|
252
|
+
'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias) VALUES'
|
259
253
|
end
|
260
254
|
|
261
255
|
# @return [String] comando insert SQL formatado netht (norml)
|
262
256
|
def netht_ins
|
263
|
-
"#{bnetht_ins}#{apies.novtx.map { |obj|
|
257
|
+
"#{bnetht_ins}#{apies.novtx.map { |obj| netht_val(obj) }.join(',')}"
|
264
258
|
end
|
265
259
|
|
266
260
|
# @return [String] comando insert SQL formatado nethi (internas)
|
267
261
|
def nethi_ins
|
268
|
-
"#{bnethi_ins}#{apies.novix.map { |obj|
|
262
|
+
"#{bnethi_ins}#{apies.novix.map { |obj| nethi_val(obj) }.join(',')}"
|
269
263
|
end
|
270
264
|
|
271
265
|
# @return [String] comando insert SQL formatado nethp (block)
|
272
266
|
def nethp_ins
|
273
|
-
"#{bnethp_ins}#{apies.novpx.map { |obj|
|
267
|
+
"#{bnethp_ins}#{apies.novpx.map { |obj| nethp_val(obj) }.join(',')}"
|
274
268
|
end
|
275
269
|
|
276
270
|
# @return [String] comando insert SQL formatado nethw (withdrawals)
|
277
271
|
def nethw_ins
|
278
|
-
"#{bnethw_ins}#{apies.novwx.map { |obj|
|
272
|
+
"#{bnethw_ins}#{apies.novwx.map { |obj| nethw_val(obj) }.join(',')}"
|
279
273
|
end
|
280
274
|
|
281
275
|
# @return [String] comando insert SQL formatado nethk (token)
|
282
276
|
def nethk_ins
|
283
|
-
"#{bnethk_ins}#{apies.novkx.map { |obj|
|
277
|
+
"#{bnethk_ins}#{apies.novkx.map { |obj| nethk_val(obj) }.join(',')}"
|
284
278
|
end
|
285
279
|
|
286
280
|
# @return [String] comando insert SQL formatado netht (norml)
|
287
281
|
def netbt_ins
|
288
|
-
"#{bnetht_ins}#{apiesc.novtx.map { |obj|
|
282
|
+
"#{bnetht_ins}#{apiesc.novtx.map { |obj| netht_val(obj) }.join(',')}"
|
289
283
|
end
|
290
284
|
|
291
285
|
# @return [String] comando insert SQL formatado nethi (internas)
|
292
286
|
def netbi_ins
|
293
|
-
"#{bnethi_ins}#{apiesc.novix.map { |obj|
|
287
|
+
"#{bnethi_ins}#{apiesc.novix.map { |obj| nethi_val(obj) }.join(',')}"
|
294
288
|
end
|
295
289
|
|
296
290
|
# @return [String] comando insert SQL formatado nethp (block)
|
297
291
|
def netbp_ins
|
298
|
-
"#{bnethp_ins}#{apiesc.novpx.map { |obj|
|
292
|
+
"#{bnethp_ins}#{apiesc.novpx.map { |obj| nethp_val(obj) }.join(',')}"
|
299
293
|
end
|
300
294
|
|
301
295
|
# @return [String] comando insert SQL formatado nethw (withdrawals)
|
302
296
|
def netbw_ins
|
303
|
-
"#{bnethw_ins}#{apiesc.novwx.map { |obj|
|
297
|
+
"#{bnethw_ins}#{apiesc.novwx.map { |obj| nethw_val(obj) }.join(',')}"
|
304
298
|
end
|
305
299
|
|
306
300
|
# @return [String] comando insert SQL formatado nethk (token)
|
307
301
|
def netbk_ins
|
308
|
-
"#{bnethk_ins}#{apiesc.novkx.map { |obj|
|
302
|
+
"#{bnethk_ins}#{apiesc.novkx.map { |obj| nethk_val(obj) }.join(',')}"
|
309
303
|
end
|
310
304
|
|
311
305
|
# @return [String] comando insert SQL formatado eos
|
312
306
|
def eost_ins
|
313
307
|
"insert #{BD}.neost(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
|
314
|
-
|
308
|
+
") VALUES#{apigm.novax.map { |obj| eost_val(obj) }.join(',')}"
|
315
309
|
end
|
316
310
|
|
317
311
|
# @return [String] comando insert SQL formatado det (trades)
|
318
312
|
def det_ins
|
319
|
-
"insert #{BD}.cdet(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj|
|
313
|
+
"insert #{BD}.cdet(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_val(obj) }.join(',')}"
|
320
314
|
end
|
321
315
|
|
322
316
|
# @return [String] comando insert SQL formatado del (ledger)
|
@@ -327,195 +321,152 @@ module Cns
|
|
327
321
|
# @return [String] comando insert SQL formatado ust (trades)
|
328
322
|
def ust_ins
|
329
323
|
"insert #{BD}.cust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
|
330
|
-
|
324
|
+
"VALUES#{apius.trades.map { |key, val| ust_val(key, val) }.join(',')}"
|
331
325
|
end
|
332
326
|
|
333
327
|
# @return [String] comando insert SQL formatado usl (ledger)
|
334
328
|
def usl_ins
|
335
329
|
"insert #{BD}.cusl(txid,refid,time,type,aclass,asset,amount,fee) " \
|
336
|
-
|
330
|
+
"VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
|
337
331
|
end
|
338
332
|
|
339
333
|
# @example (see Apibc#norml_es)
|
340
334
|
# @param [Hash] htx transacao norml etherscan
|
341
335
|
# @return [String] valores formatados netht (norml parte1)
|
342
|
-
def
|
343
|
-
"(#{Integer(htx[:blockNumber])}," \
|
344
|
-
"#{Integer(htx[:timeStamp])}," \
|
345
|
-
"'#{htx[:hash]}'," \
|
346
|
-
"#{Integer(htx[:nonce])}," \
|
347
|
-
"'#{htx[:blockHash]}'," \
|
348
|
-
"#{Integer(htx[:transactionIndex])}," \
|
349
|
-
"'#{htx[:from]}'," \
|
350
|
-
"'#{htx[:to]}'," \
|
351
|
-
"'#{htx[:iax]}'," \
|
352
|
-
"#{netht_2val(htx)}"
|
353
|
-
end
|
354
|
-
|
355
|
-
# @param (see netht_1val)
|
356
|
-
# @return [String] valores formatados netht (norml parte2)
|
357
|
-
def netht_2val(htx)
|
336
|
+
def netht_val(htx)
|
358
337
|
txr = htx[:txreceipt_status]
|
359
|
-
"cast('#{htx[:value]}' as numeric)," \
|
360
|
-
"cast('#{htx[:gas]}' as numeric)," \
|
361
|
-
"cast('#{htx[:gasPrice]}' as numeric)," \
|
362
|
-
"cast('#{htx[:gasUsed]}' as numeric)," \
|
363
|
-
"#{Integer(htx[:isError])}," \
|
364
|
-
"#{txr.length.zero? ? 'null' : txr}," \
|
365
|
-
"#{netht_3val(htx)}"
|
366
|
-
end
|
367
|
-
|
368
|
-
# @param (see netht_1val)
|
369
|
-
# @return [String] valores formatados netht (norml parte3)
|
370
|
-
def netht_3val(htx)
|
371
338
|
cta = htx[:contractAddress]
|
372
339
|
inp = htx[:input]
|
373
|
-
"#{
|
374
|
-
|
375
|
-
|
340
|
+
"(#{Integer(htx[:blockNumber])}," \
|
341
|
+
"#{Integer(htx[:timeStamp])}," \
|
342
|
+
"'#{htx[:hash]}'," \
|
343
|
+
"#{Integer(htx[:nonce])}," \
|
344
|
+
"'#{htx[:blockHash]}'," \
|
345
|
+
"#{Integer(htx[:transactionIndex])}," \
|
346
|
+
"'#{htx[:from]}'," \
|
347
|
+
"'#{htx[:to]}'," \
|
348
|
+
"'#{htx[:iax]}'," \
|
349
|
+
"cast('#{htx[:value]}' as numeric)," \
|
350
|
+
"cast('#{htx[:gas]}' as numeric)," \
|
351
|
+
"cast('#{htx[:gasPrice]}' as numeric)," \
|
352
|
+
"cast('#{htx[:gasUsed]}' as numeric)," \
|
353
|
+
"#{Integer(htx[:isError])}," \
|
354
|
+
"#{txr.empty? ? 'null' : txr}," \
|
355
|
+
"#{inp.empty? ? 'null' : "'#{inp}'"}," \
|
356
|
+
"#{cta.empty? ? 'null' : "'#{cta}'"}," \
|
357
|
+
"#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
|
376
358
|
end
|
377
359
|
|
378
360
|
# @example (see Apibc#inter_es)
|
379
361
|
# @param [Hash] htx transacao internas etherscan
|
380
362
|
# @return [String] valores formatados nethi (internas parte1)
|
381
|
-
def
|
363
|
+
def nethi_val(htx)
|
382
364
|
cta = htx[:contractAddress]
|
383
|
-
"(#{Integer(htx[:blockNumber])}," \
|
384
|
-
"#{Integer(htx[:timeStamp])}," \
|
385
|
-
"'#{htx[:hash]}'," \
|
386
|
-
"'#{htx[:from]}'," \
|
387
|
-
"'#{htx[:to]}'," \
|
388
|
-
"'#{htx[:iax]}'," \
|
389
|
-
"cast('#{htx[:value]}' as numeric)," \
|
390
|
-
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
391
|
-
"#{nethi_2val(htx)}"
|
392
|
-
end
|
393
|
-
|
394
|
-
# @param (see nethi_1val)
|
395
|
-
# @return [String] valores formatados nethi (internas parte2)
|
396
|
-
def nethi_2val(htx)
|
397
365
|
inp = htx[:input]
|
398
366
|
tid = htx[:traceId]
|
399
367
|
txr = htx[:errCode]
|
400
|
-
"#{
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
368
|
+
"(#{Integer(htx[:blockNumber])}," \
|
369
|
+
"#{Integer(htx[:timeStamp])}," \
|
370
|
+
"'#{htx[:hash]}'," \
|
371
|
+
"'#{htx[:from]}'," \
|
372
|
+
"'#{htx[:to]}'," \
|
373
|
+
"'#{htx[:iax]}'," \
|
374
|
+
"cast('#{htx[:value]}' as numeric)," \
|
375
|
+
"#{cta.empty? ? 'null' : "'#{cta}'"}," \
|
376
|
+
"#{inp.empty? ? 'null' : "'#{inp}'"}," \
|
377
|
+
"'#{htx[:type]}'," \
|
378
|
+
"cast('#{htx[:gas]}' as numeric)," \
|
379
|
+
"cast('#{htx[:gasUsed]}' as numeric)," \
|
380
|
+
"#{tid.empty? ? 'null' : "'#{tid}'"}," \
|
381
|
+
"#{Integer(htx[:isError])}," \
|
382
|
+
"#{txr.empty? ? 'null' : txr})"
|
407
383
|
end
|
408
384
|
|
409
385
|
# @example (see Apibc#block_es)
|
410
386
|
# @param [Hash] htx transacao block etherscan
|
411
387
|
# @return [String] valores formatados nethi (block parte1)
|
412
|
-
def
|
388
|
+
def nethp_val(htx)
|
413
389
|
"(#{Integer(htx[:blockNumber])}," \
|
414
|
-
|
415
|
-
|
416
|
-
|
390
|
+
"#{Integer(htx[:timeStamp])}," \
|
391
|
+
"cast('#{htx[:blockReward]}' as numeric)," \
|
392
|
+
"'#{htx[:iax]}')"
|
417
393
|
end
|
418
394
|
|
419
395
|
# @example (see Apibc#block_es)
|
420
396
|
# @param [Hash] htx transacao withdrawals etherscan
|
421
397
|
# @return [String] valores formatados nethi (withdrawals parte1)
|
422
|
-
def
|
398
|
+
def nethw_val(htx)
|
423
399
|
"(#{Integer(htx[:withdrawalIndex])}," \
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
400
|
+
"#{Integer(htx[:validatorIndex])}," \
|
401
|
+
"'#{htx[:address]}'," \
|
402
|
+
"cast('#{htx[:amount]}' as numeric)," \
|
403
|
+
"#{Integer(htx[:blockNumber])}," \
|
404
|
+
"#{Integer(htx[:timestamp])})"
|
429
405
|
end
|
430
406
|
|
431
407
|
# @example (see Apibc#token_es)
|
432
408
|
# @param [Hash] hkx token event etherscan
|
433
409
|
# @return [String] valores formatados nethk (token parte1)
|
434
|
-
def
|
435
|
-
"(#{Integer(hkx[:blockNumber])}," \
|
436
|
-
"#{Integer(hkx[:timeStamp])}," \
|
437
|
-
"'#{hkx[:hash]}'," \
|
438
|
-
"#{Integer(hkx[:nonce])}," \
|
439
|
-
"'#{hkx[:blockHash]}'," \
|
440
|
-
"#{Integer(hkx[:transactionIndex])}," \
|
441
|
-
"'#{hkx[:from]}'," \
|
442
|
-
"'#{hkx[:to]}'," \
|
443
|
-
"'#{hkx[:iax]}'," \
|
444
|
-
"#{nethk_2val(hkx)}"
|
445
|
-
end
|
446
|
-
|
447
|
-
# @param (see nethk_1val)
|
448
|
-
# @return [String] valores formatados nethk (token parte2)
|
449
|
-
def nethk_2val(hkx)
|
450
|
-
"cast('#{hkx[:value]}' as numeric)," \
|
451
|
-
"'#{hkx[:tokenName]}'," \
|
452
|
-
"'#{hkx[:tokenSymbol]}'," \
|
453
|
-
"#{Integer(hkx[:tokenDecimal])}," \
|
454
|
-
"cast('#{hkx[:gas]}' as numeric)," \
|
455
|
-
"cast('#{hkx[:gasPrice]}' as numeric)," \
|
456
|
-
"cast('#{hkx[:gasUsed]}' as numeric)," \
|
457
|
-
"#{nethk_3val(hkx)}"
|
458
|
-
end
|
459
|
-
|
460
|
-
# @param (see nethk_1val)
|
461
|
-
# @return [String] valores formatados nethk (token parte3)
|
462
|
-
def nethk_3val(hkx)
|
410
|
+
def nethk_val(hkx)
|
463
411
|
cta = hkx[:contractAddress]
|
464
412
|
inp = hkx[:input]
|
465
|
-
"#{
|
466
|
-
|
467
|
-
|
413
|
+
"(#{Integer(hkx[:blockNumber])}," \
|
414
|
+
"#{Integer(hkx[:timeStamp])}," \
|
415
|
+
"'#{hkx[:hash]}'," \
|
416
|
+
"#{Integer(hkx[:nonce])}," \
|
417
|
+
"'#{hkx[:blockHash]}'," \
|
418
|
+
"#{Integer(hkx[:transactionIndex])}," \
|
419
|
+
"'#{hkx[:from]}'," \
|
420
|
+
"'#{hkx[:to]}'," \
|
421
|
+
"'#{hkx[:iax]}'," \
|
422
|
+
"cast('#{hkx[:value]}' as numeric)," \
|
423
|
+
"'#{hkx[:tokenName]}'," \
|
424
|
+
"'#{hkx[:tokenSymbol]}'," \
|
425
|
+
"#{Integer(hkx[:tokenDecimal])}," \
|
426
|
+
"cast('#{hkx[:gas]}' as numeric)," \
|
427
|
+
"cast('#{hkx[:gasPrice]}' as numeric)," \
|
428
|
+
"cast('#{hkx[:gasUsed]}' as numeric)," \
|
429
|
+
"#{inp.empty? ? 'null' : "'#{inp}'"}," \
|
430
|
+
"#{cta.empty? ? 'null' : "'#{cta}'"}," \
|
431
|
+
"#{Integer(ops[:h][hkx[:blockNumber]] || 0)})"
|
468
432
|
end
|
469
433
|
|
470
434
|
# @example (see Apibc#ledger_gm)
|
471
435
|
# @param [Hash] hlx ledger greymass
|
472
436
|
# @return [String] valores formatados para insert eos (parte1)
|
473
|
-
def
|
437
|
+
def eost_val(hlx)
|
474
438
|
act = hlx[:action_trace][:act]
|
475
|
-
"(#{hlx[:global_action_seq]}," \
|
476
|
-
"#{hlx[:account_action_seq]}," \
|
477
|
-
"#{hlx[:block_num]}," \
|
478
|
-
"DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
|
479
|
-
"'#{act[:account]}'," \
|
480
|
-
"'#{act[:name]}'," \
|
481
|
-
"#{eost_2val(hlx, act)}"
|
482
|
-
end
|
483
|
-
|
484
|
-
# @param (see eost_1val)
|
485
|
-
# @param [Hash] act dados da acao
|
486
|
-
# @return [String] valores formatados para insert eos (parte2)
|
487
|
-
def eost_2val(hlx, act)
|
488
439
|
dat = act[:data]
|
489
440
|
qtd = dat[:quantity].to_s
|
490
441
|
str = dat[:memo].inspect
|
491
|
-
"
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
442
|
+
"(#{hlx[:global_action_seq]}," \
|
443
|
+
"#{hlx[:account_action_seq]}," \
|
444
|
+
"#{hlx[:block_num]}," \
|
445
|
+
"DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
|
446
|
+
"'#{act[:account]}'," \
|
447
|
+
"'#{act[:name]}'," \
|
448
|
+
"'#{dat[:from]}'," \
|
449
|
+
"'#{dat[:to]}'," \
|
450
|
+
"'#{hlx[:iax]}'," \
|
451
|
+
"#{qtd.to_d},'#{qtd[/[[:upper:]]+/]}'," \
|
452
|
+
"nullif('#{str.gsub(/['"]/, '')}','nil')," \
|
453
|
+
"#{ops[:h][String(hlx[:itx])] || 0})"
|
497
454
|
end
|
498
455
|
|
499
456
|
# @example (see Apice#trades_de)
|
500
457
|
# @param [Hash] htx trade bitcoinde
|
501
458
|
# @return [String] valores formatados det (trades parte1)
|
502
|
-
def
|
459
|
+
def det_val(htx)
|
503
460
|
"('#{htx[:trade_id]}'," \
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
'cast(' \
|
514
|
-
"#{htx[:type] == 'buy' ? htx[:amount_currency_to_trade_after_fee] : "-#{htx[:amount_currency_to_trade]}"}" \
|
515
|
-
' as numeric),' \
|
516
|
-
"cast(#{htx[:volume_currency_to_pay_after_fee]} as numeric)," \
|
517
|
-
"DATETIME(TIMESTAMP('#{htx[:trade_marked_as_paid_at]}'))," \
|
518
|
-
"#{Integer(ops[:h][htx[:trade_id]] || 0)})"
|
461
|
+
"DATETIME(TIMESTAMP('#{htx[:successfully_finished_at]}'))," \
|
462
|
+
"'#{htx[:type]}'," \
|
463
|
+
"'#{htx[:trading_partner_information][:username]}'," \
|
464
|
+
'cast(' \
|
465
|
+
"#{htx[:type] == 'buy' ? htx[:amount_currency_to_trade_after_fee] : "-#{htx[:amount_currency_to_trade]}"} " \
|
466
|
+
'as numeric),' \
|
467
|
+
"cast(#{htx[:volume_currency_to_pay_after_fee]} as numeric)," \
|
468
|
+
"DATETIME(TIMESTAMP('#{htx[:trade_marked_as_paid_at]}'))," \
|
469
|
+
"#{Integer(ops[:h][htx[:trade_id]] || 0)})"
|
519
470
|
end
|
520
471
|
|
521
472
|
# @example (see Apice#deposits_de)
|
@@ -525,208 +476,50 @@ module Cns
|
|
525
476
|
def del_val(hlx)
|
526
477
|
tip = hlx[:tp]
|
527
478
|
"(#{hlx[:txid]}," \
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
479
|
+
"DATETIME(TIMESTAMP('#{hlx[:time].iso8601}'))," \
|
480
|
+
"'#{tip}'," \
|
481
|
+
"'#{hlx[:add]}'," \
|
482
|
+
"'#{hlx[:moe]}'," \
|
483
|
+
"cast(#{tip == 'withdrawal' ? '-' : ''}#{hlx[:qt]} as numeric)," \
|
484
|
+
"cast(#{hlx[:fee]} as numeric))"
|
534
485
|
end
|
535
486
|
|
536
487
|
# @example (see Apice#trades_us)
|
537
488
|
# @param [String] idx identificador transacao
|
538
489
|
# @param [Hash] htx trade kraken
|
539
490
|
# @return [String] valores formatados ust (trades parte1)
|
540
|
-
def
|
541
|
-
"('#{idx}'," \
|
542
|
-
"'#{htx[:ordertxid]}'," \
|
543
|
-
"'#{htx[:pair]}'," \
|
544
|
-
"PARSE_DATETIME('%s', '#{String(htx[:time].round)}')," \
|
545
|
-
"'#{htx[:type]}'," \
|
546
|
-
"'#{htx[:ordertype]}'," \
|
547
|
-
"cast(#{htx[:price]} as numeric)," \
|
548
|
-
"cast(#{htx[:cost]} as numeric)," \
|
549
|
-
"cast(#{htx[:fee]} as numeric)," \
|
550
|
-
"#{ust_2val(idx, htx)}"
|
551
|
-
end
|
552
|
-
|
553
|
-
# @param (see ust_1val)
|
554
|
-
# @return [String] valores formatados ust (trades parte2)
|
555
|
-
def ust_2val(idx, htx)
|
491
|
+
def ust_val(idx, htx)
|
556
492
|
msc = htx[:misc].to_s
|
557
|
-
"
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
493
|
+
"('#{idx}'," \
|
494
|
+
"'#{htx[:ordertxid]}'," \
|
495
|
+
"'#{htx[:pair]}'," \
|
496
|
+
"PARSE_DATETIME('%s', '#{String(htx[:time].round)}')," \
|
497
|
+
"'#{htx[:type]}'," \
|
498
|
+
"'#{htx[:ordertype]}'," \
|
499
|
+
"cast(#{htx[:price]} as numeric)," \
|
500
|
+
"cast(#{htx[:cost]} as numeric)," \
|
501
|
+
"cast(#{htx[:fee]} as numeric)," \
|
502
|
+
"cast(#{htx[:vol]} as numeric)," \
|
503
|
+
"cast(#{htx[:margin]} as numeric)," \
|
504
|
+
"#{msc.empty? ? 'null' : "'#{msc}'"}," \
|
505
|
+
"'#{apius.ledger.select { |_, val| val[:refid] == idx }.keys.join(',') || ''}'," \
|
506
|
+
"#{Integer(ops[:h][idx] || 0)})"
|
562
507
|
end
|
563
508
|
|
564
509
|
# @example (see Apice#ledger_us)
|
565
|
-
# @param idx (see
|
510
|
+
# @param idx (see ust_val)
|
566
511
|
# @param [Hash] hlx ledger kraken
|
567
512
|
# @return [String] valores formatados usl (ledger)
|
568
513
|
def usl_val(idx, hlx)
|
569
514
|
acl = hlx[:aclass].to_s
|
570
515
|
"('#{idx}'," \
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
end
|
579
|
-
|
580
|
-
# @return [Paymium] API exchange paymium
|
581
|
-
# def apifr
|
582
|
-
# @apifr ||= Paymium.new(
|
583
|
-
# {
|
584
|
-
# sl: sql("select * from #{BD}.frsl")[0],
|
585
|
-
# nl: sql("select uuid txid,tipo,valor,moe,time,dias from #{BD}.fr order by time,1")
|
586
|
-
# },
|
587
|
-
# ops
|
588
|
-
# )
|
589
|
-
# end
|
590
|
-
#
|
591
|
-
# @return [TheRock] API exchange therock
|
592
|
-
# def apimt
|
593
|
-
# @apimt ||= TheRock.new(
|
594
|
-
# {
|
595
|
-
# sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.mtsl")[0],
|
596
|
-
# nl: sql("select id txid,time,type,valor,moe,pair,note,dias from #{BD}.mt order by time,1")
|
597
|
-
# },
|
598
|
-
# ops
|
599
|
-
# )
|
600
|
-
# end
|
601
|
-
#
|
602
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
603
|
-
# def frl_ins
|
604
|
-
# "insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
|
605
|
-
# end
|
606
|
-
#
|
607
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
608
|
-
# def mtl_ins
|
609
|
-
# "insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
|
610
|
-
# "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
|
611
|
-
# end
|
612
|
-
#
|
613
|
-
# @example (see Apice#ledger_fr)
|
614
|
-
# @param [Hash] hlx ledger paymium
|
615
|
-
# @return [String] valores formatados frl (ledger)
|
616
|
-
# def frl_val(hlx)
|
617
|
-
# uid = hlx[:uuid]
|
618
|
-
# "('#{uid}'," \
|
619
|
-
# "'#{hlx[:name]}'," \
|
620
|
-
# "cast(#{hlx[:amount]} as numeric)," \
|
621
|
-
# "'#{hlx[:currency]}'," \
|
622
|
-
# "PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
|
623
|
-
# "#{Integer(ops[:h][uid] || 0)})"
|
624
|
-
# end
|
625
|
-
#
|
626
|
-
# @example (see Apice#ledger_mt)
|
627
|
-
# @param [Hash] hlx ledger therock
|
628
|
-
# @return [String] valores formatados mtl (ledger parte1)
|
629
|
-
# def mtl_1val(hlx)
|
630
|
-
# fid = hlx[:fund_id].to_s
|
631
|
-
# "(#{hlx[:id]}," \
|
632
|
-
# "DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
|
633
|
-
# "'#{hlx[:type]}'," \
|
634
|
-
# "cast(#{hlx[:price]} as numeric)," \
|
635
|
-
# "'#{hlx[:currency]}'," \
|
636
|
-
# "#{fid.empty? ? 'null' : "'#{fid}'"}," \
|
637
|
-
# "#{mtl_2val(hlx)}"
|
638
|
-
# end
|
639
|
-
#
|
640
|
-
# @param (see mtl_1val)
|
641
|
-
# @return [String] valores formatados mtl (ledger parte2)
|
642
|
-
# def mtl_2val(hlx)
|
643
|
-
# nte = hlx[:note].to_s
|
644
|
-
# tid = hlx[:trade_id].to_s
|
645
|
-
# "#{nte.empty? ? 'null' : "'#{nte}'"}," \
|
646
|
-
# "#{tid.empty? ? 'null' : tid.to_s}," \
|
647
|
-
# "#{Integer(ops[:h][String(hlx[:id])] || 0)})"
|
648
|
-
# end
|
649
|
-
#
|
650
|
-
# @example (see Beaconchain#formata_saldos)
|
651
|
-
# @param (see Beaconchain#formata_saldos)
|
652
|
-
# @return [String] valores formatados etht (norml parte1)
|
653
|
-
# def eth2bh_1val(htb)
|
654
|
-
# "(#{Integer(htb[:balance])}," \
|
655
|
-
# "#{Integer(htb[:effectivebalance])}," \
|
656
|
-
# "#{Integer(htb[:epoch])}," \
|
657
|
-
# "#{Integer(htb[:validatorindex])})"
|
658
|
-
# end
|
659
|
-
# @return [Beaconchain] API blockchain ETH2
|
660
|
-
# def apibc
|
661
|
-
# @apibc ||= Beaconchain.new(
|
662
|
-
# {
|
663
|
-
# wb: sql("select * from #{BD}.walletEth2 order by 1"),
|
664
|
-
# nb: sql("select itx,iax from #{BD}.eth2bhx")
|
665
|
-
# },
|
666
|
-
# ops
|
667
|
-
# )
|
668
|
-
# end
|
669
|
-
# @return [String] comando insert SQL formatado eth2bh
|
670
|
-
# def eth2bh_ins
|
671
|
-
# "insert #{BD}.eth2bh(balance,effectivebalance,epoch,validatorindex" \
|
672
|
-
# ") VALUES#{apibc.nov[0..1000].map { |obj| eth2bh_1val(obj) }.join(',')}"
|
673
|
-
# end
|
674
|
-
# insere transacoes exchange paymium/therock novas na tabela fr/mt (ledger)
|
675
|
-
# def processa_frmt
|
676
|
-
# puts(format("%<n>4i LEDGER\tPAYMIUM\t\tINSERIDAS fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
|
677
|
-
# puts(format("%<n>4i LEDGER\tTHEROCK\t\tINSERIDAS mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
|
678
|
-
# end
|
679
|
-
# insere historico sados novos na tabela eth2bh
|
680
|
-
# def processa_bc
|
681
|
-
# puts(format("%<n>4i ATTESTATIONS INSERIDAS eth2at", n: apibc.novtx.empty? ? 0 : dml(eth2at_ins)))
|
682
|
-
# puts(format("%<n>4i PROPOSALS INSERIDAS eth2pr", n: apibc.novkx.empty? ? 0 : dml(eth2pr_ins)))
|
683
|
-
# puts(format("%<n>4i BALANCES\tETH2\t\tINSERIDOS eth2bh", n: apibc.nov.empty? ? 0 : dml(eth2bh_ins)))
|
684
|
-
# end
|
685
|
-
# def eth2at_ins
|
686
|
-
# "insert #{BD}.eth2at(attesterslot,committeeindex,epoch,inclusionslot,status,validatorindex" \
|
687
|
-
# ") VALUES#{apibc.novtx.map { |obj| eth2at_1val(obj) }.join(',')}"
|
688
|
-
# end
|
689
|
-
# def eth2pr_ins
|
690
|
-
# "insert #{BD}.eth2pr(attestationscount,attesterslashingscount,blockroot,depositscount,epoch," \
|
691
|
-
# 'eth1data_blockhash,eth1data_depositcount,eth1data_depositroot,graffiti,graffiti_text,parentroot,' \
|
692
|
-
# 'proposer,proposerslashingscount,randaoreveal,signature,slot,stateroot,status,voluntaryexitscount' \
|
693
|
-
# ") VALUES#{apibc.novkx.map { |obj| eth2pr_1val(obj) }.join(',')}"
|
694
|
-
# end
|
695
|
-
# def eth2at_1val(htx)
|
696
|
-
# "(#{Integer(htx[:attesterslot])}," \
|
697
|
-
# "#{Integer(htx[:committeeindex])}," \
|
698
|
-
# "#{Integer(htx[:epoch])}," \
|
699
|
-
# "#{Integer(htx[:inclusionslot])}," \
|
700
|
-
# "#{Integer(htx[:status])}," \
|
701
|
-
# "#{Integer(htx[:validatorindex])})"
|
702
|
-
# end
|
703
|
-
# def eth2pr_1val(htx)
|
704
|
-
# "(#{Integer(htx[:attestationscount])}," \
|
705
|
-
# "#{Integer(htx[:attesterslashingscount])}," \
|
706
|
-
# "'#{htx[:blockroot]}'," \
|
707
|
-
# "#{Integer(htx[:depositscount])}," \
|
708
|
-
# "#{Integer(htx[:epoch])}," \
|
709
|
-
# "'#{htx[:eth1data_blockhash]}'," \
|
710
|
-
# "#{eth2pr_2val(htx)}"
|
711
|
-
# end
|
712
|
-
# def eth2pr_2val(htx)
|
713
|
-
# grf = htx[:graffiti_text]
|
714
|
-
# "#{Integer(htx[:eth1data_depositcount])}," \
|
715
|
-
# "'#{htx[:eth1data_depositroot]}'," \
|
716
|
-
# "'#{htx[:graffiti]}'," \
|
717
|
-
# "#{grf.length.zero? ? 'null' : "'#{grf}'"}," \
|
718
|
-
# "'#{htx[:parentroot]}'," \
|
719
|
-
# "#{Integer(htx[:proposer])}," \
|
720
|
-
# "#{eth2pr_3val(htx)}"
|
721
|
-
# end
|
722
|
-
# def eth2pr_3val(htx)
|
723
|
-
# "#{Integer(htx[:proposerslashingscount])}," \
|
724
|
-
# "'#{htx[:randaoreveal]}'," \
|
725
|
-
# "'#{htx[:signature]}'," \
|
726
|
-
# "#{Integer(htx[:slot])}," \
|
727
|
-
# "'#{htx[:stateroot]}'," \
|
728
|
-
# "#{Integer(htx[:status])}," \
|
729
|
-
# "#{Integer(htx[:voluntaryexitscount])})"
|
730
|
-
# end
|
516
|
+
"'#{hlx[:refid]}'," \
|
517
|
+
"PARSE_DATETIME('%s', '#{String(hlx[:time].round)}')," \
|
518
|
+
"'#{hlx[:type]}'," \
|
519
|
+
"#{acl.empty? ? 'null' : "'#{acl}'"}," \
|
520
|
+
"'#{hlx[:asset]}'," \
|
521
|
+
"cast(#{hlx[:amount]} as numeric)," \
|
522
|
+
"cast(#{hlx[:fee]} as numeric))"
|
523
|
+
end
|
731
524
|
end
|
732
525
|
end
|