eost 0.1.5 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -0
- data/.travis.yml +1 -1
- data/Gemfile.lock +14 -14
- data/README.md +3 -3
- 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: c56d6856a474ba9665cca2a7ffe0c2da80f7f59a3805f39894ceb44251b63fcb
|
4
|
+
data.tar.gz: 2f394e34158e52bf521024224b76cc882bbbbff322722b15b3d8b6893014cca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d7f1a21656bede1d81a0d9c808e1bdcefc8699bb015e6c534c758c058b72d411bd863be4093da1ff3d5ce7d39803b9632ad2b2b43e3f5b24b0ee12b0fee3b73
|
7
|
+
data.tar.gz: 5ac5bf0c4f779688b85bd3c67f26d2988dd5223f7fa36d18b0ded364e0d44a8ed1c3a6d96ef8f069447b10d00f4cb583678d9d0baaf520f0562eff355953982f
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
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.11)
|
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
@@ -1,4 +1,4 @@
|
|
1
|
-
# Eost [![Build Status](https://travis-ci.com/hernanirvaz/
|
1
|
+
# Eost [![Build Status](https://travis-ci.com/hernanirvaz/eost.svg?branch=master)](https://travis-ci.com/hernanirvaz/eost)
|
2
2
|
|
3
3
|
Arquiva eos-transactions.csv no bigquery. Pode apagar movimentos existentes ja no bigquery.
|
4
4
|
|
@@ -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
|