cns 0.1.2 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek.yml +74 -0
- data/.rubocop.yml +4 -3
- data/Gemfile.lock +76 -10
- data/cns.gemspec +9 -6
- data/lib/cns.rb +2 -7
- data/lib/cns/apibc.rb +55 -48
- data/lib/cns/apice1.rb +22 -72
- data/lib/cns/apice2.rb +82 -39
- data/lib/cns/beaconchain1.rb +102 -0
- data/lib/cns/beaconchain2.rb +90 -0
- data/lib/cns/bigquery1.rb +23 -18
- data/lib/cns/bigquery2.rb +23 -0
- data/lib/cns/bigquery3.rb +109 -47
- data/lib/cns/bigquery4.rb +53 -52
- data/lib/cns/bitcoinde.rb +21 -20
- data/lib/cns/etherscan1.rb +21 -19
- data/lib/cns/etherscan2.rb +7 -7
- data/lib/cns/greymass1.rb +23 -18
- data/lib/cns/greymass2.rb +8 -26
- data/lib/cns/kraken.rb +21 -20
- data/lib/cns/paymium.rb +15 -15
- data/lib/cns/therock.rb +16 -15
- data/lib/cns/version.rb +1 -1
- metadata +69 -10
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @author Hernani Rodrigues Vaz
|
4
|
+
module Cns
|
5
|
+
# classe para processar historicos da beaconchain
|
6
|
+
class Beaconchain
|
7
|
+
# @return [String] texto validadores & saldos historicos
|
8
|
+
def mostra_resumo
|
9
|
+
return unless dados.count.positive?
|
10
|
+
|
11
|
+
puts("\nindex address beaconchain blh bigquery blh")
|
12
|
+
dados.each { |obj| puts(formata_validador(obj)) }
|
13
|
+
mostra_saldos
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Hash] hjn dados juntos bigquery & beaconchain
|
17
|
+
# @return [String] texto formatado dum validador
|
18
|
+
def formata_validador(hjn)
|
19
|
+
format(
|
20
|
+
'%<s1>-5.5s %<s2>-34.34s ',
|
21
|
+
s1: hjn[:id],
|
22
|
+
s2: formata_endereco(hjn[:ax], 34)
|
23
|
+
) + formata_valores(hjn)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param (see formata_validador)
|
27
|
+
# @return [String] texto formatado valores dum validador
|
28
|
+
def formata_valores(hjn)
|
29
|
+
format(
|
30
|
+
'%<v1>11.6f %<n1>3i %<v2>12.6f %<n2>6i %<ok>-3s',
|
31
|
+
v1: hjn[:es],
|
32
|
+
n1: hjn[:eb].count,
|
33
|
+
v2: hjn[:bs],
|
34
|
+
n2: hjn[:bb].count,
|
35
|
+
ok: ok?(hjn) ? 'OK' : 'NOK'
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param (see formata_validador)
|
40
|
+
# @return [Boolean] validador tem historicos novos(sim=NOK, nao=OK)?
|
41
|
+
def ok?(hjn)
|
42
|
+
hjn[:bs] == hjn[:es]
|
43
|
+
end
|
44
|
+
|
45
|
+
# @example pubkey inicio..fim
|
46
|
+
# 0x10f3a0cf0b534c..c033cf32e8a03586
|
47
|
+
# @param [String] add chave publica validador
|
48
|
+
# @param [Integer] max chars a mostrar
|
49
|
+
# @return [String] pubkey formatada
|
50
|
+
def formata_endereco(add, max)
|
51
|
+
int = Integer((max - 2) / 2)
|
52
|
+
max < 7 ? 'erro' : "#{add[0, int - 3]}..#{add[-int - 3..]}"
|
53
|
+
end
|
54
|
+
|
55
|
+
# @example
|
56
|
+
# {
|
57
|
+
# balance: 32_489_497_108,
|
58
|
+
# effectivebalance: 32_000_000_000,
|
59
|
+
# epoch: 8296,
|
60
|
+
# validatorindex: 11_766,
|
61
|
+
# week: 5
|
62
|
+
# }
|
63
|
+
# @param [Hash] hbh historico beaconchain
|
64
|
+
# @return [String] texto formatado historico beaconchain
|
65
|
+
def formata_saldos(hbh)
|
66
|
+
idx = hbh[:validatorindex]
|
67
|
+
epc = hbh[:epoch]
|
68
|
+
format(
|
69
|
+
'%<vi>5i %<vl>17.6f %<ep>6i %<id>9i',
|
70
|
+
vi: idx,
|
71
|
+
vl: (hbh[:balance].to_d / 10**9).round(10),
|
72
|
+
ep: epc,
|
73
|
+
id: itx(epc, idx)
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [String] texto historico saldos
|
78
|
+
def mostra_saldos
|
79
|
+
return unless ops[:v] && nov.count.positive?
|
80
|
+
|
81
|
+
puts("\nindex saldo epoch itx")
|
82
|
+
sorbx.each { |obj| puts(formata_saldos(obj)) }
|
83
|
+
end
|
84
|
+
|
85
|
+
# @return [Array<Hash>] lista ordenada historico saldos
|
86
|
+
def sorbx
|
87
|
+
nov.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/cns/bigquery1.rb
CHANGED
@@ -30,24 +30,25 @@ module Cns
|
|
30
30
|
@ops = pop
|
31
31
|
end
|
32
32
|
|
33
|
-
# mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass & bigquery
|
33
|
+
# mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain & bigquery
|
34
34
|
def mostra_tudo
|
35
|
-
|
36
|
-
|
35
|
+
apius.mostra_resumo
|
36
|
+
apide.mostra_resumo
|
37
37
|
apifr.mostra_resumo
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
apimt.mostra_resumo
|
39
|
+
apies.mostra_resumo
|
40
|
+
apigm.mostra_resumo
|
41
|
+
apibc.mostra_resumo
|
41
42
|
end
|
42
43
|
|
43
|
-
# insere (caso existam)
|
44
|
+
# insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass/beaconchain no bigquery
|
44
45
|
def processa_tudo
|
45
46
|
processa_us
|
46
47
|
processa_de
|
47
|
-
|
48
|
-
processa_mt
|
48
|
+
processa_frmt
|
49
49
|
processa_eth
|
50
50
|
processa_eos
|
51
|
+
processa_bc
|
51
52
|
end
|
52
53
|
|
53
54
|
private
|
@@ -64,13 +65,9 @@ module Cns
|
|
64
65
|
puts(format("%<n>2i LEDGER BITCOINDE INSERIDAS #{BD}.del", n: apide.ledger.empty? ? 0 : dml(del_ins)))
|
65
66
|
end
|
66
67
|
|
67
|
-
# insere transacoes exchange paymium
|
68
|
-
def
|
68
|
+
# insere transacoes exchange paymium/therock novas na tabela fr/mt (ledger)
|
69
|
+
def processa_frmt
|
69
70
|
puts(format("%<n>2i LEDGER PAYMIUM INSERIDAS #{BD}.fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
|
70
|
-
end
|
71
|
-
|
72
|
-
# insere transacoes exchange therock novas na tabela mt (ledger)
|
73
|
-
def processa_mt
|
74
71
|
puts(format("%<n>2i LEDGER THEROCK INSERIDAS #{BD}.mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
|
75
72
|
end
|
76
73
|
|
@@ -85,15 +82,23 @@ module Cns
|
|
85
82
|
puts(format("%<n>2i TRANSACOES EOS INSERIDAS #{BD}.eos ", n: apigm.novax.empty? ? 0 : dml(eost_ins)))
|
86
83
|
end
|
87
84
|
|
85
|
+
# insere historico sados novos na tabela eth2bh
|
86
|
+
def processa_bc
|
87
|
+
# puts(format("%<n>2i ATTESTATIONS INSERIDAS #{BD}.eth2at", n: apibc.novtx.empty? ? 0 : dml(eth2at_ins)))
|
88
|
+
# puts(format("%<n>2i PROPOSALS INSERIDAS #{BD}.eth2pr", n: apibc.novkx.empty? ? 0 : dml(eth2pr_ins)))
|
89
|
+
puts(format("%<n>2i BALANCES INSERIDOS #{BD}.eth2bh", n: apibc.nov.empty? ? 0 : dml(eth2bh_ins)))
|
90
|
+
end
|
91
|
+
|
88
92
|
# cria job bigquery & verifica execucao
|
89
93
|
#
|
90
94
|
# @param cmd (see sql)
|
91
95
|
# @return [Boolean] job ok?
|
92
96
|
def job?(cmd)
|
93
97
|
@job = api.query_job(cmd)
|
94
|
-
|
95
|
-
|
96
|
-
|
98
|
+
job.wait_until_done!
|
99
|
+
fld = job.failed?
|
100
|
+
puts(job.error['message']) if fld
|
101
|
+
fld
|
97
102
|
end
|
98
103
|
|
99
104
|
# cria Structured Query Language (SQL) job bigquery
|
data/lib/cns/bigquery2.rb
CHANGED
@@ -6,6 +6,18 @@ module Cns
|
|
6
6
|
class Bigquery
|
7
7
|
private
|
8
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..900].map { |obj| eth2bh_1val(obj) }.join(',')}"
|
19
|
+
end
|
20
|
+
|
9
21
|
# @return [Etherscan] API blockchain ETH
|
10
22
|
def apies
|
11
23
|
@apies ||= Etherscan.new(
|
@@ -29,6 +41,17 @@ module Cns
|
|
29
41
|
)
|
30
42
|
end
|
31
43
|
|
44
|
+
# @return [Beaconchain] API blockchain ETH2
|
45
|
+
def apibc
|
46
|
+
@apibc ||= Beaconchain.new(
|
47
|
+
{
|
48
|
+
wb: sql("select * from #{BD}.walletEth2 order by 1"),
|
49
|
+
nb: sql("select itx,iax from #{BD}.eth2bhx")
|
50
|
+
},
|
51
|
+
ops
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
32
55
|
# @return [Kraken] API exchange kraken
|
33
56
|
def apius
|
34
57
|
@apius ||= Kraken.new(
|
data/lib/cns/bigquery3.rb
CHANGED
@@ -13,13 +13,36 @@ module Cns
|
|
13
13
|
def etht_ins
|
14
14
|
"insert #{BD}.etht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
15
15
|
'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias' \
|
16
|
-
") VALUES#{apies.novtx.map { |
|
16
|
+
") VALUES#{apies.novtx.map { |obj| etht_1val(obj) }.join(',')}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] comando insert SQL formatado ethk (token)
|
20
|
+
def ethk_ins
|
21
|
+
"insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
22
|
+
'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
|
23
|
+
") VALUES#{apies.novkx.map { |obj| ethk_1val(obj) }.join(',')}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [String] comando insert SQL formatado eos
|
27
|
+
def eost_ins
|
28
|
+
"insert #{BD}.eos(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
|
29
|
+
") VALUES#{apigm.novax.map { |obj| eost_1val(obj) }.join(',')}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# @example (see Beaconchain#formata_saldos)
|
33
|
+
# @param (see Beaconchain#formata_saldos)
|
34
|
+
# @return [String] valores formatados etht (norml parte1)
|
35
|
+
def eth2bh_1val(htb)
|
36
|
+
"(#{Integer(htb[:balance])}," \
|
37
|
+
"#{Integer(htb[:effectivebalance])}," \
|
38
|
+
"#{Integer(htb[:epoch])}," \
|
39
|
+
"#{Integer(htb[:validatorindex])})"
|
17
40
|
end
|
18
41
|
|
19
42
|
# @example (see Apibc#norml_es)
|
20
43
|
# @param [Hash] htx transacao norml etherscan
|
21
44
|
# @return [String] valores formatados etht (norml parte1)
|
22
|
-
def
|
45
|
+
def etht_1val(htx)
|
23
46
|
"(#{Integer(htx[:blockNumber])}," \
|
24
47
|
"#{Integer(htx[:timeStamp])}," \
|
25
48
|
"'#{htx[:hash]}'," \
|
@@ -29,40 +52,36 @@ module Cns
|
|
29
52
|
"'#{htx[:from]}'," \
|
30
53
|
"'#{htx[:to]}'," \
|
31
54
|
"'#{htx[:iax]}'," \
|
32
|
-
"#{
|
55
|
+
"#{etht_2val(htx)}"
|
33
56
|
end
|
34
57
|
|
35
|
-
# @param (see
|
58
|
+
# @param (see etht_1val)
|
36
59
|
# @return [String] valores formatados etht (norml parte2)
|
37
|
-
def
|
60
|
+
def etht_2val(htx)
|
61
|
+
txr = htx[:txreceipt_status]
|
38
62
|
"cast('#{htx[:value]}' as numeric)," \
|
39
63
|
"cast('#{htx[:gas]}' as numeric)," \
|
40
64
|
"cast('#{htx[:gasPrice]}' as numeric)," \
|
41
65
|
"cast('#{htx[:gasUsed]}' as numeric)," \
|
42
66
|
"#{Integer(htx[:isError])}," \
|
43
|
-
"#{
|
44
|
-
"#{
|
67
|
+
"#{txr.length.zero? ? 'null' : txr}," \
|
68
|
+
"#{etht_3val(htx)}"
|
45
69
|
end
|
46
70
|
|
47
|
-
# @param (see
|
71
|
+
# @param (see etht_1val)
|
48
72
|
# @return [String] valores formatados etht (norml parte3)
|
49
|
-
def
|
50
|
-
|
51
|
-
|
73
|
+
def etht_3val(htx)
|
74
|
+
cta = htx[:contractAddress]
|
75
|
+
inp = htx[:input]
|
76
|
+
"#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
|
77
|
+
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
52
78
|
"#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
|
53
79
|
end
|
54
80
|
|
55
|
-
# @return [String] comando insert SQL formatado ethk (token)
|
56
|
-
def ethk_ins
|
57
|
-
"insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
58
|
-
'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
|
59
|
-
") VALUES#{apies.novkx.map { |e| ethk_val1(e) }.join(',')}"
|
60
|
-
end
|
61
|
-
|
62
81
|
# @example (see Apibc#token_es)
|
63
82
|
# @param [Hash] hkx token event etherscan
|
64
83
|
# @return [String] valores formatados ethk (token parte1)
|
65
|
-
def
|
84
|
+
def ethk_1val(hkx)
|
66
85
|
"(#{Integer(hkx[:blockNumber])}," \
|
67
86
|
"#{Integer(hkx[:timeStamp])}," \
|
68
87
|
"'#{hkx[:hash]}'," \
|
@@ -72,12 +91,12 @@ module Cns
|
|
72
91
|
"'#{hkx[:from]}'," \
|
73
92
|
"'#{hkx[:to]}'," \
|
74
93
|
"'#{hkx[:iax]}'," \
|
75
|
-
"#{
|
94
|
+
"#{ethk_2val(hkx)}"
|
76
95
|
end
|
77
96
|
|
78
|
-
# @param (see
|
97
|
+
# @param (see ethk_1val)
|
79
98
|
# @return [String] valores formatados ethk (token parte2)
|
80
|
-
def
|
99
|
+
def ethk_2val(hkx)
|
81
100
|
"cast('#{hkx[:value]}' as numeric)," \
|
82
101
|
"'#{hkx[:tokenName]}'," \
|
83
102
|
"'#{hkx[:tokenSymbol]}'," \
|
@@ -85,50 +104,93 @@ module Cns
|
|
85
104
|
"cast('#{hkx[:gas]}' as numeric)," \
|
86
105
|
"cast('#{hkx[:gasPrice]}' as numeric)," \
|
87
106
|
"cast('#{hkx[:gasUsed]}' as numeric)," \
|
88
|
-
"#{
|
107
|
+
"#{ethk_3val(hkx)}"
|
89
108
|
end
|
90
109
|
|
91
|
-
# @param (see
|
110
|
+
# @param (see ethk_1val)
|
92
111
|
# @return [String] valores formatados ethk (token parte3)
|
93
|
-
def
|
94
|
-
|
95
|
-
|
112
|
+
def ethk_3val(hkx)
|
113
|
+
cta = hkx[:contractAddress]
|
114
|
+
inp = hkx[:input]
|
115
|
+
"#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
|
116
|
+
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
96
117
|
"#{Integer(ops[:h][hkx[:blockNumber]] || 0)})"
|
97
118
|
end
|
98
119
|
|
99
|
-
# @return [String] comando insert SQL formatado eos
|
100
|
-
def eost_ins
|
101
|
-
"insert #{BD}.eos(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
|
102
|
-
") VALUES#{apigm.novax.map { |e| eost_val1(e) }.join(',')}"
|
103
|
-
end
|
104
|
-
|
105
120
|
# @example (see Apibc#ledger_gm)
|
106
121
|
# @param [Hash] hlx ledger greymass
|
107
122
|
# @return [String] valores formatados para insert eos (parte1)
|
108
|
-
def
|
109
|
-
|
123
|
+
def eost_1val(hlx)
|
124
|
+
act = hlx[:action_trace][:act]
|
110
125
|
"(#{hlx[:global_action_seq]}," \
|
111
126
|
"#{hlx[:account_action_seq]}," \
|
112
127
|
"#{hlx[:block_num]}," \
|
113
128
|
"DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
|
114
|
-
"'#{
|
115
|
-
"'#{
|
116
|
-
"#{
|
129
|
+
"'#{act[:account]}'," \
|
130
|
+
"'#{act[:name]}'," \
|
131
|
+
"#{eost_2val(hlx, act)}"
|
117
132
|
end
|
118
133
|
|
119
|
-
# @param (see
|
134
|
+
# @param (see eost_1val)
|
120
135
|
# @param [Hash] act dados da acao
|
121
136
|
# @return [String] valores formatados para insert eos (parte2)
|
122
|
-
def
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
"'#{
|
127
|
-
"'#{
|
137
|
+
def eost_2val(hlx, act)
|
138
|
+
dat = act[:data]
|
139
|
+
qtd = dat[:quantity].to_s
|
140
|
+
str = dat[:memo].inspect
|
141
|
+
"'#{dat[:from]}'," \
|
142
|
+
"'#{dat[:to]}'," \
|
128
143
|
"'#{hlx[:iax]}'," \
|
129
|
-
"#{
|
130
|
-
"nullif('#{
|
144
|
+
"#{qtd.to_d},'#{qtd[/[[:upper:]]+/]}'," \
|
145
|
+
"nullif('#{str.gsub(/['"]/, '')}','nil')," \
|
131
146
|
"#{ops[:h][String(hlx[:itx])] || 0})"
|
132
147
|
end
|
148
|
+
|
149
|
+
# def eth2at_ins
|
150
|
+
# "insert #{BD}.eth2at(attesterslot,committeeindex,epoch,inclusionslot,status,validatorindex" \
|
151
|
+
# ") VALUES#{apibc.novtx.map { |obj| eth2at_1val(obj) }.join(',')}"
|
152
|
+
# end
|
153
|
+
# def eth2pr_ins
|
154
|
+
# "insert #{BD}.eth2pr(attestationscount,attesterslashingscount,blockroot,depositscount,epoch," \
|
155
|
+
# 'eth1data_blockhash,eth1data_depositcount,eth1data_depositroot,graffiti,graffiti_text,parentroot,' \
|
156
|
+
# 'proposer,proposerslashingscount,randaoreveal,signature,slot,stateroot,status,voluntaryexitscount' \
|
157
|
+
# ") VALUES#{apibc.novkx.map { |obj| eth2pr_1val(obj) }.join(',')}"
|
158
|
+
# end
|
159
|
+
# def eth2at_1val(htx)
|
160
|
+
# "(#{Integer(htx[:attesterslot])}," \
|
161
|
+
# "#{Integer(htx[:committeeindex])}," \
|
162
|
+
# "#{Integer(htx[:epoch])}," \
|
163
|
+
# "#{Integer(htx[:inclusionslot])}," \
|
164
|
+
# "#{Integer(htx[:status])}," \
|
165
|
+
# "#{Integer(htx[:validatorindex])})"
|
166
|
+
# end
|
167
|
+
# def eth2pr_1val(htx)
|
168
|
+
# "(#{Integer(htx[:attestationscount])}," \
|
169
|
+
# "#{Integer(htx[:attesterslashingscount])}," \
|
170
|
+
# "'#{htx[:blockroot]}'," \
|
171
|
+
# "#{Integer(htx[:depositscount])}," \
|
172
|
+
# "#{Integer(htx[:epoch])}," \
|
173
|
+
# "'#{htx[:eth1data_blockhash]}'," \
|
174
|
+
# "#{eth2pr_2val(htx)}"
|
175
|
+
# end
|
176
|
+
# def eth2pr_2val(htx)
|
177
|
+
# grf = htx[:graffiti_text]
|
178
|
+
# "#{Integer(htx[:eth1data_depositcount])}," \
|
179
|
+
# "'#{htx[:eth1data_depositroot]}'," \
|
180
|
+
# "'#{htx[:graffiti]}'," \
|
181
|
+
# "#{grf.length.zero? ? 'null' : "'#{grf}'"}," \
|
182
|
+
# "'#{htx[:parentroot]}'," \
|
183
|
+
# "#{Integer(htx[:proposer])}," \
|
184
|
+
# "#{eth2pr_3val(htx)}"
|
185
|
+
# end
|
186
|
+
# def eth2pr_3val(htx)
|
187
|
+
# "#{Integer(htx[:proposerslashingscount])}," \
|
188
|
+
# "'#{htx[:randaoreveal]}'," \
|
189
|
+
# "'#{htx[:signature]}'," \
|
190
|
+
# "#{Integer(htx[:slot])}," \
|
191
|
+
# "'#{htx[:stateroot]}'," \
|
192
|
+
# "#{Integer(htx[:status])}," \
|
193
|
+
# "#{Integer(htx[:voluntaryexitscount])})"
|
194
|
+
# end
|
133
195
|
end
|
134
196
|
end
|
data/lib/cns/bigquery4.rb
CHANGED
@@ -8,23 +8,45 @@ module Cns
|
|
8
8
|
|
9
9
|
# @return [String] comando insert SQL formatado det (trades)
|
10
10
|
def det_ins
|
11
|
-
"insert #{BD}.det(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |
|
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(',')}"
|
12
34
|
end
|
13
35
|
|
14
36
|
# @example (see Apice#trades_de)
|
15
37
|
# @param [Hash] htx trade bitcoinde
|
16
38
|
# @return [String] valores formatados det (trades parte1)
|
17
|
-
def
|
39
|
+
def det_1val(htx)
|
18
40
|
"('#{htx[:trade_id]}'," \
|
19
41
|
"DATETIME(TIMESTAMP('#{htx[:successfully_finished_at]}'))," \
|
20
42
|
"'#{htx[:type]}'," \
|
21
43
|
"'#{htx[:trading_partner_information][:username]}'," \
|
22
|
-
"#{
|
44
|
+
"#{det_2val(htx)}"
|
23
45
|
end
|
24
46
|
|
25
|
-
# @param (see
|
47
|
+
# @param (see det_1val)
|
26
48
|
# @return [String] valores formatados det (trades parte2)
|
27
|
-
def
|
49
|
+
def det_2val(htx)
|
28
50
|
'cast(' \
|
29
51
|
"#{htx[:type] == 'buy' ? htx[:amount_currency_to_trade_after_fee] : "-#{htx[:amount_currency_to_trade]}"}" \
|
30
52
|
' as numeric),' \
|
@@ -33,36 +55,26 @@ module Cns
|
|
33
55
|
"#{Integer(ops[:h][htx[:trade_id]] || 0)})"
|
34
56
|
end
|
35
57
|
|
36
|
-
# @return [String] comando insert SQL formatado del (ledger)
|
37
|
-
def del_ins
|
38
|
-
"insert #{BD}.del(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |h| del_val(h) }.join(',')}"
|
39
|
-
end
|
40
|
-
|
41
58
|
# @example (see Apice#deposits_de)
|
42
59
|
# @example (see Apice#withdrawals_de)
|
43
60
|
# @param [Hash] hlx ledger (deposits + withdrawals) bitcoinde
|
44
61
|
# @return [String] valores formatados del (ledger)
|
45
62
|
def del_val(hlx)
|
63
|
+
tip = hlx[:tp]
|
46
64
|
"(#{hlx[:txid]}," \
|
47
65
|
"DATETIME(TIMESTAMP('#{hlx[:time].iso8601}'))," \
|
48
|
-
"'#{
|
66
|
+
"'#{tip}'," \
|
49
67
|
"'#{hlx[:add]}'," \
|
50
68
|
"'#{hlx[:moe]}'," \
|
51
|
-
"cast(#{
|
69
|
+
"cast(#{tip == 'withdrawal' ? '-' : ''}#{hlx[:qt]} as numeric)," \
|
52
70
|
"cast(#{hlx[:fee]} as numeric))"
|
53
71
|
end
|
54
72
|
|
55
|
-
# @return [String] comando insert SQL formatado ust (trades)
|
56
|
-
def ust_ins
|
57
|
-
"insert #{BD}.ust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
|
58
|
-
"VALUES#{apius.trades.map { |k, v| ust_val1(k, v) }.join(',')}"
|
59
|
-
end
|
60
|
-
|
61
73
|
# @example (see Apice#trades_us)
|
62
74
|
# @param [String] idx identificador transacao
|
63
75
|
# @param [Hash] htx trade kraken
|
64
76
|
# @return [String] valores formatados ust (trades parte1)
|
65
|
-
def
|
77
|
+
def ust_1val(idx, htx)
|
66
78
|
"('#{idx}'," \
|
67
79
|
"'#{htx[:ordertxid]}'," \
|
68
80
|
"'#{htx[:pair]}'," \
|
@@ -72,81 +84,70 @@ module Cns
|
|
72
84
|
"cast(#{htx[:price]} as numeric)," \
|
73
85
|
"cast(#{htx[:cost]} as numeric)," \
|
74
86
|
"cast(#{htx[:fee]} as numeric)," \
|
75
|
-
"#{
|
87
|
+
"#{ust_2val(idx, htx)}"
|
76
88
|
end
|
77
89
|
|
78
|
-
# @param (see
|
90
|
+
# @param (see ust_1val)
|
79
91
|
# @return [String] valores formatados ust (trades parte2)
|
80
|
-
def
|
92
|
+
def ust_2val(idx, htx)
|
93
|
+
msc = htx[:misc].to_s
|
81
94
|
"cast(#{htx[:vol]} as numeric)," \
|
82
95
|
"cast(#{htx[:margin]} as numeric)," \
|
83
|
-
"#{
|
84
|
-
"'#{apius.ledger.select { |_,
|
96
|
+
"#{msc.empty? ? 'null' : "'#{msc}'"}," \
|
97
|
+
"'#{apius.ledger.select { |_, val| val[:refid] == idx }.keys.join(',') || ''}'," \
|
85
98
|
"#{Integer(ops[:h][idx] || 0)})"
|
86
99
|
end
|
87
100
|
|
88
|
-
# @return [String] comando insert SQL formatado usl (ledger)
|
89
|
-
def usl_ins
|
90
|
-
"insert #{BD}.usl(txid,refid,time,type,aclass,asset,amount,fee) " \
|
91
|
-
"VALUES#{apius.ledger.map { |k, v| usl_val(k, v) }.join(',')}"
|
92
|
-
end
|
93
|
-
|
94
101
|
# @example (see Apice#ledger_us)
|
95
|
-
# @param idx (see
|
102
|
+
# @param idx (see ust_1val)
|
96
103
|
# @param [Hash] hlx ledger kraken
|
97
104
|
# @return [String] valores formatados usl (ledger)
|
98
105
|
def usl_val(idx, hlx)
|
106
|
+
acl = hlx[:aclass].to_s
|
99
107
|
"('#{idx}'," \
|
100
108
|
"'#{hlx[:refid]}'," \
|
101
109
|
"PARSE_DATETIME('%s', '#{String(hlx[:time].round)}')," \
|
102
110
|
"'#{hlx[:type]}'," \
|
103
|
-
"#{
|
111
|
+
"#{acl.empty? ? 'null' : "'#{acl}'"}," \
|
104
112
|
"'#{hlx[:asset]}'," \
|
105
113
|
"cast(#{hlx[:amount]} as numeric)," \
|
106
114
|
"cast(#{hlx[:fee]} as numeric))"
|
107
115
|
end
|
108
116
|
|
109
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
110
|
-
def frl_ins
|
111
|
-
"insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |h| frl_val(h) }.join(',')}"
|
112
|
-
end
|
113
|
-
|
114
117
|
# @example (see Apice#ledger_fr)
|
115
118
|
# @param [Hash] hlx ledger paymium
|
116
119
|
# @return [String] valores formatados frl (ledger)
|
117
120
|
def frl_val(hlx)
|
118
|
-
|
121
|
+
uid = hlx[:uuid]
|
122
|
+
"('#{uid}'," \
|
119
123
|
"'#{hlx[:name]}'," \
|
120
124
|
"cast(#{hlx[:amount]} as numeric)," \
|
121
125
|
"'#{hlx[:currency]}'," \
|
122
126
|
"PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
|
123
|
-
"#{Integer(ops[:h][
|
124
|
-
end
|
125
|
-
|
126
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
127
|
-
def mtl_ins
|
128
|
-
"insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
|
129
|
-
"VALUES#{apimt.ledger.map { |h| mtl_val1(h) }.join(',')}"
|
127
|
+
"#{Integer(ops[:h][uid] || 0)})"
|
130
128
|
end
|
131
129
|
|
132
130
|
# @example (see Apice#ledger_mt)
|
133
131
|
# @param [Hash] hlx ledger therock
|
134
132
|
# @return [String] valores formatados mtl (ledger parte1)
|
135
|
-
def
|
133
|
+
def mtl_1val(hlx)
|
134
|
+
fid = hlx[:fund_id].to_s
|
136
135
|
"(#{hlx[:id]}," \
|
137
136
|
"DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
|
138
137
|
"'#{hlx[:type]}'," \
|
139
138
|
"cast(#{hlx[:price]} as numeric)," \
|
140
139
|
"'#{hlx[:currency]}'," \
|
141
|
-
"#{
|
142
|
-
"#{
|
140
|
+
"#{fid.empty? ? 'null' : "'#{fid}'"}," \
|
141
|
+
"#{mtl_2val(hlx)}"
|
143
142
|
end
|
144
143
|
|
145
|
-
# @param (see
|
144
|
+
# @param (see mtl_1val)
|
146
145
|
# @return [String] valores formatados mtl (ledger parte2)
|
147
|
-
def
|
148
|
-
|
149
|
-
|
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}," \
|
150
151
|
"#{Integer(ops[:h][String(hlx[:id])] || 0)})"
|
151
152
|
end
|
152
153
|
end
|