cns 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,280 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('openssl')
4
+ require('base64')
5
+ require('curb')
6
+ require('json')
7
+
8
+ # @author Hernani Rodrigues Vaz
9
+ module Cns
10
+ # classe para acesso dados centralized exchanges
11
+ class Apice
12
+ # @example trades_de
13
+ # {
14
+ # trades: [{
15
+ # trade_id: 'XUWWD3',
16
+ # trading_pair: 'btceur',
17
+ # is_external_wallet_trade: false,
18
+ # type: 'sell',
19
+ # amount_currency_to_trade: '0.1',
20
+ # price: 430,
21
+ # volume_currency_to_pay: 43,
22
+ # volume_currency_to_pay_after_fee: 42.79,
23
+ # amount_currency_to_trade_after_fee: 0.099,
24
+ # fee_currency_to_pay: 0.22,
25
+ # fee_currency_to_trade: '0.00100000',
26
+ # created_at: '2014-03-22T08:14:48+01:00',
27
+ # successfully_finished_at: '2014-03-25T14:03:22+01:00',
28
+ # state: 1,
29
+ # is_trade_marked_as_paid: true,
30
+ # trade_marked_as_paid_at: '2014-03-22T08:20:01+01:00',
31
+ # payment_method: 1,
32
+ # my_rating_for_trading_partner: 'positive',
33
+ # trading_partner_information: {
34
+ # username: 'emax2000',
35
+ # is_kyc_full: false,
36
+ # trust_level: 'bronze',
37
+ # amount_trades: 4,
38
+ # rating: 100,
39
+ # bank_name: 'CASSA DI RISPARMIO DI CIVITAVECCHIA SPA',
40
+ # bic: 'CRFIIT2CXXX',
41
+ # seat_of_bank: 'IT'
42
+ # }
43
+ # }, {}],
44
+ # page: { current: 1, last: 2 },
45
+ # errors: [],
46
+ # credits: 22
47
+ # }
48
+ # @param [Integer] pag pagina dos dados
49
+ # @param [Array<Hash>] ary acumulador dos dados
50
+ # @param [String] uri Uniform Resource Identifier do pedido HTTP
51
+ # @return [Array<Hash>] lista completa trades bitcoinde
52
+ def trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades')
53
+ p = "#{uri}?#{URI.encode_www_form(state: 1, page: pag + 1)}"
54
+ r = JSON.parse(
55
+ Curl.get(p) { |h| h.headers = hde(p) }.body,
56
+ symbolize_names: true
57
+ )
58
+ ary += r[:trades]
59
+ r[:page][:current] < r[:page][:last] ? trades_de(pag + 1, ary) : ary
60
+ rescue StandardError
61
+ ary
62
+ end
63
+
64
+ # @example deposits_de
65
+ # {
66
+ # deposits: [
67
+ # {
68
+ # deposit_id: '177245',
69
+ # txid: '84f9e85bc5709cd471e3d58a7d0f42d2c4a7bbd888cabf844e200efbf0a7fda2',
70
+ # address: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
71
+ # amount: '0.13283',
72
+ # confirmations: 6,
73
+ # state: 2,
74
+ # created_at: '2014-01-31T22:01:30+01:00'
75
+ # },
76
+ # {}
77
+ # ],
78
+ # page: { current: 1, last: 1 },
79
+ # errors: [],
80
+ # credits: 23
81
+ # }
82
+ # @param (see trades_de)
83
+ # @return [Array<Hash>] lista completa uniformizada depositos bitcoinde
84
+ def deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits')
85
+ p = "#{uri}?#{URI.encode_www_form(state: 2, page: pag + 1)}"
86
+ r = JSON.parse(
87
+ Curl.get(p) { |h| h.headers = hde(p) }.body,
88
+ symbolize_names: true
89
+ )
90
+ ary += deposits_unif_de(r)
91
+ r[:page][:current] < r[:page][:last] ? deposits_de(pag + 1, ary) : ary
92
+ rescue StandardError
93
+ ary
94
+ end
95
+
96
+ # @example withdrawals_de
97
+ # {
98
+ # withdrawals: [
99
+ # {
100
+ # withdrawal_id: '136605',
101
+ # address: '1K9YMDDrmMV25EoYNqi7KUEK57Kn3TCNUJ',
102
+ # amount: '0.120087',
103
+ # network_fee: '0',
104
+ # comment: '',
105
+ # created_at: '2014-02-05T13:01:09+01:00',
106
+ # txid: '6264fe528116fcb87c812a306ca8409eecfec8fa941546c86f98984b882c8042',
107
+ # transferred_at: '2014-02-05T13:05:17+01:00',
108
+ # state: 1
109
+ # },
110
+ # {}
111
+ # ],
112
+ # page: { current: 1, last: 2 },
113
+ # errors: [],
114
+ # credits: 23
115
+ # }
116
+ # @param (see deposits_de)
117
+ # @return [Array<Hash>] lista completa uniformizada withdrawals bitcoinde
118
+ def withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals')
119
+ p = "#{uri}?#{URI.encode_www_form(state: 1, page: pag + 1)}"
120
+ r = JSON.parse(
121
+ Curl.get(p) { |h| h.headers = hde(p) }.body,
122
+ symbolize_names: true
123
+ )
124
+ ary += withdrawals_unif_de(r)
125
+ r[:page][:current] < r[:page][:last] ? withdrawals_de(pag + 1, ary) : ary
126
+ rescue StandardError
127
+ ary
128
+ end
129
+
130
+ # @example ledger_fr
131
+ # [
132
+ # {
133
+ # uuid: '50551e61-4e74-4ae7-85fd-9c2040542818',
134
+ # currency_amount: nil,
135
+ # state: 'executed',
136
+ # btc_fee: '0.0',
137
+ # currency_fee: '0.0',
138
+ # created_at: '2014-03-04T09:00Z',
139
+ # updated_at: '2014-03-04T09:00Z',
140
+ # currency: 'EUR',
141
+ # comment: '5723',
142
+ # amount: '100.0',
143
+ # type: 'WireDeposit',
144
+ # account_operations: [{
145
+ # uuid: 'b5058a68-cf99-4438-86d3-e773eba418ec',
146
+ # name: 'wire_deposit',
147
+ # amount: '100.0',
148
+ # currency: 'EUR',
149
+ # created_at: '2014-03-04T09:00Z',
150
+ # created_at_int: 1_393_923_644,
151
+ # is_trading_account: false
152
+ # }, {}]
153
+ # },
154
+ # {}
155
+ # ]
156
+ # @param (see trades_de)
157
+ # @return [Array<Hash>] lista ledger paymium
158
+ def ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders')
159
+ r = JSON.parse(
160
+ Curl.get(uri, offset: pag) { |h| h.headers = hfr("#{uri}?#{URI.encode_www_form(offset: pag)}") }.body,
161
+ symbolize_names: true
162
+ )
163
+ r.empty? ? ary : ledger_fr(pag + r.size, ary + r)
164
+ rescue StandardError
165
+ ary
166
+ end
167
+
168
+ # @example ledger_mt
169
+ # {
170
+ # transactions: [
171
+ # {
172
+ # id: 305_445,
173
+ # date: '2014-03-06T10:59:13.000Z',
174
+ # type: 'withdraw',
175
+ # price: 97.47,
176
+ # currency: 'EUR',
177
+ # fund_id: nil,
178
+ # order_id: nil,
179
+ # trade_id: nil,
180
+ # note: 'BOV withdraw',
181
+ # transfer_detail: nil
182
+ # },
183
+ # {}
184
+ # ],
185
+ # meta: {
186
+ # total_count: nil,
187
+ # first: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
188
+ # previous: nil,
189
+ # current: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
190
+ # next: { page: 2, href: 'https://api.therocktrading.com/v1/transactions?page=2' },
191
+ # last: nil
192
+ # }
193
+ # }
194
+ # @param (see trades_de)
195
+ # @return [Array<Hash>] lista ledger therock
196
+ def ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions')
197
+ r = JSON.parse(
198
+ Curl.get(uri, page: pag) { |h| h.headers = hmt("#{uri}?#{URI.encode_www_form(page: pag)}") }.body,
199
+ symbolize_names: true
200
+ )[:transactions]
201
+ r.empty? ? ary : ledger_mt(pag + r.size, ary + r)
202
+ rescue StandardError
203
+ ary
204
+ end
205
+
206
+ # @example trades_us
207
+ # {
208
+ # error: [],
209
+ # result: {
210
+ # trades: {
211
+ # "TVINF5-TIOUB-YFNGKE": {
212
+ # ordertxid: 'ORPSUW-YKP4F-UJZOC6',
213
+ # pair: 'XETHXXBT',
214
+ # time: 1_463_435_684.8387,
215
+ # type: 'buy',
216
+ # ordertype: 'market',
217
+ # price: '0.024989',
218
+ # cost: '1.193973',
219
+ # fee: '0.003104',
220
+ # vol: '47.77994129',
221
+ # margin: '0.000000',
222
+ # misc: ''
223
+ # },
224
+ # "OUTRO-TRADE-ID": {}
225
+ # },
226
+ # count: 157
227
+ # }
228
+ # }
229
+ # @param [Integer] ofs offset dos dados
230
+ # @param [Hash] has acumulador dos dados
231
+ # @param (see account_us)
232
+ # @return [Hash] dados trades kraken
233
+ def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private', uri = 'TradesHistory', non = nnc)
234
+ r = JSON.parse(
235
+ Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |h| h.headers = hus(uri, nonce: non, ofs: ofs) }.body,
236
+ symbolize_names: true
237
+ )[:result]
238
+ has.merge!(r[:trades])
239
+ ofs += 50
240
+ ofs < r[:count] ? trades_us(ofs, has) : has
241
+ rescue StandardError
242
+ has
243
+ end
244
+
245
+ # @example ledger_us
246
+ # {
247
+ # error: [],
248
+ # result: {
249
+ # ledger: {
250
+ # "LXXURB-ITI7S-CXVERS": {
251
+ # refid: 'ACCHF3A-RIBBMO-VYBESY',
252
+ # time: 1_543_278_716.2775,
253
+ # type: 'withdrawal',
254
+ # subtype: '',
255
+ # aclass: 'currency',
256
+ # asset: 'ZEUR',
257
+ # amount: '-15369.6200',
258
+ # fee: '0.0900',
259
+ # balance: '0.0062'
260
+ # },
261
+ # "OUTRO-LEDGER-ID": {}
262
+ # },
263
+ # count: 376
264
+ # }
265
+ # }
266
+ # @param (see trades_us)
267
+ # @return [Hash] dados ledger kraken
268
+ def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private', uri = 'Ledgers', non = nnc)
269
+ r = JSON.parse(
270
+ Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |h| h.headers = hus(uri, nonce: non, ofs: ofs) }.body,
271
+ symbolize_names: true
272
+ )[:result]
273
+ has.merge!(r[:ledger])
274
+ ofs += 50
275
+ ofs < r[:count] ? ledger_us(ofs, has) : has
276
+ rescue StandardError
277
+ has
278
+ end
279
+ end
280
+ end
@@ -7,7 +7,7 @@ require('bigdecimal/util')
7
7
  module Cns
8
8
  BD = 'hernanirvaz.coins'
9
9
 
10
- # classe para processar bigquery
10
+ # (see Bigquery)
11
11
  class Bigquery
12
12
  # @return [Google::Cloud::Bigquery] API bigquery
13
13
  attr_reader :api
@@ -22,7 +22,7 @@ module Cns
22
22
  # @option pop [Hash] :h ({}) configuracao ajuste reposicionamento temporal
23
23
  # @option pop [Boolean] :v (false) mostra transacoes trades & ledger?
24
24
  # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
25
- # @return [Bigquery] API bigquery & kraken/bitcoinde/paymium/therock
25
+ # @return [Bigquery] API bigquery
26
26
  def initialize(pop)
27
27
  # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
28
28
  # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
@@ -30,57 +30,59 @@ module Cns
30
30
  @ops = pop
31
31
  end
32
32
 
33
- # situacao completa entre kraken/bitcoinde/paymium/therock & bigquery
33
+ # mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass & bigquery
34
34
  def mostra_tudo
35
- apius.mostra_resumo
36
- apide.mostra_resumo
35
+ # apius.mostra_resumo
36
+ # apide.mostra_resumo
37
37
  apifr.mostra_resumo
38
- apimt.mostra_resumo
39
- apies.mostra_resumo
40
- apigm.mostra_resumo
38
+ # apimt.mostra_resumo
39
+ # apies.mostra_resumo
40
+ # apigm.mostra_resumo
41
41
  end
42
42
 
43
- # insere (caso existam) transacoes novas do kraken/bitcoinde/paymium/therock no bigquery
43
+ # insere (caso existam) transacoes novas kraken/bitcoinde/paymium/therock/etherscan/greymass no bigquery
44
44
  def processa_tudo
45
45
  processa_us
46
46
  processa_de
47
47
  processa_fr
48
48
  processa_mt
49
- processa_eos
50
49
  processa_eth
50
+ processa_eos
51
51
  end
52
52
 
53
- # insere transacoes kraken novas nas tabelas ust (trades), usl (ledger)
53
+ private
54
+
55
+ # insere transacoes exchange kraken novas nas tabelas ust (trades), usl (ledger)
54
56
  def processa_us
55
57
  puts(format("%<n>2i TRADES KRAKEN INSERIDAS #{BD}.ust", n: apius.trades.empty? ? 0 : dml(ust_ins)))
56
58
  puts(format("%<n>2i LEDGER KRAKEN INSERIDAS #{BD}.usl", n: apius.ledger.empty? ? 0 : dml(usl_ins)))
57
59
  end
58
60
 
59
- # insere transacoes bitcoinde novas nas tabelas det (trades), del (ledger)
61
+ # insere transacoes exchange bitcoinde novas nas tabelas det (trades), del (ledger)
60
62
  def processa_de
61
63
  puts(format("%<n>2i TRADES BITCOINDE INSERIDAS #{BD}.det", n: apide.trades.empty? ? 0 : dml(det_ins)))
62
64
  puts(format("%<n>2i LEDGER BITCOINDE INSERIDAS #{BD}.del", n: apide.ledger.empty? ? 0 : dml(del_ins)))
63
65
  end
64
66
 
65
- # insere transacoes paymium novas na tabela fr (ledger)
67
+ # insere transacoes exchange paymium novas na tabela fr (ledger)
66
68
  def processa_fr
67
69
  puts(format("%<n>2i LEDGER PAYMIUM INSERIDAS #{BD}.fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
68
70
  end
69
71
 
70
- # insere transacoes paymium novas na tabela mt (ledger)
72
+ # insere transacoes exchange therock novas na tabela mt (ledger)
71
73
  def processa_mt
72
74
  puts(format("%<n>2i LEDGER THEROCK INSERIDAS #{BD}.mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
73
75
  end
74
76
 
75
- # insere transacoes novas na tabela eos
76
- def processa_eos
77
- puts(format("%<n>2i LINHAS INSERIDAS #{BD}.eos ", n: apigm.novax.count.positive? ? dml(eost_ins) : 0))
77
+ # insere transacoes blockchain novas nas tabelas etht (norml), ethk (token)
78
+ def processa_eth
79
+ puts(format("%<n>2i TRANSACOES ETH INSERIDAS #{BD}.etht", n: apies.novtx.empty? ? 0 : dml(etht_ins)))
80
+ puts(format("%<n>2i TOKEN EVENTS ETH INSERIDAS #{BD}.ethk", n: apies.novkx.empty? ? 0 : dml(ethk_ins)))
78
81
  end
79
82
 
80
- # insere transacoes novas nas tabelas etht (trx normais), ethk (trx token)
81
- def processa_eth
82
- puts(format("%<n>2i LINHAS INSERIDAS #{BD}.etht", n: apies.novtx.count.positive? ? dml(etht_ins) : 0))
83
- puts(format("%<n>2i LINHAS INSERIDAS #{BD}.ethk", n: apies.novkx.count.positive? ? dml(ethk_ins) : 0))
83
+ # insere transacoes blockchain novas na tabela eos
84
+ def processa_eos
85
+ puts(format("%<n>2i TRANSACOES EOS INSERIDAS #{BD}.eos ", n: apigm.novax.empty? ? 0 : dml(eost_ins)))
84
86
  end
85
87
 
86
88
  # cria job bigquery & verifica execucao
@@ -4,7 +4,9 @@
4
4
  module Cns
5
5
  # (see Bigquery)
6
6
  class Bigquery
7
- # @return [Etherscan] API etherscan
7
+ private
8
+
9
+ # @return [Etherscan] API blockchain ETH
8
10
  def apies
9
11
  @apies ||= Etherscan.new(
10
12
  {
@@ -16,7 +18,7 @@ module Cns
16
18
  )
17
19
  end
18
20
 
19
- # @return [Greymass] API greymass
21
+ # @return [Greymass] API blockchain EOS
20
22
  def apigm
21
23
  @apigm ||= Greymass.new(
22
24
  {
@@ -27,7 +29,7 @@ module Cns
27
29
  )
28
30
  end
29
31
 
30
- # @return [Kraken] API kraken - obter saldos & transacoes trades e ledger
32
+ # @return [Kraken] API exchange kraken
31
33
  def apius
32
34
  @apius ||= Kraken.new(
33
35
  {
@@ -39,7 +41,7 @@ module Cns
39
41
  )
40
42
  end
41
43
 
42
- # @return [Bitcoinde] API Bitcoinde - obter saldos & transacoes trades e ledger
44
+ # @return [Bitcoinde] API exchange bitcoinde
43
45
  def apide
44
46
  @apide ||= Bitcoinde.new(
45
47
  {
@@ -51,7 +53,7 @@ module Cns
51
53
  )
52
54
  end
53
55
 
54
- # @return [Paymium] API Paymium - obter saldos & transacoes ledger
56
+ # @return [Paymium] API exchange paymium
55
57
  def apifr
56
58
  @apifr ||= Paymium.new(
57
59
  {
@@ -62,7 +64,7 @@ module Cns
62
64
  )
63
65
  end
64
66
 
65
- # @return [TheRock] API TheRock - obter saldos & transacoes ledger
67
+ # @return [TheRock] API exchange therock
66
68
  def apimt
67
69
  @apimt ||= TheRock.new(
68
70
  {
@@ -5,16 +5,20 @@ require('bigdecimal/util')
5
5
 
6
6
  # @author Hernani Rodrigues Vaz
7
7
  module Cns
8
- # classe para processar etherscan/greymass & bigquery
8
+ # (see Bigquery)
9
9
  class Bigquery
10
- # @return [String] comando insert SQL formatado etht (trx normais)
10
+ private
11
+
12
+ # @return [String] comando insert SQL formatado etht (norml)
11
13
  def etht_ins
12
14
  "insert #{BD}.etht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
13
15
  'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias' \
14
16
  ") VALUES#{apies.novtx.map { |e| etht_val1(e) }.join(',')}"
15
17
  end
16
18
 
17
- # @return [String] valores formatados etht (trx normais parte1)
19
+ # @example (see Apibc#norml_es)
20
+ # @param [Hash] htx transacao norml etherscan
21
+ # @return [String] valores formatados etht (norml parte1)
18
22
  def etht_val1(htx)
19
23
  "(#{Integer(htx[:blockNumber])}," \
20
24
  "#{Integer(htx[:timeStamp])}," \
@@ -28,7 +32,8 @@ module Cns
28
32
  "#{etht_val2(htx)}"
29
33
  end
30
34
 
31
- # @return [String] valores formatados etht (trx normais parte2)
35
+ # @param (see etht_val1)
36
+ # @return [String] valores formatados etht (norml parte2)
32
37
  def etht_val2(htx)
33
38
  "cast('#{htx[:value]}' as numeric)," \
34
39
  "cast('#{htx[:gas]}' as numeric)," \
@@ -39,21 +44,24 @@ module Cns
39
44
  "#{etht_val3(htx)}"
40
45
  end
41
46
 
42
- # @return [String] valores formatados etht (trx normais parte3)
47
+ # @param (see etht_val1)
48
+ # @return [String] valores formatados etht (norml parte3)
43
49
  def etht_val3(htx)
44
50
  "#{htx[:input].length.zero? ? 'null' : "'#{htx[:input]}'"}," \
45
51
  "#{htx[:contractAddress].length.zero? ? 'null' : "'#{htx[:contractAddress]}'"}," \
46
52
  "#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
47
53
  end
48
54
 
49
- # @return [String] comando insert SQL formatado ethk (trx token)
55
+ # @return [String] comando insert SQL formatado ethk (token)
50
56
  def ethk_ins
51
57
  "insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
52
58
  'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
53
59
  ") VALUES#{apies.novkx.map { |e| ethk_val1(e) }.join(',')}"
54
60
  end
55
61
 
56
- # @return [String] valores formatados ethk (trx token parte1)
62
+ # @example (see Apibc#token_es)
63
+ # @param [Hash] hkx token event etherscan
64
+ # @return [String] valores formatados ethk (token parte1)
57
65
  def ethk_val1(hkx)
58
66
  "(#{Integer(hkx[:blockNumber])}," \
59
67
  "#{Integer(hkx[:timeStamp])}," \
@@ -67,7 +75,8 @@ module Cns
67
75
  "#{ethk_val2(hkx)}"
68
76
  end
69
77
 
70
- # @return [String] valores formatados ethk (trx token parte2)
78
+ # @param (see ethk_val1)
79
+ # @return [String] valores formatados ethk (token parte2)
71
80
  def ethk_val2(hkx)
72
81
  "cast('#{hkx[:value]}' as numeric)," \
73
82
  "'#{hkx[:tokenName]}'," \
@@ -79,7 +88,8 @@ module Cns
79
88
  "#{ethk_val3(hkx)}"
80
89
  end
81
90
 
82
- # @return [String] valores formatados ethk (trx token parte3)
91
+ # @param (see ethk_val1)
92
+ # @return [String] valores formatados ethk (token parte3)
83
93
  def ethk_val3(hkx)
84
94
  "#{hkx[:input].length.zero? ? 'null' : "'#{hkx[:input]}'"}," \
85
95
  "#{hkx[:contractAddress].length.zero? ? 'null' : "'#{hkx[:contractAddress]}'"}," \
@@ -92,31 +102,33 @@ module Cns
92
102
  ") VALUES#{apigm.novax.map { |e| eost_val1(e) }.join(',')}"
93
103
  end
94
104
 
95
- # @param [Hash] htx transacao ligadas a uma carteira - sem elementos irrelevantes
105
+ # @example (see Apibc#ledger_gm)
106
+ # @param [Hash] hlx ledger greymass
96
107
  # @return [String] valores formatados para insert eos (parte1)
97
- def eost_val1(htx)
98
- a = htx[:action_trace][:act]
99
- "(#{htx[:global_action_seq]}," \
100
- "#{htx[:account_action_seq]}," \
101
- "#{htx[:block_num]}," \
102
- "DATETIME(TIMESTAMP('#{htx[:block_time]}'))," \
108
+ def eost_val1(hlx)
109
+ a = hlx[:action_trace][:act]
110
+ "(#{hlx[:global_action_seq]}," \
111
+ "#{hlx[:account_action_seq]}," \
112
+ "#{hlx[:block_num]}," \
113
+ "DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
103
114
  "'#{a[:account]}'," \
104
115
  "'#{a[:name]}'," \
105
- "#{eost_val2(htx, a)}"
116
+ "#{eost_val2(hlx, a)}"
106
117
  end
107
118
 
108
- # @param [Hash] htx transacao ligadas a uma carteira - sem elementos irrelevantes
119
+ # @param (see eost_val1)
120
+ # @param [Hash] act dados da acao
109
121
  # @return [String] valores formatados para insert eos (parte2)
110
- def eost_val2(htx, act)
122
+ def eost_val2(hlx, act)
111
123
  d = act[:data]
112
124
  q = d[:quantity].to_s
113
125
  s = d[:memo].inspect
114
126
  "'#{d[:from]}'," \
115
127
  "'#{d[:to]}'," \
116
- "'#{htx[:iax]}'," \
128
+ "'#{hlx[:iax]}'," \
117
129
  "#{q.to_d},'#{q[/[[:upper:]]+/]}'," \
118
130
  "nullif('#{s.gsub(/['"]/, '')}','nil')," \
119
- "#{ops[:h][String(htx[:itx])] || 0})"
131
+ "#{ops[:h][String(hlx[:itx])] || 0})"
120
132
  end
121
133
  end
122
134
  end