eost 0.1.4 → 0.1.10
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 +12 -0
- data/Gemfile.lock +14 -14
- data/README.md +2 -2
- data/eost.gemspec +2 -4
- data/lib/eost.rb +38 -24
- data/lib/eost/bigquery.rb +128 -55
- data/lib/eost/carteiras.rb +109 -0
- data/lib/eost/eosscan.rb +214 -0
- data/lib/eost/folhacalculo.rb +49 -53
- data/lib/eost/formatar.rb +66 -0
- data/lib/eost/version.rb +1 -1
- data/specs/chain.json +256 -0
- data/specs/history.json +54 -0
- data/specs/wallet.json +12 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d031951cd05d284d8e679971217766af5810b1477ec50f764de21434e6ed1365
|
4
|
+
data.tar.gz: 6d6c4f0ef603b7a716d723c61760b5e25ace70df9fb60551560822f2a69c9ca4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fe57e184c412367a17d3b3f037366ce6f7300da4c5988dcbaec8ca2bbbc3f619ab7b7f49647cd93e2fe5cbc15e502c5dd0366bfe9113248f8ff2ee90bfdce32
|
7
|
+
data.tar.gz: 5cc3f5058ca1b3009094c6ecc298c9887efff89d8a7552a280924b47476e6b29c2e7521c83998694cb56b6a4ed7b5b240f6b68863315ba84367d5a7449bb127c
|
data/.rubocop.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eost (0.1.
|
4
|
+
eost (0.1.10)
|
5
5
|
google-cloud-bigquery
|
6
6
|
roo
|
7
7
|
thor
|
@@ -12,12 +12,12 @@ GEM
|
|
12
12
|
specs:
|
13
13
|
addressable (2.7.0)
|
14
14
|
public_suffix (>= 2.0.2, < 5.0)
|
15
|
-
concurrent-ruby (1.1.
|
16
|
-
declarative (0.0.
|
15
|
+
concurrent-ruby (1.1.7)
|
16
|
+
declarative (0.0.20)
|
17
17
|
declarative-option (0.1.0)
|
18
18
|
faraday (1.0.1)
|
19
19
|
multipart-post (>= 1.2, < 3)
|
20
|
-
google-api-client (0.
|
20
|
+
google-api-client (0.44.0)
|
21
21
|
addressable (~> 2.5, >= 2.5.1)
|
22
22
|
googleauth (~> 0.9)
|
23
23
|
httpclient (>= 2.8.1, < 3.0)
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
representable (~> 3.0)
|
26
26
|
retriable (>= 2.0, < 4.0)
|
27
27
|
signet (~> 0.12)
|
28
|
-
google-cloud-bigquery (1.21.
|
28
|
+
google-cloud-bigquery (1.21.2)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
30
|
google-api-client (~> 0.33)
|
31
31
|
google-cloud-core (~> 1.2)
|
@@ -34,10 +34,10 @@ GEM
|
|
34
34
|
google-cloud-core (1.5.0)
|
35
35
|
google-cloud-env (~> 1.0)
|
36
36
|
google-cloud-errors (~> 1.0)
|
37
|
-
google-cloud-env (1.3.
|
37
|
+
google-cloud-env (1.3.3)
|
38
38
|
faraday (>= 0.17.3, < 2.0)
|
39
|
-
google-cloud-errors (1.0.
|
40
|
-
googleauth (0.
|
39
|
+
google-cloud-errors (1.0.1)
|
40
|
+
googleauth (0.13.1)
|
41
41
|
faraday (>= 0.17.3, < 2.0)
|
42
42
|
jwt (>= 1.4, < 3.0)
|
43
43
|
memoist (~> 0.16)
|
@@ -45,16 +45,16 @@ GEM
|
|
45
45
|
os (>= 0.9, < 2.0)
|
46
46
|
signet (~> 0.14)
|
47
47
|
httpclient (2.8.3)
|
48
|
-
jwt (2.2.
|
48
|
+
jwt (2.2.2)
|
49
49
|
memoist (0.16.2)
|
50
50
|
mini_mime (1.0.2)
|
51
51
|
mini_portile2 (2.4.0)
|
52
|
-
multi_json (1.
|
52
|
+
multi_json (1.15.0)
|
53
53
|
multipart-post (2.1.1)
|
54
|
-
nokogiri (1.10.
|
54
|
+
nokogiri (1.10.10)
|
55
55
|
mini_portile2 (~> 2.4.0)
|
56
|
-
os (1.1.
|
57
|
-
public_suffix (4.0.
|
56
|
+
os (1.1.1)
|
57
|
+
public_suffix (4.0.5)
|
58
58
|
rake (12.3.3)
|
59
59
|
representable (3.0.4)
|
60
60
|
declarative (< 0.1.0)
|
@@ -72,7 +72,7 @@ GEM
|
|
72
72
|
multi_json (~> 1.10)
|
73
73
|
thor (1.0.1)
|
74
74
|
uber (0.1.0)
|
75
|
-
yard (0.9.
|
75
|
+
yard (0.9.25)
|
76
76
|
|
77
77
|
PLATFORMS
|
78
78
|
ruby
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hernanirvaz/eost. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hernanirvaz/eost/blob/master/CODE_OF_CONDUCT.md).
|
36
36
|
|
37
37
|
|
38
38
|
## License
|
@@ -41,4 +41,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
41
|
|
42
42
|
## Code of Conduct
|
43
43
|
|
44
|
-
Everyone interacting in the Eost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
44
|
+
Everyone interacting in the Eost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hernanirvaz/eost/blob/master/CODE_OF_CONDUCT.md).
|
data/eost.gemspec
CHANGED
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.license = 'MIT'
|
12
12
|
|
13
13
|
spec.summary = 'Arquiva eos-transactions.csv no bigquery.'
|
14
|
-
spec.description = spec.summary +
|
15
|
-
' Pode apagar movimentos existentes ja no bigquery.'
|
14
|
+
spec.description = spec.summary + ' Pode apagar movimentos existentes ja no bigquery.'
|
16
15
|
|
17
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
17
|
spec.metadata['yard.run'] = 'yard'
|
@@ -22,8 +21,7 @@ Gem::Specification.new do |spec|
|
|
22
21
|
# Specify which files should be added to the gem when it is released.
|
23
22
|
# The `git ls-files -z` loads files in RubyGem that have been added into git.
|
24
23
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
-
`git ls-files -z`.split("\x0")
|
26
|
-
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
25
|
end
|
28
26
|
spec.bindir = 'exe'
|
29
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
data/lib/eost.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require('thor')
|
4
|
+
require('eost/bigquery')
|
5
|
+
require('eost/carteiras')
|
6
|
+
require('eost/eosscan')
|
7
|
+
require('eost/folhacalculo')
|
8
|
+
require('eost/formatar')
|
9
|
+
require('eost/version')
|
7
10
|
|
11
|
+
# @author Hernani Rodrigues Vaz
|
8
12
|
module Eost
|
9
13
|
ID = `whoami`.chomp
|
10
14
|
|
@@ -12,33 +16,43 @@ module Eost
|
|
12
16
|
|
13
17
|
# CLI para carregar folhas calculo comuns no bigquery
|
14
18
|
class CLI < Thor
|
15
|
-
desc '
|
16
|
-
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
|
17
|
-
|
18
|
-
option :
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# processa csv
|
23
|
-
def load
|
24
|
-
# opcoes apagar linhas
|
19
|
+
desc 'workfc', 'carrega/apaga dados da folha calculo'
|
20
|
+
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads", desc: 'Onde procurar folhas calculo'
|
21
|
+
option :x, banner: 'EXT', default: '.csv', desc: 'Extensao das folhas calculo'
|
22
|
+
option :e, type: :boolean, default: false, desc: 'apaga linha igual'
|
23
|
+
option :m, type: :boolean, default: false, desc: 'apaga linhas existencia multipla'
|
24
|
+
# processa folha calculo
|
25
|
+
def workfc
|
25
26
|
Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
|
26
|
-
Bigquery.new(f, options[:e]).
|
27
|
+
Bigquery.new(f, { e: options[:e], m: options[:m], i: true }).processa_csv
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
desc '
|
31
|
-
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# mostra csv
|
36
|
-
def mostra
|
31
|
+
desc 'showfc', 'mostra dados da folha calculo'
|
32
|
+
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads", desc: 'Onde procurar folhas calculo'
|
33
|
+
option :x, banner: 'EXT', default: '.csv', desc: 'Extensao das folhas calculo'
|
34
|
+
# show folha calculo
|
35
|
+
def showfc
|
37
36
|
Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
|
38
|
-
Bigquery.new(f).
|
37
|
+
Bigquery.new(f).processa_csv
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
|
-
|
41
|
+
desc 'work', 'carrega transacoes novas no bigquery'
|
42
|
+
option :h, type: :hash, default: {}, desc: 'configuracao ajuste reposicionamento temporal'
|
43
|
+
# carrega transacoes novas no bigquery
|
44
|
+
def work
|
45
|
+
Bigquery.new('', options).processa
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'show', 'mostra reumo carteiras & transacoes'
|
49
|
+
option :v, type: :boolean, default: false, desc: 'mostra transacoes'
|
50
|
+
option :t, type: :boolean, default: false, desc: 'mostra transacoes todas ou somente novas'
|
51
|
+
# mostra reumo carteiras & transacoes
|
52
|
+
def show
|
53
|
+
Bigquery.new('', options).carteiras.mostra_resumo
|
54
|
+
end
|
55
|
+
|
56
|
+
default_task :show
|
43
57
|
end
|
44
58
|
end
|
data/lib/eost/bigquery.rb
CHANGED
@@ -1,93 +1,166 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require('roo')
|
4
|
+
require('google/cloud/bigquery')
|
5
5
|
|
6
6
|
module Eost
|
7
|
+
BD = 'hernanirvaz.coins'
|
7
8
|
DF = '%Y-%m-%d'
|
8
9
|
DI = '%Y-%m-%d %H:%M:%S'
|
9
10
|
|
10
|
-
#
|
11
|
+
# (see Bigquery)
|
11
12
|
class Bigquery
|
12
|
-
# @return [Roo::
|
13
|
-
attr_reader :
|
14
|
-
# @return [
|
15
|
-
attr_reader :
|
13
|
+
# @return [Roo::CSV] folha calculo a processar
|
14
|
+
attr_reader :folha
|
15
|
+
# @return [Hash<Symbol, Boolean>] opcoes trabalho com linhas
|
16
|
+
attr_reader :linha
|
17
|
+
|
16
18
|
# @return [Google::Cloud::Bigquery] API bigquery
|
17
19
|
attr_reader :api
|
20
|
+
# @return [Array] row folha calculo em processamento
|
21
|
+
attr_reader :row
|
18
22
|
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
|
19
23
|
attr_reader :job
|
20
|
-
# @return (see
|
21
|
-
attr_reader :
|
22
|
-
# @return [Boolean] apaga linhas existentes sim/nao?
|
23
|
-
attr_reader :apaga
|
24
|
+
# @return (see sql)
|
25
|
+
attr_reader :sqr
|
24
26
|
|
25
|
-
# permite processa folhas calculo comuns no bigquery
|
26
|
-
#
|
27
27
|
# @param [String] csv folha calculo para processar
|
28
|
-
# @param [Boolean]
|
29
|
-
# @
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
# @param [Hash<Symbol, Boolean>] ops opcoes trabalho com linhas
|
29
|
+
# @option ops [Boolean] :e (false) apaga linha igual?
|
30
|
+
# @option ops [Boolean] :m (false) apaga linhas existencia multipla?
|
31
|
+
# @option ops [Boolean] :i (false) insere linha nova?
|
32
|
+
# @return [Bigquery] acesso folhas calculo bloks.io & correspondente bigquery dataset
|
33
|
+
def initialize(csv = '', ops = { e: false, m: false, i: false })
|
34
|
+
@folha = Roo::CSV.new(csv) if csv.size.positive?
|
35
|
+
@linha = ops
|
36
|
+
|
33
37
|
# usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
|
34
38
|
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
35
39
|
@api = Google::Cloud::Bigquery.new
|
36
40
|
end
|
37
41
|
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
# @return [Carteiras] API eosscan - processar transacoes
|
43
|
+
def transacoes
|
44
|
+
@transacoes ||= Carteiras.new(
|
45
|
+
{
|
46
|
+
wb: sql("select * from #{BD}.walletEos order by 1").map { |e| { ax: e[:weos], sl: e[:eos].to_d } },
|
47
|
+
nt: sql("select blocknumber,iax from #{BD}.eostx order by 1")
|
48
|
+
},
|
49
|
+
linha
|
50
|
+
)
|
47
51
|
end
|
48
52
|
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
# @return [Integer] numero linhas afetadas
|
53
|
-
def dml(sql)
|
54
|
-
job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
|
53
|
+
# @return [Carteiras] API eosscan - processar carteiras & transacoes
|
54
|
+
def carteiras
|
55
|
+
transacoes
|
55
56
|
end
|
56
57
|
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
def sql_select
|
61
|
-
# se array.count > 1 => nao fazer nada
|
62
|
-
@sql = job_bigquery?('select * ' + sql_where) ? [{}, {}] : job.data
|
58
|
+
# insere transacoes novas na tabela eos
|
59
|
+
def processa
|
60
|
+
puts(format("%<n>2i LINHAS INSERIDAS #{BD}.eos", n: transacoes.novas.count.positive? ? eos_insert_api : 0))
|
63
61
|
end
|
64
62
|
|
65
|
-
# @return [String]
|
63
|
+
# @return [String] campos da tabela eos no bigquery
|
64
|
+
def eos_fields
|
65
|
+
'blocknumber,time,contract,action,acfrom,acto,amount,symbol,memo,data,dias'
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [String] parte sql para processamento linhas existentes
|
66
69
|
def sql_where
|
67
|
-
"from
|
70
|
+
"from #{BD}.eos where blocknumber=#{row[0]}"
|
68
71
|
end
|
69
72
|
|
70
73
|
# @return [Integer] numero linhas inseridas
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
def eos_insert_csv
|
75
|
+
return 1 unless linha[:i]
|
76
|
+
|
77
|
+
dml("INSERT #{BD}.eos(#{eos_fields}) VALUES(#{eos_csv_val1})")
|
75
78
|
end
|
76
79
|
|
77
|
-
# @return [String]
|
78
|
-
def
|
79
|
-
"#{row[0]},
|
80
|
+
# @return [String] valores formatados para insert eos (parte1)
|
81
|
+
def eos_csv_val1
|
82
|
+
"#{row[0]}," \
|
83
|
+
"'#{Time.parse(row[1]).strftime(DI)}'," \
|
84
|
+
"'#{row[2]}'," \
|
85
|
+
"#{eos_csv_val2}"
|
80
86
|
end
|
81
87
|
|
82
|
-
# @return [String]
|
83
|
-
def
|
84
|
-
"'#{row[3]}',
|
85
|
-
"'#{row[
|
88
|
+
# @return [String] valores formatados para insert eos (parte2)
|
89
|
+
def eos_csv_val2
|
90
|
+
"'#{row[3]}'," \
|
91
|
+
"'#{row[4]}'," \
|
92
|
+
"'#{row[5]}'," \
|
93
|
+
"#{Float(row[6])}," \
|
94
|
+
"'#{row[7]}'," \
|
95
|
+
"'#{row[8]}'," \
|
96
|
+
"'#{row[9]}',0"
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [Integer] numero linhas inseridas
|
100
|
+
def eos_insert_api
|
101
|
+
dml("INSERT #{BD}.eos(#{eos_fields}) VALUES#{transacoes.novas.map { |e| eos_api_val1(e) }.join(',')}")
|
86
102
|
end
|
87
103
|
|
88
|
-
# @
|
89
|
-
|
90
|
-
|
104
|
+
# @param [Hash] htx transacao ligadas a uma carteira - sem elementos irrelevantes
|
105
|
+
# @return [String] valores formatados para insert eos (parte1)
|
106
|
+
def eos_api_val1(htx)
|
107
|
+
"(#{Integer(htx['block_num'])}," \
|
108
|
+
"DATETIME(TIMESTAMP('#{htx['block_time']}'))," \
|
109
|
+
"'#{act(htx)['account']}'," \
|
110
|
+
"'#{act(htx)['name']}'," \
|
111
|
+
"'#{act_data(htx)['from']}'," \
|
112
|
+
"'#{act_data(htx)['to']}'," \
|
113
|
+
"#{eos_api_val2(htx)}"
|
114
|
+
end
|
115
|
+
|
116
|
+
# @param [Hash] htx transacao ligadas a uma carteira - sem elementos irrelevantes
|
117
|
+
# @return [String] valores formatados para insert eos (parte2)
|
118
|
+
def eos_api_val2(htx)
|
119
|
+
"#{act_data(htx)['quantity'].to_d}," \
|
120
|
+
"'#{act_data(htx)['quantity'][/[[:upper:]]+/]}'," \
|
121
|
+
"'#{act_data(htx)['memo']}'," \
|
122
|
+
"'#{act_data(htx)}'," \
|
123
|
+
"#{Integer(linha[:h][String(htx['block_num'])] || 0)})"
|
124
|
+
end
|
125
|
+
|
126
|
+
# @param [Hash] htx transacao normal
|
127
|
+
# @return [Hash] dados da acao
|
128
|
+
def act(htx)
|
129
|
+
htx['action_trace']['act']
|
130
|
+
end
|
131
|
+
|
132
|
+
# @param [Hash] htx transacao normal
|
133
|
+
# @return [Hash] dados da acao
|
134
|
+
def act_data(htx)
|
135
|
+
act(htx)['data']
|
136
|
+
end
|
137
|
+
|
138
|
+
# cria job bigquery & verifica execucao
|
139
|
+
#
|
140
|
+
# @param cmd (see sql)
|
141
|
+
# @return [Boolean] job ok?
|
142
|
+
def job?(cmd)
|
143
|
+
@job = api.query_job(cmd)
|
144
|
+
@job.wait_until_done!
|
145
|
+
puts(@job.error['message']) if @job.failed?
|
146
|
+
@job.failed?
|
147
|
+
end
|
148
|
+
|
149
|
+
# cria Structured Query Language (SQL) job bigquery
|
150
|
+
#
|
151
|
+
# @param [String] cmd comando SQL a executar
|
152
|
+
# @param [Array<Hash>] red resultado quando SQL tem erro
|
153
|
+
# @return [Google::Cloud::Bigquery::Data] resultado do SQL
|
154
|
+
def sql(cmd, red = [])
|
155
|
+
@sqr = job?(cmd) ? red : job.data
|
156
|
+
end
|
157
|
+
|
158
|
+
# cria Data Manipulation Language (DML) job bigquery
|
159
|
+
#
|
160
|
+
# @param cmd (see sql)
|
161
|
+
# @return [Integer] numero linhas afetadas
|
162
|
+
def dml(cmd)
|
163
|
+
job?(cmd) ? 0 : job.num_dml_affected_rows
|
91
164
|
end
|
92
165
|
end
|
93
166
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('bigdecimal/util')
|
4
|
+
|
5
|
+
# @author Hernani Rodrigues Vaz
|
6
|
+
module Eost
|
7
|
+
# classe para processar carteiras & transacoes
|
8
|
+
class Carteiras
|
9
|
+
# @return [Eosscan] API eosscan
|
10
|
+
attr_reader :api
|
11
|
+
# @return [Array<Hash>] todos os dados bigquery
|
12
|
+
attr_reader :dbq
|
13
|
+
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
14
|
+
attr_reader :ops
|
15
|
+
# @return [Array<Integer>] lista blocknumbers transacoes no bigquery - condicionados por opcoes iniciais
|
16
|
+
attr_reader :abn
|
17
|
+
|
18
|
+
# @param [Hash] dad todos os dados bigquery
|
19
|
+
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
20
|
+
# @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
|
21
|
+
# @option pop [Boolean] :v (false) mostra dados transacoes?
|
22
|
+
# @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
|
23
|
+
# @return [Carteiras] API eosscan - processar transacoes
|
24
|
+
def initialize(dad, pop)
|
25
|
+
@api = Eosscan.new
|
26
|
+
@dbq = dad
|
27
|
+
@ops = pop
|
28
|
+
@abn = (ops[:t] ? [] : dbq[:nt].map { |t| t[:blocknumber] })
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Array<Hash>] todos os dados eosscan - saldos & transacoes
|
32
|
+
def des
|
33
|
+
@des ||= dbq[:wb].map { |e| base_eosscan(e) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Array<Hash>] todos os dados juntos bigquery & eosscan
|
37
|
+
def djn
|
38
|
+
@djn ||= dbq[:wb].map { |b| bigquery_eosscan(b, des.select { |s| b[:ax] == s[:ax] }.first) }
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Array<Integer>] lista blocknumbers de transacoes novas
|
42
|
+
def bnn
|
43
|
+
@bnn ||= (des.map { |e| e[:tx].map { |n| Integer(n['block_num']) } }.flatten - abn)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Array<Hash>] lista transacoes novas
|
47
|
+
def novas
|
48
|
+
@novas ||= des.map { |e| e[:tx].select { |s| bnn.include?(Integer(s['block_num'])) } }.flatten.uniq
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Array<Hash>] lista ordenada transacoes novas
|
52
|
+
def novas_sort
|
53
|
+
novas.sort { |a, b| Integer(a['block_num']) <=> Integer(b['block_num']) }
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [Hash] hwb wallet bigquery eos
|
57
|
+
# @return [Hash] dados eosscan - address, saldo & transacoes
|
58
|
+
def base_eosscan(hwb)
|
59
|
+
{
|
60
|
+
ax: hwb[:ax],
|
61
|
+
sl: eosscan_sl(hwb[:ax]).inject(:+),
|
62
|
+
tx: eosscan_tx(hwb[:ax])
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param (see bigquery_eosscan)
|
67
|
+
# @return [Hash<Array, Boolean>] lista blocknumbers novos & carteira ok?
|
68
|
+
def novas_ok(hwb, hes)
|
69
|
+
# quando todas as transacoes obtidas da api vao ser inseridas,
|
70
|
+
# entao podem ficar transacoes por inserir - api consegue apenas um maximo de 100 transacoes
|
71
|
+
n = hes[:tx].map { |v| Integer(v['block_num']) } - abn
|
72
|
+
{ nn: n, ok: hwb[:sl] == hes[:sl] && n.count < hes[:tx].count }
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param hwb (see base_eosscan)
|
76
|
+
# @param [Hash] hes dados eosscan
|
77
|
+
# @return [Hash] dados juntos bigquery & eosscan
|
78
|
+
def bigquery_eosscan(hwb, hes)
|
79
|
+
{
|
80
|
+
id: hwb[:id],
|
81
|
+
ax: hwb[:ax],
|
82
|
+
bs: hwb[:sl],
|
83
|
+
bt: dbq[:nt].select { |t| t[:iax] == hwb[:ax] },
|
84
|
+
es: hes[:sl],
|
85
|
+
et: hes[:tx]
|
86
|
+
}.merge(novas_ok(hwb, hes))
|
87
|
+
end
|
88
|
+
|
89
|
+
# @param [String] add endereco carteira EOS
|
90
|
+
# @return [Array<BigDecimal>] lista recursos - liquido, net, spu
|
91
|
+
def eosscan_sl(add)
|
92
|
+
v = api.chain_get_account(account_name: add)
|
93
|
+
[
|
94
|
+
v['core_liquid_balance'].to_d,
|
95
|
+
v['total_resources']['net_weight'].to_d,
|
96
|
+
v['total_resources']['cpu_weight'].to_d
|
97
|
+
]
|
98
|
+
end
|
99
|
+
|
100
|
+
# @param (see eosscan_sl)
|
101
|
+
# @return [Array<Hash>] lista ultimas 100 transacoes ligadas a uma carteira - sem elementos irrelevantes
|
102
|
+
def eosscan_tx(add)
|
103
|
+
api.history_get_actions(account_name: add, offset: -100)['actions'].map do |e|
|
104
|
+
e.delete('global_action_seq')
|
105
|
+
e
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|