cns 0.9.2 → 0.9.3
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 +1 -1
- data/lib/cns/bitcoinde.rb +72 -67
- data/lib/cns/etherscan.rb +172 -178
- data/lib/cns/greymass.rb +61 -63
- data/lib/cns/kraken.rb +71 -68
- data/lib/cns/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5864db949cd54475943852878f488bcb0e62e342dafcc2f0be4d2e418a6e4a8
|
4
|
+
data.tar.gz: 2f33d2a740c1787f92246625ff11d44f1cc06d4ac8cbe2a54e610aca6a2309ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 989d84cf9d660f93068f135d35f8963633431787446a2a666562230560965711430820cc57ebc8ec7e6dd540005c920d1791431ac20e9acd0a71e84565a24dc4
|
7
|
+
data.tar.gz: b8818edca07d3e902cd1a126e9474efe1ff15c3088ca6939f27be8f5422fd91f88a024e2b407a75dd156426cbb4f30b9971548c23ccad0f648348607bd6da435
|
data/Gemfile.lock
CHANGED
data/lib/cns/bitcoinde.rb
CHANGED
@@ -7,11 +7,9 @@ module Cns
|
|
7
7
|
# classe para processar transacoes trades/ledger do bitcoinde
|
8
8
|
class Bitcoinde
|
9
9
|
# @return [Apius] API bitcoinde
|
10
|
-
attr_reader :api
|
11
10
|
# @return [Array<Hash>] todos os dados bigquery
|
12
|
-
attr_reader :bqd
|
13
11
|
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
14
|
-
attr_reader :ops
|
12
|
+
attr_reader :api, :bqd, :ops
|
15
13
|
|
16
14
|
# @param [Hash] dad todos os dados bigquery
|
17
15
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
@@ -33,7 +31,7 @@ module Cns
|
|
33
31
|
# @return [String] texto saldos & transacoes & ajuste dias
|
34
32
|
def mresumo
|
35
33
|
puts("\nBITCOINDE\ntipo bitcoinde bigquery")
|
36
|
-
exd[:sl].sort.each { |
|
34
|
+
exd[:sl].sort.each { |k, v| puts(fos(k, v)) }
|
37
35
|
mtotais
|
38
36
|
|
39
37
|
mtrades
|
@@ -45,42 +43,37 @@ module Cns
|
|
45
43
|
|
46
44
|
private
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
46
|
+
# mosta contadores transacoes
|
47
|
+
def mtotais
|
48
|
+
vtt = exd[:tt].count
|
49
|
+
vnt = bqd[:nt].count
|
50
|
+
vtl = exd[:tl].count
|
51
|
+
vnl = bqd[:nl].count
|
55
52
|
|
56
|
-
|
57
|
-
|
53
|
+
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}")
|
54
|
+
puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vtl, d: vnl, o: vtl == vnl ? 'OK' : 'NOK')}")
|
58
55
|
end
|
59
56
|
|
60
|
-
#
|
61
|
-
def
|
62
|
-
|
63
|
-
end
|
57
|
+
# mosta transacoes trades
|
58
|
+
def mtrades
|
59
|
+
return unless ops[:v] && novcdet.any?
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
@kyl ||= exd[:tl].map { |oex| oex[:txid] } - bqkyl
|
61
|
+
puts("\ntrades data hora dt criacao tipo par btc eur")
|
62
|
+
novcdet.sort_by { |i| -i[:srx] }.each { |o| puts(fot(o)) }
|
68
63
|
end
|
69
64
|
|
70
|
-
#
|
71
|
-
def
|
72
|
-
|
73
|
-
end
|
65
|
+
# mosta transacoes ledger
|
66
|
+
def mledger
|
67
|
+
return unless ops[:v] && novcdel.any?
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
@novcdel ||= exd[:tl].select { |obj| kyl.include?(obj[:txid]) }
|
69
|
+
puts("\nledger data hora tipo moe quantidade custo")
|
70
|
+
novcdel.sort_by { |i| -i[:srx] }.each { |o| puts(fol(o)) }
|
78
71
|
end
|
79
72
|
|
80
73
|
# @param [String] moe codigo bitcoinde da moeda
|
81
74
|
# @param [Hash] hsx saldo bitcoinde da moeda
|
82
75
|
# @return [String] texto formatado saldos
|
83
|
-
def
|
76
|
+
def fos(moe, hsx)
|
84
77
|
vbq = bqd[:sl][moe.downcase.to_sym].to_d
|
85
78
|
vex = hsx[:total_amount]
|
86
79
|
format(
|
@@ -92,9 +85,9 @@ module Cns
|
|
92
85
|
)
|
93
86
|
end
|
94
87
|
|
95
|
-
# @param
|
88
|
+
# @param [Hash] htn trades bitcoinde
|
96
89
|
# @return [String] texto formatado trade
|
97
|
-
def
|
90
|
+
def fot(htx)
|
98
91
|
format(
|
99
92
|
'%<ky>-6.6s %<dt>19.19s %<dp>10.10s %<ty>-5.5s %<mo>-8.8s %<vl>18.8f %<co>8.2f',
|
100
93
|
ky: htx[:trade_id],
|
@@ -107,9 +100,9 @@ module Cns
|
|
107
100
|
)
|
108
101
|
end
|
109
102
|
|
110
|
-
# @param
|
103
|
+
# @param [Hash] htn ledger bitcoinde
|
111
104
|
# @return [String] texto formatado ledger
|
112
|
-
def
|
105
|
+
def fol(hlx)
|
113
106
|
format(
|
114
107
|
'%<ky>6i %<dt>19.19s %<ty>-10.10s %<mo>-3.3s %<pr>19.8f %<vl>18.8f',
|
115
108
|
ky: hlx[:txid],
|
@@ -121,51 +114,33 @@ module Cns
|
|
121
114
|
)
|
122
115
|
end
|
123
116
|
|
124
|
-
|
125
|
-
|
126
|
-
vtt = exd[:tt].count
|
127
|
-
vnt = bqd[:nt].count
|
128
|
-
vtl = exd[:tl].count
|
129
|
-
vnl = bqd[:nl].count
|
130
|
-
|
131
|
-
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}")
|
132
|
-
puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vtl, d: vnl, o: vtl == vnl ? 'OK' : 'NOK')}")
|
133
|
-
end
|
134
|
-
|
135
|
-
# @return [String] texto transacoes trades
|
136
|
-
def mtrades
|
137
|
-
return unless ops[:v] && novcdet.any?
|
138
|
-
|
139
|
-
puts("\ntrades data hora dt criacao tipo par btc eur")
|
140
|
-
novcdet.sort_by { |i| -i[:srx] }.each { |o| puts(formata_trades(o)) }
|
141
|
-
end
|
142
|
-
|
143
|
-
# @return [String] texto transacoes ledger
|
144
|
-
def mledger
|
145
|
-
return unless ops[:v] && novcdel.any?
|
146
|
-
|
147
|
-
puts("\nledger data hora tipo moe quantidade custo")
|
148
|
-
novcdel.sort_by { |i| -i[:srx] }.each { |o| puts(formata_ledger(o)) }
|
117
|
+
def show_all?
|
118
|
+
ops[:t] || false
|
149
119
|
end
|
150
120
|
|
151
|
-
#
|
121
|
+
# @param [Hash] itm recursos bitcoinde
|
122
|
+
# @return [Hash<BigDecimal>] moedas & sados
|
152
123
|
def pdea(itm)
|
153
124
|
itm.select { |k, _| EM.include?(k) }.transform_values { |o| o.merge(total_amount: o[:total_amount].to_d) }
|
154
125
|
end
|
155
126
|
|
156
|
-
#
|
157
|
-
|
158
|
-
|
127
|
+
# @param [Object] val time bitcoinde
|
128
|
+
# @return [Time] processa time (somtimes is string)
|
129
|
+
def ptm(val)
|
130
|
+
val.is_a?(String) ? Time.parse(val) : val
|
159
131
|
end
|
160
132
|
|
133
|
+
# @param [Hash] itm transacao bitcoinde
|
134
|
+
# @return [Hash] transaccao filtrada
|
161
135
|
def pdes(key, itm)
|
162
136
|
tym = ptm(itm[key])
|
163
137
|
itm.merge(srx: Integer(tym), key => tym)
|
164
138
|
end
|
165
139
|
|
166
|
-
#
|
167
|
-
|
168
|
-
|
140
|
+
# @param [Array<Hash>] htx trade bitcoinde
|
141
|
+
# @return [Array<Hash>] transaccao filtrada
|
142
|
+
def pdet(htx)
|
143
|
+
htx.map do |t|
|
169
144
|
pdes(:successfully_finished_at, t).merge(
|
170
145
|
trade_marked_as_paid_at: ptm(t[:trade_marked_as_paid_at]),
|
171
146
|
username: t[:trading_partner_information][:username],
|
@@ -176,10 +151,40 @@ module Cns
|
|
176
151
|
end
|
177
152
|
end
|
178
153
|
|
179
|
-
#
|
154
|
+
# @param [Array<Hash>] hlx ledger bitcoinde
|
155
|
+
# @return [Array<Hash>] transaccao filtrada
|
156
|
+
def pdel(hlx)
|
157
|
+
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
|
+
end
|
159
|
+
|
160
|
+
# @return [Array<String>] indices trades bigquery
|
161
|
+
def bqkyt
|
162
|
+
@bqkyt ||= show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid] } || [])
|
163
|
+
end
|
164
|
+
|
165
|
+
# @return [Array<Integer>] indices ledger bigquery
|
166
|
+
def bqkyl
|
167
|
+
@bqkyl ||= show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid] } || [])
|
168
|
+
end
|
169
|
+
|
170
|
+
# @return [Array<String>] lista txid trades novos
|
171
|
+
def kyt
|
172
|
+
@kyt ||= exd[:tt].map { |t| t[:trade_id] } - bqkyt
|
173
|
+
end
|
180
174
|
|
181
|
-
|
182
|
-
|
175
|
+
# @return [Array<Integer>] lista txid ledger novos
|
176
|
+
def kyl
|
177
|
+
@kyl ||= exd[:tl].map { |t| t[:txid] } - bqkyl
|
178
|
+
end
|
179
|
+
|
180
|
+
# @return [Array<Hash>] lista trades bitcoinde novos
|
181
|
+
def novcdet
|
182
|
+
@novcdet ||= exd[:tt].select { |obj| kyt.include?(obj[:trade_id]) }
|
183
|
+
end
|
184
|
+
|
185
|
+
# @return [Array<Hash>] lista ledger (deposits + withdrawals) bitcoinde novos
|
186
|
+
def novcdel
|
187
|
+
@novcdel ||= exd[:tl].select { |obj| kyl.include?(obj[:txid]) }
|
183
188
|
end
|
184
189
|
end
|
185
190
|
end
|
data/lib/cns/etherscan.rb
CHANGED
@@ -4,50 +4,45 @@ require('bigdecimal/util')
|
|
4
4
|
|
5
5
|
# @author Hernani Rodrigues Vaz
|
6
6
|
module Cns
|
7
|
-
# chaves a eliminar da API - resultado deve ser ignirado pois muda a cada pedido API feito
|
8
|
-
DL = %i[cumulativeGasUsed confirmations].freeze
|
9
|
-
|
10
7
|
# classe para processar transacoes do etherscan
|
11
8
|
class Etherscan
|
12
9
|
# @return [Apibc] API blockchains
|
13
|
-
attr_reader :api
|
14
10
|
# @return [Array<Hash>] todos os dados bigquery
|
15
|
-
attr_reader :bqd
|
16
11
|
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
17
|
-
attr_reader :ops
|
12
|
+
attr_reader :api, :bqd, :ops
|
18
13
|
|
19
14
|
TT = {
|
20
15
|
normal: {
|
21
16
|
new: :novnetht,
|
22
|
-
format: :
|
17
|
+
format: :foti,
|
23
18
|
header: "\ntx normal from to data valor",
|
24
19
|
sork: :srx,
|
25
20
|
adjk: :hash
|
26
21
|
},
|
27
22
|
internal: {
|
28
23
|
new: :novnethi,
|
29
|
-
format: :
|
24
|
+
format: :foti,
|
30
25
|
header: "\ntx intern from to data valor",
|
31
26
|
sork: :srx,
|
32
27
|
adjk: :hash
|
33
28
|
},
|
34
29
|
block: {
|
35
30
|
new: :novnethp,
|
36
|
-
format: :
|
31
|
+
format: :fop,
|
37
32
|
header: "\ntx block address data valor",
|
38
33
|
sork: :itx,
|
39
34
|
adjk: :blockNumber
|
40
35
|
},
|
41
36
|
token: {
|
42
37
|
new: :novnethk,
|
43
|
-
format: :
|
38
|
+
format: :fok,
|
44
39
|
header: "\ntx token from to data valor moeda",
|
45
40
|
sork: :srx,
|
46
41
|
adjk: :hash
|
47
42
|
},
|
48
43
|
withdrawal: {
|
49
44
|
new: :novnethw,
|
50
|
-
format: :
|
45
|
+
format: :fow,
|
51
46
|
header: "\nwithdrawal validator data valor",
|
52
47
|
sork: :itx,
|
53
48
|
adjk: :withdrawalIndex
|
@@ -57,59 +52,77 @@ module Cns
|
|
57
52
|
# @param [Hash] dad todos os dados bigquery
|
58
53
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
59
54
|
# @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
|
60
|
-
# @option pop [Boolean] :v (false) mostra dados transacoes
|
61
|
-
# @return [Etherscan] API etherscan - processar transacoes
|
55
|
+
# @option pop [Boolean] :v (false) mostra dados transacoes
|
56
|
+
# @return [Etherscan] API etherscan - processar transacoes
|
62
57
|
def initialize(dad, pop)
|
63
58
|
@api = Apibc.new
|
64
59
|
@bqd = dad
|
65
60
|
@ops = pop.transform_keys(&:to_sym)
|
66
61
|
end
|
67
62
|
|
68
|
-
#
|
63
|
+
# mostra resumo carteiras & transacoes & ajuste dias
|
69
64
|
def mresumo_simples
|
70
65
|
return unless dados.any?
|
71
66
|
|
72
67
|
puts("\nid address etherscan bigquery")
|
73
|
-
dados.each { |
|
68
|
+
dados.each { |o| puts(focs(o)) }
|
74
69
|
mtransacoes_novas
|
75
70
|
mconfiguracao_ajuste_dias
|
76
71
|
end
|
77
72
|
|
78
|
-
#
|
73
|
+
# mostra resumo carteiras & transacoes & ajuste dias (com contadores)
|
79
74
|
def mresumo
|
80
75
|
return unless dados.any?
|
81
76
|
|
82
77
|
puts("\nid address etherscan tn ti tb tk tw bigquery tn ti tb tk tw")
|
83
|
-
dados.each { |
|
78
|
+
dados.each { |o| puts(foct(o)) }
|
84
79
|
mtransacoes_novas
|
85
80
|
mconfiguracao_ajuste_dias
|
86
81
|
end
|
87
82
|
|
88
83
|
private
|
89
84
|
|
90
|
-
#
|
91
|
-
|
92
|
-
|
93
|
-
|
85
|
+
# mosta transacoes novas
|
86
|
+
def mtransacoes_novas
|
87
|
+
TT.each do |_, cfg|
|
88
|
+
ntx = send(cfg[:new])
|
89
|
+
next unless ops[:v] && ntx.any?
|
90
|
+
|
91
|
+
puts(cfg[:header])
|
92
|
+
ntx.sort_by { |s| -s[cfg[:sork]] }.each { |t| puts(send(cfg[:format], t)) }
|
93
|
+
end
|
94
94
|
end
|
95
95
|
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
# mostra configuration text for adjusting days
|
97
|
+
def mconfiguracao_ajuste_dias
|
98
|
+
TT.each do |typ, cfg|
|
99
|
+
ntx = send(cfg[:new])
|
100
|
+
next unless ntx.any?
|
101
|
+
|
102
|
+
puts("\najuste dias transacoes #{typ}\n-h=#{ntx.sort_by { |s| -s[cfg[:sork]] }.map { |t| "#{t[cfg[:adjk]]}:0" }.join(' ')}")
|
103
|
+
end
|
100
104
|
end
|
101
105
|
|
102
|
-
# @param
|
103
|
-
# @return [String] texto formatado
|
104
|
-
def
|
105
|
-
format(
|
106
|
+
# @param [Hash] hjn dados juntos bigquery & etherscan
|
107
|
+
# @return [String] texto formatado duma carteira
|
108
|
+
def focs(hjn)
|
109
|
+
format(
|
110
|
+
'%<s1>-6.6s %<s2>-42.42s %<v1>13.6f %<v2>13.6f %<ok>-3s',
|
111
|
+
s1: hjn[:id],
|
112
|
+
s2: hjn[:ax],
|
113
|
+
v1: hjn[:es],
|
114
|
+
v2: hjn[:bs],
|
115
|
+
ok: ok?(hjn) ? 'OK' : 'NOK'
|
116
|
+
)
|
106
117
|
end
|
107
118
|
|
108
|
-
# @param (see
|
109
|
-
# @return [String] texto formatado
|
110
|
-
def
|
119
|
+
# @param (see focs)
|
120
|
+
# @return [String] texto formatado duma carteira (com contadores)
|
121
|
+
def foct(hjn)
|
111
122
|
format(
|
112
|
-
'%<v1>11.4f %<n1>3i %<n2>2i %<n3>2i %<n4>2i %<w1>4i %<v2>11.4f %<n5>3i %<n6>2i %<n7>2i %<n8>2i %<w2>4i %<ok>-3s',
|
123
|
+
'%<s1>-6.6s %<s2>-10.10s %<v1>11.4f %<n1>3i %<n2>2i %<n3>2i %<n4>2i %<w1>4i %<v2>11.4f %<n5>3i %<n6>2i %<n7>2i %<n8>2i %<w2>4i %<ok>-3s',
|
124
|
+
s1: hjn[:id],
|
125
|
+
s2: foe1(hjn[:ax], 10),
|
113
126
|
v1: hjn[:es],
|
114
127
|
n1: hjn[:et].count,
|
115
128
|
n2: hjn[:ei].count,
|
@@ -126,25 +139,30 @@ module Cns
|
|
126
139
|
)
|
127
140
|
end
|
128
141
|
|
129
|
-
# @
|
142
|
+
# @param (see focs)
|
143
|
+
# @return [Boolean] check saldo & contadores ipwtk
|
130
144
|
def ok?(hjn)
|
131
145
|
oks?(hjn) && okipw?(hjn) && hjn[:bt].count == hjn[:et].count && hjn[:bk].count == hjn[:ek].count
|
132
146
|
end
|
133
147
|
|
148
|
+
# @param (see focs)
|
149
|
+
# @return [Boolean] check contadores ipw
|
134
150
|
def okipw?(hjn)
|
135
151
|
oks?(hjn) && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bw].count == hjn[:ew].count
|
136
152
|
end
|
137
153
|
|
138
|
-
# @
|
154
|
+
# @param (see focs)
|
155
|
+
# @return [Boolean] carteira tem transacoes novas (sim=NOK, nao=OK)?
|
139
156
|
def oks?(hjn)
|
140
157
|
hjn[:es].round(6) == hjn[:bs].round(6)
|
141
158
|
end
|
142
159
|
|
143
160
|
# @example ether address inicio..fim
|
144
161
|
# 0x10f3a0cf0b534c..c033cf32e8a03586
|
162
|
+
# @param [String] add endereco ETH
|
145
163
|
# @param [Integer] max chars a mostrar
|
146
164
|
# @return [String] endereco formatado
|
147
|
-
def
|
165
|
+
def foe1(add, max)
|
148
166
|
return 'erro' if max < 7
|
149
167
|
|
150
168
|
max -= 2
|
@@ -155,97 +173,137 @@ module Cns
|
|
155
173
|
|
156
174
|
# @example ether address inicio..fim
|
157
175
|
# me-app..4b437776403d
|
176
|
+
# @param add (see foe1)
|
158
177
|
# @param [Integer] max chars a mostrar
|
159
178
|
# @return [String] endereco formatado
|
160
|
-
def
|
179
|
+
def foe2(add, max)
|
161
180
|
return 'erro' if max < 7
|
162
181
|
|
163
182
|
max -= 2
|
164
183
|
ini = Integer(max / 2)
|
165
184
|
inf = max % 2
|
166
|
-
hid = bqd[:wb].find { |
|
185
|
+
hid = bqd[:wb].find { |o| o[:ax] == add }
|
167
186
|
ndd = hid ? "#{hid[:id]}-#{add}" : add
|
168
187
|
"#{ndd[0, ini]}..#{ndd[-inf - ini..]}"
|
169
188
|
end
|
170
189
|
|
171
|
-
# @
|
172
|
-
# @
|
173
|
-
|
174
|
-
def formata_tx_ti(htx)
|
190
|
+
# @param [Hash] htx transacao etherscan normal(t)/(i)nternal
|
191
|
+
# @return [String] texto formatado
|
192
|
+
def foti(htx)
|
175
193
|
format(
|
176
194
|
'%<hx>-29.29s %<fr>-15.15s %<to>-15.15s %<dt>10.10s %<vl>7.3f',
|
177
|
-
hx:
|
178
|
-
fr:
|
179
|
-
to:
|
195
|
+
hx: foe1(htx[:hash], 29),
|
196
|
+
fr: foe2(htx[:from], 15),
|
197
|
+
to: foe2(htx[:to], 15),
|
180
198
|
dt: htx[:timeStamp].strftime('%F'),
|
181
199
|
vl: htx[:value] / (10**18)
|
182
200
|
)
|
183
201
|
end
|
184
202
|
|
185
|
-
# @
|
186
|
-
# @
|
187
|
-
|
188
|
-
def formata_tx_token(hkx)
|
203
|
+
# @param [Hash] hkx transacao etherscan to(k)en
|
204
|
+
# @return [String] texto formatado
|
205
|
+
def fok(hkx)
|
189
206
|
format(
|
190
207
|
'%<hx>-20.20s %<fr>-15.15s %<to>-15.15s %<dt>10.10s %<vl>10.3f %<sy>-5.5s',
|
191
|
-
hx:
|
192
|
-
fr:
|
193
|
-
to:
|
208
|
+
hx: foe1(hkx[:hash], 20),
|
209
|
+
fr: foe2(hkx[:from], 15),
|
210
|
+
to: foe2(hkx[:to], 15),
|
194
211
|
dt: hkx[:timeStamp].strftime('%F'),
|
195
212
|
vl: hkx[:value] / (10**18),
|
196
213
|
sy: hkx[:tokenSymbol]
|
197
214
|
)
|
198
215
|
end
|
199
216
|
|
200
|
-
# @
|
201
|
-
# @
|
202
|
-
|
203
|
-
|
204
|
-
format(
|
205
|
-
'%<bn>9i %<fr>-41.41s %<dt>10.10s %<vl>17.6f',
|
206
|
-
bn: htx[:blockNumber],
|
207
|
-
fr: formata_enderec2(htx[:iax], 41),
|
208
|
-
dt: htx[:timeStamp].strftime('%F'),
|
209
|
-
vl: htx[:blockReward] / (10**18)
|
210
|
-
)
|
217
|
+
# @param [Hash] hpx transacao etherscan (p)roduced blocks
|
218
|
+
# @return [String] texto formatado
|
219
|
+
def fop(hpx)
|
220
|
+
format('%<bn>9i %<fr>-41.41s %<dt>10.10s %<vl>17.6f', bn: hpx[:blockNumber], fr: foe2(hpx[:iax], 41), dt: hpx[:timeStamp].strftime('%F'), vl: hpx[:blockReward] / (10**18))
|
211
221
|
end
|
212
222
|
|
213
|
-
# @
|
214
|
-
# @param [Hash] htx transacao withdrawals etherscan
|
223
|
+
# @param [Hash] hwx transacao etherscan (w)ithdrawals
|
215
224
|
# @return [String] texto formatado transacao withdrawals etherscan
|
216
|
-
def
|
217
|
-
format('%<bn>10i %<vi>9i %<dt>10.10s %<vl>10.6f', bn:
|
225
|
+
def fow(hwx)
|
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))
|
218
227
|
end
|
219
228
|
|
220
|
-
# @
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
229
|
+
# @param [Hash] abc account etherscan
|
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
|
225
243
|
|
226
|
-
|
227
|
-
|
228
|
-
|
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
|
+
}
|
229
265
|
end
|
230
266
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
ntx = send(cfg[:new])
|
235
|
-
next unless ntx.any?
|
267
|
+
def show_all?
|
268
|
+
ops[:t] || false
|
269
|
+
end
|
236
270
|
|
237
|
-
|
238
|
-
|
271
|
+
# @param [Hash] htx transacao
|
272
|
+
# @return [Hash] transaccao filtrada
|
273
|
+
def pess(htx)
|
274
|
+
tym = Integer(htx[:timeStamp])
|
275
|
+
htx.merge(srx: tym, timeStamp: Time.at(tym))
|
276
|
+
end
|
277
|
+
|
278
|
+
# @param add (see foe1)
|
279
|
+
# @param [Array<Hash>] ary lista transacoes normal(t)/(i)nternal/to(k)en
|
280
|
+
# @return [Array<Hash>] lista transacoes filtrada
|
281
|
+
def ftik(add, ary)
|
282
|
+
ary.map { |o| pess(o).merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d) }
|
283
|
+
end
|
284
|
+
|
285
|
+
# @param add (see foe1)
|
286
|
+
# @param [Array<Hash>] ary lista transacoes (p)roduced blocks
|
287
|
+
# @return [Array<Hash>] lista transacoes filtrada
|
288
|
+
def fppp(add, ary)
|
289
|
+
ary.map { |o| o.merge(itx: Integer(o[:blockNumber]), iax: add, blockReward: o[:blockReward].to_d, timeStamp: Time.at(Integer(o[:timeStamp]))) }
|
239
290
|
end
|
240
291
|
|
241
|
-
# @
|
292
|
+
# @param add (see foe1)
|
293
|
+
# @param [Array<Hash>] ary lista transacoes (w)ithdrawals
|
294
|
+
# @return [Array<Hash>] lista transacoes filtrada
|
295
|
+
def fwww(add, ary)
|
296
|
+
ary.map { |o| o.merge(itx: Integer(o[:withdrawalIndex]), iax: add, amount: o[:amount].to_d, timeStamp: Time.at(Integer(o[:timestamp]))) }
|
297
|
+
end
|
298
|
+
|
299
|
+
# @return [Array<String>] lista enderecos
|
242
300
|
def lax
|
243
|
-
@lax ||= bqd[:wb].map { |
|
301
|
+
@lax ||= bqd[:wb].map { |o| o[:ax] }
|
244
302
|
end
|
245
303
|
|
246
304
|
# @return [Array<Hash>] todos os dados etherscan - saldos & transacoes
|
247
305
|
def bcd
|
248
|
-
@bcd ||= api.account_es(lax).map { |
|
306
|
+
@bcd ||= api.account_es(lax).map { |o| base_bc(o) }
|
249
307
|
end
|
250
308
|
|
251
309
|
# @return [Array<Hash>] todos os dados juntos bigquery & etherscan
|
@@ -253,143 +311,79 @@ module Cns
|
|
253
311
|
@dados ||= bqd[:wb].map { |b| bq_bc(b, bcd.find { |e| b[:ax] == e[:ax] }) }
|
254
312
|
end
|
255
313
|
|
256
|
-
|
257
|
-
ops[:t] || false
|
258
|
-
end
|
259
|
-
|
314
|
+
# @return [Array<Integer>] indices transacoes bigquery
|
260
315
|
def bqidt
|
261
316
|
@bqidt ||= show_all? ? [] : (bqd[:nt]&.map { |i| i[:itx] } || [])
|
262
317
|
end
|
263
318
|
|
264
|
-
# @return [Array<Integer>]
|
265
|
-
def idt
|
266
|
-
@idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
267
|
-
end
|
268
|
-
|
319
|
+
# @return [Array<Integer>] indices transacoes bigquery
|
269
320
|
def bqidi
|
270
321
|
@bqidi ||= show_all? ? [] : (bqd[:ni]&.map { |i| i[:itx] } || [])
|
271
322
|
end
|
272
323
|
|
273
|
-
# @return [Array<Integer>]
|
274
|
-
def idi
|
275
|
-
@idi ||= bcd.map { |o| o[:ix].map { |i| i[:itx] } }.flatten - bqidi
|
276
|
-
end
|
277
|
-
|
324
|
+
# @return [Array<Integer>] indices transacoes bigquery
|
278
325
|
def bqidp
|
279
326
|
@bqidp ||= show_all? ? [] : (bqd[:np]&.map { |i| i[:itx] } || [])
|
280
327
|
end
|
281
328
|
|
282
|
-
# @return [Array<Integer>]
|
283
|
-
def idp
|
284
|
-
@idp ||= bcd.map { |o| o[:px].map { |i| i[:itx] } }.flatten - bqidp
|
285
|
-
end
|
286
|
-
|
329
|
+
# @return [Array<Integer>] indices transacoes bigquery
|
287
330
|
def bqidw
|
288
331
|
@bqidw ||= show_all? ? [] : (bqd[:nw]&.map { |i| i[:itx] } || [])
|
289
332
|
end
|
290
333
|
|
291
|
-
# @return [Array<Integer>]
|
292
|
-
def idw
|
293
|
-
@idw ||= bcd.map { |o| o[:wx].map { |i| i[:itx] } }.flatten - bqidw
|
294
|
-
end
|
295
|
-
|
334
|
+
# @return [Array<Integer>] indices transacoes bigquery
|
296
335
|
def bqidk
|
297
336
|
@bqidk ||= show_all? ? [] : (bqd[:nk]&.map { |i| i[:itx] } || [])
|
298
337
|
end
|
299
338
|
|
300
|
-
# @return [Array<Integer>]
|
301
|
-
def
|
302
|
-
@
|
339
|
+
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
340
|
+
def idt
|
341
|
+
@idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
303
342
|
end
|
304
343
|
|
305
|
-
# @
|
306
|
-
|
307
|
-
|
308
|
-
def base_bc(abc)
|
309
|
-
acc = abc[:account].downcase
|
310
|
-
{
|
311
|
-
ax: acc,
|
312
|
-
sl: abc[:balance].to_d / (10**18),
|
313
|
-
tx: ftik(acc, api.norml_es(acc)),
|
314
|
-
ix: ftik(acc, api.inter_es(acc)),
|
315
|
-
px: fppp(acc, api.block_es(acc)),
|
316
|
-
wx: fwww(acc, api.withw_es(acc)),
|
317
|
-
kx: ftik(acc, api.token_es(acc))
|
318
|
-
}
|
344
|
+
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
345
|
+
def idi
|
346
|
+
@idi ||= bcd.map { |o| o[:ix].map { |i| i[:itx] } }.flatten - bqidi
|
319
347
|
end
|
320
348
|
|
321
|
-
# @
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
|
335
|
-
es: hbc[:sl],
|
336
|
-
et: hbc[:tx],
|
337
|
-
ei: hbc[:ix],
|
338
|
-
ep: hbc[:px],
|
339
|
-
ew: hbc[:wx],
|
340
|
-
ek: hbc[:kx]
|
341
|
-
}
|
349
|
+
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
350
|
+
def idp
|
351
|
+
@idp ||= bcd.map { |o| o[:px].map { |i| i[:itx] } }.flatten - bqidp
|
352
|
+
end
|
353
|
+
|
354
|
+
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
355
|
+
def idw
|
356
|
+
@idw ||= bcd.map { |o| o[:wx].map { |i| i[:itx] } }.flatten - bqidw
|
357
|
+
end
|
358
|
+
|
359
|
+
# @return [Array<Integer>] indices transacoes novas (etherscan - bigquery)
|
360
|
+
def idk
|
361
|
+
@idk ||= bcd.map { |o| o[:kx].map { |i| i[:itx] } }.flatten - bqidk
|
342
362
|
end
|
343
363
|
|
344
364
|
# @return [Array<Hash>] lista transacoes normais novas
|
345
365
|
def novnetht
|
346
|
-
@novnetht ||= bcd.map { |
|
366
|
+
@novnetht ||= bcd.map { |o| o[:tx].select { |t| idt.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
347
367
|
end
|
348
368
|
|
349
369
|
# @return [Array<Hash>] lista transacoes internas novas
|
350
370
|
def novnethi
|
351
|
-
@novnethi ||= bcd.map { |
|
371
|
+
@novnethi ||= bcd.map { |o| o[:ix].select { |t| idi.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
352
372
|
end
|
353
373
|
|
354
374
|
# @return [Array<Hash>] lista transacoes block novas
|
355
375
|
def novnethp
|
356
|
-
@novnethp ||= bcd.map { |
|
376
|
+
@novnethp ||= bcd.map { |o| o[:px].select { |t| idp.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
357
377
|
end
|
358
378
|
|
359
379
|
# @return [Array<Hash>] lista transacoes withdrawals novas
|
360
380
|
def novnethw
|
361
|
-
@novnethw ||= bcd.map { |
|
381
|
+
@novnethw ||= bcd.map { |o| o[:wx].select { |t| idw.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
362
382
|
end
|
363
383
|
|
364
384
|
# @return [Array<Hash>] lista transacoes token novas
|
365
385
|
def novnethk
|
366
|
-
@novnethk ||= bcd.map { |
|
367
|
-
end
|
368
|
-
|
369
|
-
def pess(itm)
|
370
|
-
tym = Integer(itm[:timeStamp])
|
371
|
-
itm.merge(srx: tym, timeStamp: Time.at(tym))
|
372
|
-
end
|
373
|
-
|
374
|
-
# @param add (see Apibc#norml_es)
|
375
|
-
# @param [Array<Hash>] ary lista transacoes/token events
|
376
|
-
# @return [Array<Hash>] lista transacoes/token events filtrada
|
377
|
-
def ftik(add, ary)
|
378
|
-
ary.map { |o| pess(o).merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d) }
|
379
|
-
end
|
380
|
-
|
381
|
-
# @param add (see Apibc#norml_es)
|
382
|
-
# @param [Array<Hash>] ary lista blocks events
|
383
|
-
# @return [Array<Hash>] lista blocks events filtrada
|
384
|
-
def fppp(add, ary)
|
385
|
-
ary.map { |o| o.merge(itx: Integer(o[:blockNumber]), iax: add, blockReward: o[:blockReward].to_d, timeStamp: Time.at(Integer(o[:timeStamp]))) }
|
386
|
-
end
|
387
|
-
|
388
|
-
# @param add (see Apibc#norml_es)
|
389
|
-
# @param [Array<Hash>] ary lista blocks events
|
390
|
-
# @return [Array<Hash>] lista blocks events filtrada
|
391
|
-
def fwww(add, ary)
|
392
|
-
ary.map { |o| o.merge(itx: Integer(o[:withdrawalIndex]), iax: add, amount: o[:amount].to_d, timeStamp: Time.at(Integer(o[:timestamp]))) }
|
386
|
+
@novnethk ||= bcd.map { |o| o[:kx].select { |t| idk.include?(t[:itx]) } }.flatten.uniq { |i| i[:itx] }
|
393
387
|
end
|
394
388
|
end
|
395
389
|
end
|
data/lib/cns/greymass.rb
CHANGED
@@ -7,11 +7,17 @@ module Cns
|
|
7
7
|
# classe para processar transacoes do greymass
|
8
8
|
class Greymass
|
9
9
|
# @return [Apibc] API blockchains
|
10
|
-
attr_reader :api
|
11
10
|
# @return [Array<Hash>] todos os dados bigquery
|
12
|
-
attr_reader :bqd
|
13
11
|
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
14
|
-
attr_reader :ops
|
12
|
+
attr_reader :api, :bqd, :ops
|
13
|
+
|
14
|
+
TT = {
|
15
|
+
new: :novneost,
|
16
|
+
format: :fol,
|
17
|
+
header: "\nsequence num from to accao data valor moeda",
|
18
|
+
sork: :itx,
|
19
|
+
adjk: :itx
|
20
|
+
}
|
15
21
|
|
16
22
|
# @param [Hash] dad todos os dados bigquery
|
17
23
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
@@ -25,29 +31,38 @@ module Cns
|
|
25
31
|
@ops = pop.transform_keys(&:to_sym)
|
26
32
|
end
|
27
33
|
|
28
|
-
TT = {
|
29
|
-
new: :novneost,
|
30
|
-
format: :formata_ledger,
|
31
|
-
header: "\nsequence num from to accao data valor moeda",
|
32
|
-
sork: :itx,
|
33
|
-
adjk: :itx
|
34
|
-
}
|
35
|
-
|
36
34
|
# @return [String] texto carteiras & transacoes & ajuste dias
|
37
35
|
def mresumo
|
38
36
|
return unless dados.any?
|
39
37
|
|
40
38
|
puts("\naddress greymass ntx bigquery ntx")
|
41
|
-
dados.each { |
|
39
|
+
dados.each { |o| puts(foct(o)) }
|
42
40
|
mtransacoes_novas
|
43
41
|
mconfiguracao_ajuste_dias
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
47
45
|
|
46
|
+
# mosta transacoes novas
|
47
|
+
def mtransacoes_novas
|
48
|
+
ntx = send(TT[:new])
|
49
|
+
return unless ops[:v] && ntx.any?
|
50
|
+
|
51
|
+
puts(TT[:header])
|
52
|
+
ntx.sort_by { |s| -s[TT[:sork]] }.each { |t| puts(send(TT[:format], t)) }
|
53
|
+
end
|
54
|
+
|
55
|
+
# mostra configuration text for adjusting days
|
56
|
+
def mconfiguracao_ajuste_dias
|
57
|
+
ntx = send(TT[:new])
|
58
|
+
return unless ntx.any?
|
59
|
+
|
60
|
+
puts("\nstring ajuste dias\n-h=#{ntx.sort_by { |s| -s[TT[:sork]] }.map { |t| "#{t[TT[:adjk]]}:0" }.join(' ')}")
|
61
|
+
end
|
62
|
+
|
48
63
|
# @param [Hash] hjn dados juntos bigquery & greymass
|
49
64
|
# @return [String] texto formatado duma carteira
|
50
|
-
def
|
65
|
+
def foct(hjn)
|
51
66
|
format(
|
52
67
|
'%<s1>-12.12s %<v1>14.4f %<n1>4i %<v2>14.4f %<n2>4i %<ok>-3s',
|
53
68
|
s1: hjn[:ax],
|
@@ -59,16 +74,15 @@ module Cns
|
|
59
74
|
)
|
60
75
|
end
|
61
76
|
|
62
|
-
# @param (see
|
77
|
+
# @param (see foct)
|
63
78
|
# @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
|
64
79
|
def ok?(hjn)
|
65
80
|
hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
|
66
81
|
end
|
67
82
|
|
68
|
-
# @example (see Apibc#ledger_gm)
|
69
83
|
# @param [Hash] hlx ledger greymass
|
70
|
-
# @return [String] texto formatado
|
71
|
-
def
|
84
|
+
# @return [String] texto formatado
|
85
|
+
def fol(hlx)
|
72
86
|
format(
|
73
87
|
'%<bn>12i %<fr>-12.12s %<to>-12.12s %<ac>-10.10s %<dt>10.10s %<vl>12.4f %<sy>-6.6s',
|
74
88
|
ac: hlx[:name],
|
@@ -81,47 +95,6 @@ module Cns
|
|
81
95
|
)
|
82
96
|
end
|
83
97
|
|
84
|
-
# @return [String] Display new transactions based on verbose option
|
85
|
-
def mtransacoes_novas
|
86
|
-
ntx = send(TT[:new])
|
87
|
-
return unless ops[:v] && ntx.any?
|
88
|
-
|
89
|
-
puts(TT[:header])
|
90
|
-
ntx.sort_by { |s| -s[TT[:sork]] }.each { |t| puts(send(TT[:format], t)) }
|
91
|
-
end
|
92
|
-
|
93
|
-
# @return [String] texto configuracao ajuste dias das transacoes
|
94
|
-
def mconfiguracao_ajuste_dias
|
95
|
-
ntx = send(TT[:new])
|
96
|
-
return unless ntx.any?
|
97
|
-
|
98
|
-
puts("\nstring ajuste dias\n-h=#{ntx.sort_by { |s| -s[TT[:sork]] }.map { |t| "#{t[TT[:adjk]]}:0" }.join(' ')}")
|
99
|
-
end
|
100
|
-
|
101
|
-
# @return [Array<Hash>] todos os dados greymass - saldos & transacoes
|
102
|
-
def bcd
|
103
|
-
@bcd ||= bqd[:wb].map { |obj| base_bc(obj) }
|
104
|
-
end
|
105
|
-
|
106
|
-
# @return [Array<Hash>] todos os dados juntos bigquery & greymass
|
107
|
-
def dados
|
108
|
-
@dados ||= bqd[:wb].map { |b| bq_bc(b, bcd.find { |g| b[:ax] == g[:ax] }) }
|
109
|
-
end
|
110
|
-
|
111
|
-
def show_all?
|
112
|
-
ops[:t] || false
|
113
|
-
end
|
114
|
-
|
115
|
-
def bqidt
|
116
|
-
@bqidt ||= show_all? ? [] : (bqd[:nt]&.map { |i| i[:itx] } || [])
|
117
|
-
end
|
118
|
-
|
119
|
-
# @return [Array<Integer>] lista indices transacoes novas
|
120
|
-
def idt
|
121
|
-
@idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
122
|
-
end
|
123
|
-
|
124
|
-
# @example (see Apibc#account_gm)
|
125
98
|
# @param [Hash] wbq wallet bigquery
|
126
99
|
# @return [Hash] dados greymass - address, saldo & transacoes
|
127
100
|
def base_bc(wbq)
|
@@ -138,17 +111,17 @@ module Cns
|
|
138
111
|
id: wbq[:id],
|
139
112
|
ax: xbq,
|
140
113
|
bs: wbq[:sl],
|
141
|
-
bt: bqd[:nt].select { |
|
114
|
+
bt: bqd[:nt].select { |o| o[:iax] == xbq },
|
142
115
|
es: hbc[:sl],
|
143
116
|
et: hbc[:tx]
|
144
117
|
}
|
145
118
|
end
|
146
119
|
|
147
|
-
|
148
|
-
|
149
|
-
@novneost ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten
|
120
|
+
def show_all?
|
121
|
+
ops[:t] || false
|
150
122
|
end
|
151
123
|
|
124
|
+
# @param [String] add EOS account name
|
152
125
|
# @return [Array<BigDecimal>] lista recursos - liquido, net, spu
|
153
126
|
def peosa(add)
|
154
127
|
hac = api.account_gm(add)
|
@@ -156,7 +129,7 @@ module Cns
|
|
156
129
|
[hac[:core_liquid_balance].to_d, htr[:net_weight].to_d, htr[:cpu_weight].to_d]
|
157
130
|
end
|
158
131
|
|
159
|
-
# @param add (see
|
132
|
+
# @param add (see peosa)
|
160
133
|
# @param [Array<Hash>] ary lista transacoes
|
161
134
|
# @return [Array<Hash>] lista transacoes filtrada
|
162
135
|
def peost(add, ary)
|
@@ -178,5 +151,30 @@ module Cns
|
|
178
151
|
)
|
179
152
|
end
|
180
153
|
end
|
154
|
+
|
155
|
+
# @return [Array<Hash>] todos os dados greymass - saldos & transacoes
|
156
|
+
def bcd
|
157
|
+
@bcd ||= bqd[:wb].map { |o| base_bc(o) }
|
158
|
+
end
|
159
|
+
|
160
|
+
# @return [Array<Hash>] todos os dados juntos bigquery & greymass
|
161
|
+
def dados
|
162
|
+
@dados ||= bqd[:wb].map { |b| bq_bc(b, bcd.find { |g| b[:ax] == g[:ax] }) }
|
163
|
+
end
|
164
|
+
|
165
|
+
# @return [Array<Integer>] indices transacoes bigquery
|
166
|
+
def bqidt
|
167
|
+
@bqidt ||= show_all? ? [] : (bqd[:nt]&.map { |i| i[:itx] } || [])
|
168
|
+
end
|
169
|
+
|
170
|
+
# @return [Array<Integer>] indices transacoes novas (greymass - bigquery)
|
171
|
+
def idt
|
172
|
+
@idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
173
|
+
end
|
174
|
+
|
175
|
+
# @return [Array<Hash>] lista transacoes novas
|
176
|
+
def novneost
|
177
|
+
@novneost ||= bcd.map { |obc| obc[:tx].select { |o| idt.include?(o[:itx]) } }.flatten
|
178
|
+
end
|
181
179
|
end
|
182
180
|
end
|
data/lib/cns/kraken.rb
CHANGED
@@ -7,11 +7,9 @@ module Cns
|
|
7
7
|
# classe para processar transacoes trades/ledger do kraken
|
8
8
|
class Kraken
|
9
9
|
# @return [Apius] API kraken
|
10
|
-
attr_reader :api
|
11
10
|
# @return [Array<Hash>] todos os dados bigquery
|
12
|
-
attr_reader :bqd
|
13
11
|
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
14
|
-
attr_reader :ops
|
12
|
+
attr_reader :api, :bqd, :ops
|
15
13
|
|
16
14
|
# @param [Hash] dad todos os dados bigquery
|
17
15
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
@@ -33,7 +31,7 @@ module Cns
|
|
33
31
|
# @return [String] texto saldos & transacoes & ajuste dias
|
34
32
|
def mresumo
|
35
33
|
puts("\nKRAKEN\ntipo kraken bigquery")
|
36
|
-
exd[:sl].sort.each { |key, val| puts(
|
34
|
+
exd[:sl].sort.each { |key, val| puts(fos(key, val)) }
|
37
35
|
mtotais
|
38
36
|
|
39
37
|
mtrades
|
@@ -45,43 +43,37 @@ module Cns
|
|
45
43
|
|
46
44
|
private
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
46
|
+
# mosta contadores transacoes
|
47
|
+
def mtotais
|
48
|
+
vkt = exd[:kt].count
|
49
|
+
vnt = bqd[:nt].count
|
50
|
+
vkl = exd[:kl].count
|
51
|
+
vnl = bqd[:nl].count
|
55
52
|
|
56
|
-
|
57
|
-
|
53
|
+
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vkt, b: vnt, o: vkt == vnt ? 'OK' : 'NOK')}")
|
54
|
+
puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vkl, d: vnl, o: vkl == vnl ? 'OK' : 'NOK')}")
|
58
55
|
end
|
59
56
|
|
60
|
-
#
|
61
|
-
def
|
62
|
-
|
63
|
-
end
|
57
|
+
# mosta transacoes trades
|
58
|
+
def mtrades
|
59
|
+
return unless ops[:v] && novcust.any?
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
@kyl ||= exd[:kl].keys - bqkyl
|
61
|
+
puts("\ntrade data hora tipo par preco volume custo")
|
62
|
+
novcust.sort_by { |_, v| -v[:srx] }.each { |k, t| puts(fot(k, t)) }
|
68
63
|
end
|
69
64
|
|
70
|
-
#
|
71
|
-
def
|
72
|
-
|
73
|
-
end
|
65
|
+
# mosta transacoes ledger
|
66
|
+
def mledger
|
67
|
+
return unless ops[:v] && novcusl.any?
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
@novcusl ||= exd[:kl].slice(*kyl)
|
69
|
+
puts("\nledger data hora tipo moeda quantidade custo")
|
70
|
+
novcusl.sort_by { |_, v| -v[:srx] }.each { |k, t| puts(fol(k, t)) }
|
78
71
|
end
|
79
72
|
|
80
|
-
# @example (see Apice#account_us)
|
81
73
|
# @param [String] moe codigo kraken da moeda
|
82
74
|
# @param [BigDecimal] sal saldo kraken da moeda
|
83
75
|
# @return [String] texto formatado saldos
|
84
|
-
def
|
76
|
+
def fos(moe, sal)
|
85
77
|
vbq = bqd[:sl][moe.downcase.to_sym].to_d
|
86
78
|
format(
|
87
79
|
'%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
|
@@ -92,10 +84,10 @@ module Cns
|
|
92
84
|
)
|
93
85
|
end
|
94
86
|
|
95
|
-
# @
|
96
|
-
# @param
|
87
|
+
# @param [Symbol] idx id da transacao
|
88
|
+
# @param [Hash] htn trades kraken
|
97
89
|
# @return [String] texto formatado trade
|
98
|
-
def
|
90
|
+
def fot(idx, htx)
|
99
91
|
format(
|
100
92
|
'%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-8.8s %<pr>8.2f %<vl>10.4f %<co>13.2f',
|
101
93
|
ky: idx,
|
@@ -108,10 +100,10 @@ module Cns
|
|
108
100
|
)
|
109
101
|
end
|
110
102
|
|
111
|
-
# @
|
112
|
-
# @param
|
103
|
+
# @param idx (see fot)
|
104
|
+
# @param [Hash] hln ledger kraken
|
113
105
|
# @return [String] texto formatado ledger
|
114
|
-
def
|
106
|
+
def fol(idx, hlx)
|
115
107
|
format(
|
116
108
|
'%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-4.4s %<pr>18.7f %<vl>18.7f',
|
117
109
|
ky: idx,
|
@@ -123,39 +115,18 @@ module Cns
|
|
123
115
|
)
|
124
116
|
end
|
125
117
|
|
126
|
-
|
127
|
-
|
128
|
-
vkt = exd[:kt].count
|
129
|
-
vnt = bqd[:nt].count
|
130
|
-
vkl = exd[:kl].count
|
131
|
-
vnl = bqd[:nl].count
|
132
|
-
|
133
|
-
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vkt, b: vnt, o: vkt == vnt ? 'OK' : 'NOK')}")
|
134
|
-
puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vkl, d: vnl, o: vkl == vnl ? 'OK' : 'NOK')}")
|
135
|
-
end
|
136
|
-
|
137
|
-
# @return [String] texto transacoes trades
|
138
|
-
def mtrades
|
139
|
-
return unless ops[:v] && novcust.any?
|
140
|
-
|
141
|
-
puts("\ntrade data hora tipo par preco volume custo")
|
142
|
-
novcust.sort_by { |_, v| -v[:srx] }.each { |k, t| puts(formata_trades(k, t)) }
|
143
|
-
end
|
144
|
-
|
145
|
-
# @return [String] texto transacoes ledger
|
146
|
-
def mledger
|
147
|
-
return unless ops[:v] && novcusl.any?
|
148
|
-
|
149
|
-
puts("\nledger data hora tipo moeda quantidade custo")
|
150
|
-
novcusl.sort_by { |_, v| -v[:srx] }.each { |k, t| puts(formata_ledger(k, t)) }
|
118
|
+
def show_all?
|
119
|
+
ops[:t] || false
|
151
120
|
end
|
152
121
|
|
153
|
-
#
|
122
|
+
# @param [Hash] itm recursos kraken
|
123
|
+
# @return [Hash<BigDecimal>] moedas & sados
|
154
124
|
def pusa(itm)
|
155
125
|
itm.select { |k, _| EM.include?(k) }.transform_values { |v| v.to_d }
|
156
126
|
end
|
157
127
|
|
158
|
-
#
|
128
|
+
# @param [Hash] itm transacao kraken
|
129
|
+
# @return [Hash] transaccao filtrada
|
159
130
|
def pusk(itm)
|
160
131
|
itm.map do |k, v|
|
161
132
|
t = Integer(v[:time])
|
@@ -163,14 +134,46 @@ module Cns
|
|
163
134
|
end.to_h
|
164
135
|
end
|
165
136
|
|
166
|
-
#
|
167
|
-
|
168
|
-
|
137
|
+
# @param [Hash] htx trade kraken
|
138
|
+
# @return [Hash] transaccao filtrada
|
139
|
+
def pust(htx)
|
140
|
+
pusk(htx).transform_values { |t| t.merge(pair: t[:pair].upcase, price: t[:price].to_d, vol: t[:vol].to_d, cost: t[:cost].to_d) }
|
141
|
+
end
|
142
|
+
|
143
|
+
# @param [Hash] hlx ledger kraken
|
144
|
+
# @return [Hash] transaccao filtrada
|
145
|
+
def pusl(hlx)
|
146
|
+
pusk(hlx).transform_values { |t| t.merge(asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
|
147
|
+
end
|
148
|
+
|
149
|
+
# @return [Array<Symbol>] indices trades bigquery
|
150
|
+
def bqkyt
|
151
|
+
@bqkyt ||= show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid].to_sym } || [])
|
169
152
|
end
|
170
153
|
|
171
|
-
#
|
172
|
-
def
|
173
|
-
|
154
|
+
# @return [Array<Symbol>] indices ledger bigquery
|
155
|
+
def bqkyl
|
156
|
+
@bqkyl ||= show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid].to_sym } || [])
|
157
|
+
end
|
158
|
+
|
159
|
+
# @return [Array<Symbol>] lista txid trades novos
|
160
|
+
def kyt
|
161
|
+
@kyt ||= exd[:kt].keys - bqkyt
|
162
|
+
end
|
163
|
+
|
164
|
+
# @return [Array<Symbol>] lista txid ledger novos
|
165
|
+
def kyl
|
166
|
+
@kyl ||= exd[:kl].keys - bqkyl
|
167
|
+
end
|
168
|
+
|
169
|
+
# @return [Hash] trades kraken novos
|
170
|
+
def novcust
|
171
|
+
@novcust ||= exd[:kt].slice(*kyt)
|
172
|
+
end
|
173
|
+
|
174
|
+
# @return [Hash] ledger kraken novos
|
175
|
+
def novcusl
|
176
|
+
@novcusl ||= exd[:kl].slice(*kyl)
|
174
177
|
end
|
175
178
|
end
|
176
179
|
end
|
data/lib/cns/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hernâni Rodrigues Vaz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|