cns 0.3.4 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- 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
- data/ruby-lint.yml +10 -0
- metadata +8 -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
data/lib/cns/bigquery1.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require('google/cloud/bigquery')
|
4
|
-
require('bigdecimal/util')
|
5
|
-
|
6
|
-
# @author Hernani Rodrigues Vaz
|
7
|
-
module Cns
|
8
|
-
BD = 'hernanirvaz.coins'
|
9
|
-
|
10
|
-
# (see Bigquery)
|
11
|
-
class Bigquery
|
12
|
-
# @return [Google::Cloud::Bigquery] API bigquery
|
13
|
-
attr_reader :api
|
14
|
-
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
|
15
|
-
attr_reader :job
|
16
|
-
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
17
|
-
attr_reader :ops
|
18
|
-
# @return (see sql)
|
19
|
-
attr_reader :sqr
|
20
|
-
|
21
|
-
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
22
|
-
# @option pop [Hash] :h ({}) configuracao ajuste reposicionamento temporal
|
23
|
-
# @option pop [Boolean] :v (false) mostra transacoes trades & ledger?
|
24
|
-
# @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
|
25
|
-
# @return [Bigquery] API bigquery
|
26
|
-
def initialize(pop)
|
27
|
-
# usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
|
28
|
-
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
29
|
-
@api = Google::Cloud::Bigquery.new
|
30
|
-
@ops = pop
|
31
|
-
end
|
32
|
-
|
33
|
-
# mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain & bigquery
|
34
|
-
def mostra_tudo
|
35
|
-
apius.mostra_resumo
|
36
|
-
apide.mostra_resumo
|
37
|
-
#apifr.mostra_resumo
|
38
|
-
#apimt.mostra_resumo
|
39
|
-
apies.mostra_resumo
|
40
|
-
apigm.mostra_resumo
|
41
|
-
#apibc.mostra_resumo
|
42
|
-
end
|
43
|
-
|
44
|
-
# insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain no bigquery
|
45
|
-
def processa_tudo
|
46
|
-
processa_us
|
47
|
-
processa_de
|
48
|
-
#processa_frmt
|
49
|
-
processa_eth
|
50
|
-
processa_eos
|
51
|
-
#processa_bc
|
52
|
-
end
|
53
|
-
|
54
|
-
# insere transacoes blockchain novas nas tabelas etht (norml), ethi (internas), ethp (block), ethk (token)
|
55
|
-
def processa_eth
|
56
|
-
puts(format("%<n>4i TRANSACOES ETH NORMAIS\tINSERIDAS etht", n: apies.novtx.empty? ? 0 : dml(etht_ins)))
|
57
|
-
puts(format("%<n>4i TRANSACOES ETH INTERNAS\tINSERIDAS ethi", n: apies.novix.empty? ? 0 : dml(ethi_ins)))
|
58
|
-
puts(format("%<n>4i TRANSACOES ETH BLOCK\tINSERIDAS ethp", n: apies.novpx.empty? ? 0 : dml(ethp_ins)))
|
59
|
-
puts(format("%<n>4i TRANSACOES ETH WITHDRAWALS\tINSERIDAS ethw", n: apies.novwx.empty? ? 0 : dml(ethw_ins)))
|
60
|
-
puts(format("%<n>4i TOKENS\tETH\t\tINSERIDAS ethk", n: apies.novkx.empty? ? 0 : dml(ethk_ins)))
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
# insere transacoes exchange kraken novas nas tabelas ust (trades), usl (ledger)
|
66
|
-
def processa_us
|
67
|
-
puts(format("%<n>4i TRADES\tKRAKEN\t\tINSERIDAS ust", n: apius.trades.empty? ? 0 : dml(ust_ins)))
|
68
|
-
puts(format("%<n>4i LEDGER\tKRAKEN\t\tINSERIDAS usl", n: apius.ledger.empty? ? 0 : dml(usl_ins)))
|
69
|
-
end
|
70
|
-
|
71
|
-
# insere transacoes exchange bitcoinde novas nas tabelas det (trades), del (ledger)
|
72
|
-
def processa_de
|
73
|
-
puts(format("%<n>4i TRADES\tBITCOINDE\tINSERIDAS det", n: apide.trades.empty? ? 0 : dml(det_ins)))
|
74
|
-
puts(format("%<n>4i LEDGER\tBITCOINDE\tINSERIDAS del", n: apide.ledger.empty? ? 0 : dml(del_ins)))
|
75
|
-
end
|
76
|
-
|
77
|
-
# insere transacoes exchange paymium/therock novas na tabela fr/mt (ledger)
|
78
|
-
def processa_frmt
|
79
|
-
puts(format("%<n>4i LEDGER\tPAYMIUM\t\tINSERIDAS fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
|
80
|
-
puts(format("%<n>4i LEDGER\tTHEROCK\t\tINSERIDAS mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
|
81
|
-
end
|
82
|
-
|
83
|
-
# insere transacoes blockchain novas na tabela eos
|
84
|
-
def processa_eos
|
85
|
-
puts(format("%<n>4i TRANSACOES\tEOS\t\tINSERIDAS eos ", n: apigm.novax.empty? ? 0 : dml(eost_ins)))
|
86
|
-
end
|
87
|
-
|
88
|
-
# insere historico sados novos na tabela eth2bh
|
89
|
-
def processa_bc
|
90
|
-
# puts(format("%<n>4i ATTESTATIONS INSERIDAS #{BD}.eth2at", n: apibc.novtx.empty? ? 0 : dml(eth2at_ins)))
|
91
|
-
# puts(format("%<n>4i PROPOSALS INSERIDAS #{BD}.eth2pr", n: apibc.novkx.empty? ? 0 : dml(eth2pr_ins)))
|
92
|
-
puts(format("%<n>4i BALANCES\tETH2\t\tINSERIDOS eth2bh", n: apibc.nov.empty? ? 0 : dml(eth2bh_ins)))
|
93
|
-
end
|
94
|
-
|
95
|
-
# cria job bigquery & verifica execucao
|
96
|
-
#
|
97
|
-
# @param cmd (see sql)
|
98
|
-
# @return [Boolean] job ok?
|
99
|
-
def job?(cmd)
|
100
|
-
@job = api.query_job(cmd)
|
101
|
-
job.wait_until_done!
|
102
|
-
fld = job.failed?
|
103
|
-
puts(job.error['message']) if fld
|
104
|
-
fld
|
105
|
-
end
|
106
|
-
|
107
|
-
# cria Structured Query Language (SQL) job bigquery
|
108
|
-
#
|
109
|
-
# @param [String] cmd comando SQL a executar
|
110
|
-
# @param [String] res resultado quando SQL tem erro
|
111
|
-
# @return [Google::Cloud::Bigquery::Data] resultado do SQL
|
112
|
-
def sql(cmd, res = [])
|
113
|
-
@sqr = job?(cmd) ? res : job.data
|
114
|
-
end
|
115
|
-
|
116
|
-
# cria Data Manipulation Language (DML) job bigquery
|
117
|
-
#
|
118
|
-
# @param cmd (see sql)
|
119
|
-
# @return [Integer] numero linhas afetadas
|
120
|
-
def dml(cmd)
|
121
|
-
job?(cmd) ? 0 : job.num_dml_affected_rows
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/lib/cns/bigquery2.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @author Hernani Rodrigues Vaz
|
4
|
-
module Cns
|
5
|
-
# (see Bigquery)
|
6
|
-
class Bigquery
|
7
|
-
private
|
8
|
-
|
9
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
10
|
-
def mtl_ins
|
11
|
-
"insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
|
12
|
-
"VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
|
13
|
-
end
|
14
|
-
|
15
|
-
# @return [String] comando insert SQL formatado eth2bh
|
16
|
-
def eth2bh_ins
|
17
|
-
"insert #{BD}.eth2bh(balance,effectivebalance,epoch,validatorindex" \
|
18
|
-
") VALUES#{apibc.nov[0..1000].map { |obj| eth2bh_1val(obj) }.join(',')}"
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return [Etherscan] API blockchain ETH
|
22
|
-
def apies
|
23
|
-
@apies ||= Etherscan.new(
|
24
|
-
{
|
25
|
-
wb: sql("select * from #{BD}.walletEth order by 2"),
|
26
|
-
nt: sql("select itx,iax from #{BD}.ethtx"),
|
27
|
-
ni: sql("select itx,iax from #{BD}.ethix"),
|
28
|
-
np: sql("select itx,iax from #{BD}.ethpx"),
|
29
|
-
nw: sql("select itx,iax from #{BD}.ethwx"),
|
30
|
-
nk: sql("select itx,iax from #{BD}.ethkx")
|
31
|
-
},
|
32
|
-
ops
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [Greymass] API blockchain EOS
|
37
|
-
def apigm
|
38
|
-
@apigm ||= Greymass.new(
|
39
|
-
{
|
40
|
-
wb: sql("select * from #{BD}.walletEos order by 2"),
|
41
|
-
nt: sql("select itx,iax from #{BD}.eostx")
|
42
|
-
},
|
43
|
-
ops
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
# @return [Beaconchain] API blockchain ETH2
|
48
|
-
def apibc
|
49
|
-
@apibc ||= Beaconchain.new(
|
50
|
-
{
|
51
|
-
wb: sql("select * from #{BD}.walletEth2 order by 1"),
|
52
|
-
nb: sql("select itx,iax from #{BD}.eth2bhx")
|
53
|
-
},
|
54
|
-
ops
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
# @return [Kraken] API exchange kraken
|
59
|
-
def apius
|
60
|
-
@apius ||= Kraken.new(
|
61
|
-
{
|
62
|
-
sl: sql("select sum(btc) xxbt,sum(eth) xeth,sum(eos) eos,sum(eur) zeur from #{BD}.ussl")[0],
|
63
|
-
nt: sql("select * from #{BD}.ustx order by time,txid"),
|
64
|
-
nl: sql("select * from #{BD}.uslx order by time,txid")
|
65
|
-
},
|
66
|
-
ops
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
# @return [Bitcoinde] API exchange bitcoinde
|
71
|
-
def apide
|
72
|
-
@apide ||= Bitcoinde.new(
|
73
|
-
{
|
74
|
-
sl: sql("select sum(btc) btc from #{BD}.desl")[0],
|
75
|
-
nt: sql("select * from #{BD}.detx order by time,txid"),
|
76
|
-
nl: sql("select * from #{BD}.delx order by time,txid")
|
77
|
-
},
|
78
|
-
ops
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
# @return [Paymium] API exchange paymium
|
83
|
-
def apifr
|
84
|
-
@apifr ||= Paymium.new(
|
85
|
-
{
|
86
|
-
sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.frsl")[0],
|
87
|
-
nl: sql("select * from #{BD}.frlx order by time,txid")
|
88
|
-
},
|
89
|
-
ops
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
# @return [TheRock] API exchange therock
|
94
|
-
def apimt
|
95
|
-
@apimt ||= TheRock.new(
|
96
|
-
{
|
97
|
-
sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.mtsl")[0],
|
98
|
-
nl: sql("select * from #{BD}.mtlx order by time,txid")
|
99
|
-
},
|
100
|
-
ops
|
101
|
-
)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/lib/cns/bigquery3.rb
DELETED
@@ -1,268 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require('google/cloud/bigquery')
|
4
|
-
require('bigdecimal/util')
|
5
|
-
|
6
|
-
# @author Hernani Rodrigues Vaz
|
7
|
-
module Cns
|
8
|
-
# (see Bigquery)
|
9
|
-
class Bigquery
|
10
|
-
private
|
11
|
-
|
12
|
-
# @return [String] comando insert SQL formatado etht (norml)
|
13
|
-
def etht_ins
|
14
|
-
"insert #{BD}.etht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
15
|
-
'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias' \
|
16
|
-
") VALUES#{apies.novtx.map { |obj| etht_1val(obj) }.join(',')}"
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [String] comando insert SQL formatado ethi (internas)
|
20
|
-
def ethi_ins
|
21
|
-
"insert #{BD}.ethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
|
22
|
-
'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode' \
|
23
|
-
") VALUES#{apies.novix.map { |obj| ethi_1val(obj) }.join(',')}"
|
24
|
-
end
|
25
|
-
|
26
|
-
# @return [String] comando insert SQL formatado ethp (block)
|
27
|
-
def ethp_ins
|
28
|
-
"insert #{BD}.ethp(blocknumber,timestamp,blockreward,iax" \
|
29
|
-
") VALUES#{apies.novpx.map { |obj| ethp_1val(obj) }.join(',')}"
|
30
|
-
end
|
31
|
-
|
32
|
-
# @return [String] comando insert SQL formatado ethw (withdrawals)
|
33
|
-
def ethw_ins
|
34
|
-
"insert #{BD}.ethw(withdrawalindex,validatorindex,address,amount,blocknumber,timestamp" \
|
35
|
-
") VALUES#{apies.novwx.map { |obj| ethw_1val(obj) }.join(',')}"
|
36
|
-
end
|
37
|
-
|
38
|
-
# @return [String] comando insert SQL formatado ethk (token)
|
39
|
-
def ethk_ins
|
40
|
-
"insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
41
|
-
'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
|
42
|
-
") VALUES#{apies.novkx.map { |obj| ethk_1val(obj) }.join(',')}"
|
43
|
-
end
|
44
|
-
|
45
|
-
# @return [String] comando insert SQL formatado eos
|
46
|
-
def eost_ins
|
47
|
-
"insert #{BD}.eos(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
|
48
|
-
") VALUES#{apigm.novax.map { |obj| eost_1val(obj) }.join(',')}"
|
49
|
-
end
|
50
|
-
|
51
|
-
# @example (see Beaconchain#formata_saldos)
|
52
|
-
# @param (see Beaconchain#formata_saldos)
|
53
|
-
# @return [String] valores formatados etht (norml parte1)
|
54
|
-
def eth2bh_1val(htb)
|
55
|
-
"(#{Integer(htb[:balance])}," \
|
56
|
-
"#{Integer(htb[:effectivebalance])}," \
|
57
|
-
"#{Integer(htb[:epoch])}," \
|
58
|
-
"#{Integer(htb[:validatorindex])})"
|
59
|
-
end
|
60
|
-
|
61
|
-
# @example (see Apibc#norml_es)
|
62
|
-
# @param [Hash] htx transacao norml etherscan
|
63
|
-
# @return [String] valores formatados etht (norml parte1)
|
64
|
-
def etht_1val(htx)
|
65
|
-
"(#{Integer(htx[:blockNumber])}," \
|
66
|
-
"#{Integer(htx[:timeStamp])}," \
|
67
|
-
"'#{htx[:hash]}'," \
|
68
|
-
"#{Integer(htx[:nonce])}," \
|
69
|
-
"'#{htx[:blockHash]}'," \
|
70
|
-
"#{Integer(htx[:transactionIndex])}," \
|
71
|
-
"'#{htx[:from]}'," \
|
72
|
-
"'#{htx[:to]}'," \
|
73
|
-
"'#{htx[:iax]}'," \
|
74
|
-
"#{etht_2val(htx)}"
|
75
|
-
end
|
76
|
-
|
77
|
-
# @param (see etht_1val)
|
78
|
-
# @return [String] valores formatados etht (norml parte2)
|
79
|
-
def etht_2val(htx)
|
80
|
-
txr = htx[:txreceipt_status]
|
81
|
-
"cast('#{htx[:value]}' as numeric)," \
|
82
|
-
"cast('#{htx[:gas]}' as numeric)," \
|
83
|
-
"cast('#{htx[:gasPrice]}' as numeric)," \
|
84
|
-
"cast('#{htx[:gasUsed]}' as numeric)," \
|
85
|
-
"#{Integer(htx[:isError])}," \
|
86
|
-
"#{txr.length.zero? ? 'null' : txr}," \
|
87
|
-
"#{etht_3val(htx)}"
|
88
|
-
end
|
89
|
-
|
90
|
-
# @param (see etht_1val)
|
91
|
-
# @return [String] valores formatados etht (norml parte3)
|
92
|
-
def etht_3val(htx)
|
93
|
-
cta = htx[:contractAddress]
|
94
|
-
inp = htx[:input]
|
95
|
-
"#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
|
96
|
-
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
97
|
-
"#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
|
98
|
-
end
|
99
|
-
|
100
|
-
# @example (see Apibc#inter_es)
|
101
|
-
# @param [Hash] htx transacao internas etherscan
|
102
|
-
# @return [String] valores formatados ethi (internas parte1)
|
103
|
-
def ethi_1val(htx)
|
104
|
-
cta = htx[:contractAddress]
|
105
|
-
"(#{Integer(htx[:blockNumber])}," \
|
106
|
-
"#{Integer(htx[:timeStamp])}," \
|
107
|
-
"'#{htx[:hash]}'," \
|
108
|
-
"'#{htx[:from]}'," \
|
109
|
-
"'#{htx[:to]}'," \
|
110
|
-
"'#{htx[:iax]}'," \
|
111
|
-
"cast('#{htx[:value]}' as numeric)," \
|
112
|
-
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
113
|
-
"#{ethi_2val(htx)}"
|
114
|
-
end
|
115
|
-
|
116
|
-
# @param (see ethi_1val)
|
117
|
-
# @return [String] valores formatados ethi (internas parte2)
|
118
|
-
def ethi_2val(htx)
|
119
|
-
inp = htx[:input]
|
120
|
-
tid = htx[:traceId]
|
121
|
-
txr = htx[:errCode]
|
122
|
-
"#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
|
123
|
-
"'#{htx[:type]}'," \
|
124
|
-
"cast('#{htx[:gas]}' as numeric)," \
|
125
|
-
"cast('#{htx[:gasUsed]}' as numeric)," \
|
126
|
-
"#{tid.length.zero? ? 'null' : "'#{tid}'"}," \
|
127
|
-
"#{Integer(htx[:isError])}," \
|
128
|
-
"#{txr.length.zero? ? 'null' : txr})"
|
129
|
-
end
|
130
|
-
|
131
|
-
# @example (see Apibc#block_es)
|
132
|
-
# @param [Hash] htx transacao block etherscan
|
133
|
-
# @return [String] valores formatados ethi (block parte1)
|
134
|
-
def ethp_1val(htx)
|
135
|
-
"(#{Integer(htx[:blockNumber])}," \
|
136
|
-
"#{Integer(htx[:timeStamp])}," \
|
137
|
-
"cast('#{htx[:blockReward]}' as numeric)," \
|
138
|
-
"'#{htx[:iax]}')"
|
139
|
-
end
|
140
|
-
|
141
|
-
# @example (see Apibc#block_es)
|
142
|
-
# @param [Hash] htx transacao withdrawals etherscan
|
143
|
-
# @return [String] valores formatados ethi (withdrawals parte1)
|
144
|
-
def ethw_1val(htx)
|
145
|
-
"(#{Integer(htx[:withdrawalIndex])}," \
|
146
|
-
"#{Integer(htx[:validatorIndex])}," \
|
147
|
-
"'#{htx[:address]}'," \
|
148
|
-
"cast('#{htx[:amount]}' as numeric)," \
|
149
|
-
"#{Integer(htx[:blockNumber])}," \
|
150
|
-
"#{Integer(htx[:timestamp])})"
|
151
|
-
end
|
152
|
-
|
153
|
-
# @example (see Apibc#token_es)
|
154
|
-
# @param [Hash] hkx token event etherscan
|
155
|
-
# @return [String] valores formatados ethk (token parte1)
|
156
|
-
def ethk_1val(hkx)
|
157
|
-
"(#{Integer(hkx[:blockNumber])}," \
|
158
|
-
"#{Integer(hkx[:timeStamp])}," \
|
159
|
-
"'#{hkx[:hash]}'," \
|
160
|
-
"#{Integer(hkx[:nonce])}," \
|
161
|
-
"'#{hkx[:blockHash]}'," \
|
162
|
-
"#{Integer(hkx[:transactionIndex])}," \
|
163
|
-
"'#{hkx[:from]}'," \
|
164
|
-
"'#{hkx[:to]}'," \
|
165
|
-
"'#{hkx[:iax]}'," \
|
166
|
-
"#{ethk_2val(hkx)}"
|
167
|
-
end
|
168
|
-
|
169
|
-
# @param (see ethk_1val)
|
170
|
-
# @return [String] valores formatados ethk (token parte2)
|
171
|
-
def ethk_2val(hkx)
|
172
|
-
"cast('#{hkx[:value]}' as numeric)," \
|
173
|
-
"'#{hkx[:tokenName]}'," \
|
174
|
-
"'#{hkx[:tokenSymbol]}'," \
|
175
|
-
"#{Integer(hkx[:tokenDecimal])}," \
|
176
|
-
"cast('#{hkx[:gas]}' as numeric)," \
|
177
|
-
"cast('#{hkx[:gasPrice]}' as numeric)," \
|
178
|
-
"cast('#{hkx[:gasUsed]}' as numeric)," \
|
179
|
-
"#{ethk_3val(hkx)}"
|
180
|
-
end
|
181
|
-
|
182
|
-
# @param (see ethk_1val)
|
183
|
-
# @return [String] valores formatados ethk (token parte3)
|
184
|
-
def ethk_3val(hkx)
|
185
|
-
cta = hkx[:contractAddress]
|
186
|
-
inp = hkx[:input]
|
187
|
-
"#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
|
188
|
-
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
189
|
-
"#{Integer(ops[:h][hkx[:blockNumber]] || 0)})"
|
190
|
-
end
|
191
|
-
|
192
|
-
# @example (see Apibc#ledger_gm)
|
193
|
-
# @param [Hash] hlx ledger greymass
|
194
|
-
# @return [String] valores formatados para insert eos (parte1)
|
195
|
-
def eost_1val(hlx)
|
196
|
-
act = hlx[:action_trace][:act]
|
197
|
-
"(#{hlx[:global_action_seq]}," \
|
198
|
-
"#{hlx[:account_action_seq]}," \
|
199
|
-
"#{hlx[:block_num]}," \
|
200
|
-
"DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
|
201
|
-
"'#{act[:account]}'," \
|
202
|
-
"'#{act[:name]}'," \
|
203
|
-
"#{eost_2val(hlx, act)}"
|
204
|
-
end
|
205
|
-
|
206
|
-
# @param (see eost_1val)
|
207
|
-
# @param [Hash] act dados da acao
|
208
|
-
# @return [String] valores formatados para insert eos (parte2)
|
209
|
-
def eost_2val(hlx, act)
|
210
|
-
dat = act[:data]
|
211
|
-
qtd = dat[:quantity].to_s
|
212
|
-
str = dat[:memo].inspect
|
213
|
-
"'#{dat[:from]}'," \
|
214
|
-
"'#{dat[:to]}'," \
|
215
|
-
"'#{hlx[:iax]}'," \
|
216
|
-
"#{qtd.to_d},'#{qtd[/[[:upper:]]+/]}'," \
|
217
|
-
"nullif('#{str.gsub(/['"]/, '')}','nil')," \
|
218
|
-
"#{ops[:h][String(hlx[:itx])] || 0})"
|
219
|
-
end
|
220
|
-
|
221
|
-
# def eth2at_ins
|
222
|
-
# "insert #{BD}.eth2at(attesterslot,committeeindex,epoch,inclusionslot,status,validatorindex" \
|
223
|
-
# ") VALUES#{apibc.novtx.map { |obj| eth2at_1val(obj) }.join(',')}"
|
224
|
-
# end
|
225
|
-
# def eth2pr_ins
|
226
|
-
# "insert #{BD}.eth2pr(attestationscount,attesterslashingscount,blockroot,depositscount,epoch," \
|
227
|
-
# 'eth1data_blockhash,eth1data_depositcount,eth1data_depositroot,graffiti,graffiti_text,parentroot,' \
|
228
|
-
# 'proposer,proposerslashingscount,randaoreveal,signature,slot,stateroot,status,voluntaryexitscount' \
|
229
|
-
# ") VALUES#{apibc.novkx.map { |obj| eth2pr_1val(obj) }.join(',')}"
|
230
|
-
# end
|
231
|
-
# def eth2at_1val(htx)
|
232
|
-
# "(#{Integer(htx[:attesterslot])}," \
|
233
|
-
# "#{Integer(htx[:committeeindex])}," \
|
234
|
-
# "#{Integer(htx[:epoch])}," \
|
235
|
-
# "#{Integer(htx[:inclusionslot])}," \
|
236
|
-
# "#{Integer(htx[:status])}," \
|
237
|
-
# "#{Integer(htx[:validatorindex])})"
|
238
|
-
# end
|
239
|
-
# def eth2pr_1val(htx)
|
240
|
-
# "(#{Integer(htx[:attestationscount])}," \
|
241
|
-
# "#{Integer(htx[:attesterslashingscount])}," \
|
242
|
-
# "'#{htx[:blockroot]}'," \
|
243
|
-
# "#{Integer(htx[:depositscount])}," \
|
244
|
-
# "#{Integer(htx[:epoch])}," \
|
245
|
-
# "'#{htx[:eth1data_blockhash]}'," \
|
246
|
-
# "#{eth2pr_2val(htx)}"
|
247
|
-
# end
|
248
|
-
# def eth2pr_2val(htx)
|
249
|
-
# grf = htx[:graffiti_text]
|
250
|
-
# "#{Integer(htx[:eth1data_depositcount])}," \
|
251
|
-
# "'#{htx[:eth1data_depositroot]}'," \
|
252
|
-
# "'#{htx[:graffiti]}'," \
|
253
|
-
# "#{grf.length.zero? ? 'null' : "'#{grf}'"}," \
|
254
|
-
# "'#{htx[:parentroot]}'," \
|
255
|
-
# "#{Integer(htx[:proposer])}," \
|
256
|
-
# "#{eth2pr_3val(htx)}"
|
257
|
-
# end
|
258
|
-
# def eth2pr_3val(htx)
|
259
|
-
# "#{Integer(htx[:proposerslashingscount])}," \
|
260
|
-
# "'#{htx[:randaoreveal]}'," \
|
261
|
-
# "'#{htx[:signature]}'," \
|
262
|
-
# "#{Integer(htx[:slot])}," \
|
263
|
-
# "'#{htx[:stateroot]}'," \
|
264
|
-
# "#{Integer(htx[:status])}," \
|
265
|
-
# "#{Integer(htx[:voluntaryexitscount])})"
|
266
|
-
# end
|
267
|
-
end
|
268
|
-
end
|
data/lib/cns/bigquery4.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @author Hernani Rodrigues Vaz
|
4
|
-
module Cns
|
5
|
-
# classe para processar bigquery
|
6
|
-
class Bigquery
|
7
|
-
private
|
8
|
-
|
9
|
-
# @return [String] comando insert SQL formatado det (trades)
|
10
|
-
def det_ins
|
11
|
-
"insert #{BD}.det(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_1val(obj) }.join(',')}"
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [String] comando insert SQL formatado del (ledger)
|
15
|
-
def del_ins
|
16
|
-
"insert #{BD}.del(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [String] comando insert SQL formatado ust (trades)
|
20
|
-
def ust_ins
|
21
|
-
"insert #{BD}.ust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
|
22
|
-
"VALUES#{apius.trades.map { |key, val| ust_1val(key, val) }.join(',')}"
|
23
|
-
end
|
24
|
-
|
25
|
-
# @return [String] comando insert SQL formatado usl (ledger)
|
26
|
-
def usl_ins
|
27
|
-
"insert #{BD}.usl(txid,refid,time,type,aclass,asset,amount,fee) " \
|
28
|
-
"VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
|
29
|
-
end
|
30
|
-
|
31
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
32
|
-
def frl_ins
|
33
|
-
"insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
|
34
|
-
end
|
35
|
-
|
36
|
-
# @example (see Apice#trades_de)
|
37
|
-
# @param [Hash] htx trade bitcoinde
|
38
|
-
# @return [String] valores formatados det (trades parte1)
|
39
|
-
def det_1val(htx)
|
40
|
-
"('#{htx[:trade_id]}'," \
|
41
|
-
"DATETIME(TIMESTAMP('#{htx[:successfully_finished_at]}'))," \
|
42
|
-
"'#{htx[:type]}'," \
|
43
|
-
"'#{htx[:trading_partner_information][:username]}'," \
|
44
|
-
"#{det_2val(htx)}"
|
45
|
-
end
|
46
|
-
|
47
|
-
# @param (see det_1val)
|
48
|
-
# @return [String] valores formatados det (trades parte2)
|
49
|
-
def det_2val(htx)
|
50
|
-
'cast(' \
|
51
|
-
"#{htx[:type] == 'buy' ? htx[:amount_currency_to_trade_after_fee] : "-#{htx[:amount_currency_to_trade]}"}" \
|
52
|
-
' as numeric),' \
|
53
|
-
"cast(#{htx[:volume_currency_to_pay_after_fee]} as numeric)," \
|
54
|
-
"DATETIME(TIMESTAMP('#{htx[:trade_marked_as_paid_at]}'))," \
|
55
|
-
"#{Integer(ops[:h][htx[:trade_id]] || 0)})"
|
56
|
-
end
|
57
|
-
|
58
|
-
# @example (see Apice#deposits_de)
|
59
|
-
# @example (see Apice#withdrawals_de)
|
60
|
-
# @param [Hash] hlx ledger (deposits + withdrawals) bitcoinde
|
61
|
-
# @return [String] valores formatados del (ledger)
|
62
|
-
def del_val(hlx)
|
63
|
-
tip = hlx[:tp]
|
64
|
-
"(#{hlx[:txid]}," \
|
65
|
-
"DATETIME(TIMESTAMP('#{hlx[:time].iso8601}'))," \
|
66
|
-
"'#{tip}'," \
|
67
|
-
"'#{hlx[:add]}'," \
|
68
|
-
"'#{hlx[:moe]}'," \
|
69
|
-
"cast(#{tip == 'withdrawal' ? '-' : ''}#{hlx[:qt]} as numeric)," \
|
70
|
-
"cast(#{hlx[:fee]} as numeric))"
|
71
|
-
end
|
72
|
-
|
73
|
-
# @example (see Apice#trades_us)
|
74
|
-
# @param [String] idx identificador transacao
|
75
|
-
# @param [Hash] htx trade kraken
|
76
|
-
# @return [String] valores formatados ust (trades parte1)
|
77
|
-
def ust_1val(idx, htx)
|
78
|
-
"('#{idx}'," \
|
79
|
-
"'#{htx[:ordertxid]}'," \
|
80
|
-
"'#{htx[:pair]}'," \
|
81
|
-
"PARSE_DATETIME('%s', '#{String(htx[:time].round)}')," \
|
82
|
-
"'#{htx[:type]}'," \
|
83
|
-
"'#{htx[:ordertype]}'," \
|
84
|
-
"cast(#{htx[:price]} as numeric)," \
|
85
|
-
"cast(#{htx[:cost]} as numeric)," \
|
86
|
-
"cast(#{htx[:fee]} as numeric)," \
|
87
|
-
"#{ust_2val(idx, htx)}"
|
88
|
-
end
|
89
|
-
|
90
|
-
# @param (see ust_1val)
|
91
|
-
# @return [String] valores formatados ust (trades parte2)
|
92
|
-
def ust_2val(idx, htx)
|
93
|
-
msc = htx[:misc].to_s
|
94
|
-
"cast(#{htx[:vol]} as numeric)," \
|
95
|
-
"cast(#{htx[:margin]} as numeric)," \
|
96
|
-
"#{msc.empty? ? 'null' : "'#{msc}'"}," \
|
97
|
-
"'#{apius.ledger.select { |_, val| val[:refid] == idx }.keys.join(',') || ''}'," \
|
98
|
-
"#{Integer(ops[:h][idx] || 0)})"
|
99
|
-
end
|
100
|
-
|
101
|
-
# @example (see Apice#ledger_us)
|
102
|
-
# @param idx (see ust_1val)
|
103
|
-
# @param [Hash] hlx ledger kraken
|
104
|
-
# @return [String] valores formatados usl (ledger)
|
105
|
-
def usl_val(idx, hlx)
|
106
|
-
acl = hlx[:aclass].to_s
|
107
|
-
"('#{idx}'," \
|
108
|
-
"'#{hlx[:refid]}'," \
|
109
|
-
"PARSE_DATETIME('%s', '#{String(hlx[:time].round)}')," \
|
110
|
-
"'#{hlx[:type]}'," \
|
111
|
-
"#{acl.empty? ? 'null' : "'#{acl}'"}," \
|
112
|
-
"'#{hlx[:asset]}'," \
|
113
|
-
"cast(#{hlx[:amount]} as numeric)," \
|
114
|
-
"cast(#{hlx[:fee]} as numeric))"
|
115
|
-
end
|
116
|
-
|
117
|
-
# @example (see Apice#ledger_fr)
|
118
|
-
# @param [Hash] hlx ledger paymium
|
119
|
-
# @return [String] valores formatados frl (ledger)
|
120
|
-
def frl_val(hlx)
|
121
|
-
uid = hlx[:uuid]
|
122
|
-
"('#{uid}'," \
|
123
|
-
"'#{hlx[:name]}'," \
|
124
|
-
"cast(#{hlx[:amount]} as numeric)," \
|
125
|
-
"'#{hlx[:currency]}'," \
|
126
|
-
"PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
|
127
|
-
"#{Integer(ops[:h][uid] || 0)})"
|
128
|
-
end
|
129
|
-
|
130
|
-
# @example (see Apice#ledger_mt)
|
131
|
-
# @param [Hash] hlx ledger therock
|
132
|
-
# @return [String] valores formatados mtl (ledger parte1)
|
133
|
-
def mtl_1val(hlx)
|
134
|
-
fid = hlx[:fund_id].to_s
|
135
|
-
"(#{hlx[:id]}," \
|
136
|
-
"DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
|
137
|
-
"'#{hlx[:type]}'," \
|
138
|
-
"cast(#{hlx[:price]} as numeric)," \
|
139
|
-
"'#{hlx[:currency]}'," \
|
140
|
-
"#{fid.empty? ? 'null' : "'#{fid}'"}," \
|
141
|
-
"#{mtl_2val(hlx)}"
|
142
|
-
end
|
143
|
-
|
144
|
-
# @param (see mtl_1val)
|
145
|
-
# @return [String] valores formatados mtl (ledger parte2)
|
146
|
-
def mtl_2val(hlx)
|
147
|
-
nte = hlx[:note].to_s
|
148
|
-
tid = hlx[:trade_id].to_s
|
149
|
-
"#{nte.empty? ? 'null' : "'#{nte}'"}," \
|
150
|
-
"#{tid.empty? ? 'null' : tid.to_s}," \
|
151
|
-
"#{Integer(ops[:h][String(hlx[:id])] || 0)})"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|