cns 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2877c747c139b72d545038365090e1fbcb59c81765fa1148d8df42fad5e41b1d
4
- data.tar.gz: c41981db14030be80f42b0e0ab6854029bf17a6139252b8b54327e5322dada49
3
+ metadata.gz: da09bc00042879c60ab8a13b28b3dbe0a3d94cc7ed2ff59140dd77cce58b15ef
4
+ data.tar.gz: 71e31f61372c2b3038fad8f8193540716d4ec6c180aae4a9165080da5716a654
5
5
  SHA512:
6
- metadata.gz: 78c94bf76ba9186e059ea685cb8f7f2dc60b977f4c006b9f220bdd7872c34864f676e3e429f21f3f0482c40af4288deaba3540bd860e54cfb1eff91cef720d23
7
- data.tar.gz: d40243a18acc0c830f30bbbea36ad2f86b948cee06527a378bde11848db21fc19d17a1bd8de36ce63c6f8fb269dc59e26145e7e47da573b63b514243746657ed
6
+ metadata.gz: 863ef89dc981204b33cd4967d3c040fa5b70e6697d954ed77397d8b2e18da2bb4023f2eb359c762c6656c746215b46637bb075649fc4239c3b228a19ece0481a
7
+ data.tar.gz: 98bf85c399dd0b99d5bed870ce696ee5c8e302e2402ab1c84f7109cff35ad0f591a3f39dbe4d55ebda45692625b76facd052d6879711df416ce5a5cbde379ef7
data/.rubocop.yml CHANGED
@@ -2,12 +2,66 @@
2
2
  AllCops:
3
3
  TargetRubyVersion: 3.1
4
4
  EnabledByDefault: true
5
+ NewCops: enable # Automatically enable new cops introduced in updates
5
6
 
7
+ Metrics/ClassLength:
8
+ Enabled: false
9
+
10
+ Metrics/ParameterLists:
11
+ Enabled: false
12
+
13
+ Metrics/MethodLength:
14
+ Max: 25
15
+
16
+ Metrics/AbcSize:
17
+ Max: 40
18
+
19
+ # Formatting Rules
20
+ Layout/LineLength:
21
+ Max: 160
22
+ AllowHeredoc: true
23
+ AllowURI: true
24
+
25
+ Layout/IndentationWidth:
26
+ Width: 2
27
+
28
+ Layout/SpaceInsideHashLiteralBraces:
29
+ EnforcedStyle: space
30
+
31
+ Layout/SingleLineBlockChain:
32
+ Enabled: false
33
+
34
+ Layout/SpaceInsideParens:
35
+ Enabled: true
36
+
37
+ # Style Preferences
6
38
  Style/Copyright:
7
39
  Enabled: false
8
40
 
9
- Lint/ConstantResolution:
41
+ Style/Documentation:
42
+ Enabled: false
43
+
44
+ Style/RequireOrder:
10
45
  Enabled: false
11
46
 
12
47
  Style/ConstantVisibility:
13
48
  Enabled: false
49
+
50
+ Style/OptionHash:
51
+ Enabled: false
52
+
53
+ Style/StringLiterals:
54
+ EnforcedStyle: single_quotes
55
+
56
+ Style/NumericLiterals:
57
+ MinDigits: 5
58
+
59
+ # Linting
60
+ Lint/UselessAssignment:
61
+ Enabled: true
62
+
63
+ Lint/AmbiguousOperatorPrecedence:
64
+ Enabled: true
65
+
66
+ Lint/ConstantResolution:
67
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.7.9)
4
+ cns (0.8.0)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
@@ -18,9 +18,9 @@ GEM
18
18
  benchmark (0.4.0)
19
19
  bigdecimal (3.1.9)
20
20
  concurrent-ruby (1.3.5)
21
- curb (1.0.8)
21
+ curb (1.0.9)
22
22
  declarative (0.0.20)
23
- diff-lcs (1.5.1)
23
+ diff-lcs (1.6.0)
24
24
  dry-configurable (1.3.0)
25
25
  dry-core (~> 1.1)
26
26
  zeitwerk (~> 2.6)
@@ -99,15 +99,14 @@ GEM
99
99
  kramdown-parser-gfm (1.1.0)
100
100
  kramdown (~> 2.0)
101
101
  language_server-protocol (3.17.0.4)
102
- logger (1.6.5)
102
+ lint_roller (1.1.0)
103
+ logger (1.6.6)
103
104
  mini_mime (1.1.5)
104
- mini_portile2 (2.8.8)
105
105
  multi_json (1.15.0)
106
106
  mutex_m (0.3.0)
107
107
  net-http (0.6.0)
108
108
  uri
109
- nokogiri (1.18.2)
110
- mini_portile2 (~> 2.8.2)
109
+ nokogiri (1.18.2-x86_64-linux-gnu)
111
110
  racc (~> 1.4)
112
111
  observer (0.1.2)
113
112
  os (1.1.4)
@@ -136,10 +135,11 @@ GEM
136
135
  retriable (3.1.2)
137
136
  reverse_markdown (3.0.0)
138
137
  nokogiri
139
- rexml (3.4.0)
140
- rubocop (1.71.2)
138
+ rexml (3.4.1)
139
+ rubocop (1.72.1)
141
140
  json (~> 2.3)
142
- language_server-protocol (>= 3.17.0)
141
+ language_server-protocol (~> 3.17.0.2)
142
+ lint_roller (~> 1.1.0)
143
143
  parallel (~> 1.10)
144
144
  parser (>= 3.3.0.2)
145
145
  rainbow (>= 2.2.2, < 4.0)
@@ -149,10 +149,10 @@ GEM
149
149
  unicode-display_width (>= 2.4.0, < 4.0)
150
150
  rubocop-ast (1.38.0)
151
151
  parser (>= 3.3.1.0)
152
- rubocop-rake (0.6.0)
153
- rubocop (~> 1.0)
152
+ rubocop-rake (0.7.1)
153
+ lint_roller (~> 1.1)
154
+ rubocop (>= 1.72.1)
154
155
  ruby-progressbar (1.13.0)
155
- rufo (0.18.0)
156
156
  signet (0.19.0)
157
157
  addressable (~> 2.8)
158
158
  faraday (>= 0.17.5, < 3.a)
@@ -197,9 +197,8 @@ DEPENDENCIES
197
197
  reek
198
198
  rubocop
199
199
  rubocop-rake
200
- rufo
201
200
  solargraph
202
201
  yard
203
202
 
204
203
  BUNDLED WITH
205
- 2.3.7
204
+ 2.6.3
data/cns.gemspec CHANGED
@@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency('reek')
32
32
  spec.add_development_dependency('rubocop')
33
33
  spec.add_development_dependency('rubocop-rake')
34
- spec.add_development_dependency('rufo')
35
34
  spec.add_development_dependency('solargraph')
36
35
  spec.add_development_dependency('yard')
37
36
 
@@ -39,4 +38,5 @@ Gem::Specification.new do |spec|
39
38
  spec.add_dependency('faraday')
40
39
  spec.add_dependency('google-cloud-bigquery')
41
40
  spec.add_dependency('thor')
41
+ spec.metadata['rubygems_mfa_required'] = 'true'
42
42
  end
data/lib/cns/apibc.rb CHANGED
@@ -12,7 +12,7 @@ module Cns
12
12
  # @return [Array<Hash>] List of addresses with balances
13
13
  def account_es(addresses)
14
14
  response = etherscan_req('balancemulti', addresses.join(','), 1, tag: 'latest')
15
- response[:status] == '1' ? response.dig(:result) : []
15
+ response[:status] == '1' ? response[:result] : []
16
16
  end
17
17
 
18
18
  # Get EOS account information
@@ -80,24 +80,14 @@ module Cns
80
80
  # Reusable Faraday connection
81
81
  def connection(base_url)
82
82
  Faraday.new(base_url) do |conn|
83
- conn.headers = {
84
- content_type: 'application/json',
85
- accept: 'application/json',
86
- user_agent: 'blockchain-api-client'
87
- }
83
+ conn.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'blockchain-api-client' }
88
84
  conn.adapter(Faraday.default_adapter)
89
85
  end
90
86
  end
91
87
 
92
88
  # Generic Etherscan API request handler
93
89
  def etherscan_req(action, address, page = 1, params = {})
94
- params = {
95
- module: 'account',
96
- action: action,
97
- address: address,
98
- page: page,
99
- apikey: ENV.fetch('ETHERSCAN_API_KEY')
100
- }.merge(params)
90
+ params = { module: 'account', action: action, address: address, page: page, apikey: ENV.fetch('ETHERSCAN_API_KEY') }.merge(params)
101
91
  parse_json(connection('https://api.etherscan.io').get('/api', params).body)
102
92
  rescue Faraday::Error, JSON::ParserError
103
93
  { status: '0', result: [] }
data/lib/cns/apice.rb CHANGED
@@ -55,10 +55,7 @@ module Cns
55
55
  # @param non (see hde)
56
56
  # @return [Hash] saldos no kraken
57
57
  def account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc)
58
- JSON.parse(
59
- Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body,
60
- symbolize_names: true
61
- )[:result]
58
+ JSON.parse(Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body, symbolize_names: true)[:result]
62
59
  rescue StandardError
63
60
  {}
64
61
  end
@@ -158,12 +155,7 @@ module Cns
158
155
  # ]
159
156
  # @return [Hash] deposit uniformizado bitcoinde
160
157
  def deposit_unif(has)
161
- {
162
- add: has[:address],
163
- time: Time.parse(has[:created_at]),
164
- qt: has[:amount],
165
- txid: Integer(has[:deposit_id])
166
- }.merge(tp: 'deposit', moe: 'btc', fee: '0')
158
+ { add: has[:address], time: Time.parse(has[:created_at]), qt: has[:amount], txid: Integer(has[:deposit_id]) }.merge(tp: 'deposit', moe: 'btc', fee: '0')
167
159
  end
168
160
 
169
161
  # @example withdrawals_de
@@ -249,16 +241,14 @@ module Cns
249
241
  # @param [Hash] has acumulador dos dados
250
242
  # @param (see account_us)
251
243
  # @return [Hash] dados trades kraken
252
- def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private')
253
- uri = 'TradesHistory'
254
- non = nnc
244
+ def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private', uri = 'TradesHistory', non = nnc)
255
245
  res = JSON.parse(
256
246
  Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
257
247
  symbolize_names: true
258
248
  )[:result]
259
249
  has.merge!(res[:trades])
260
- sleep 2
261
- res[:trades].count > 0 ? trades_us(ofs + res[:trades].count, has) : has
250
+ sleep(2)
251
+ res[:trades].count.positive? ? trades_us(ofs + res[:trades].count, has) : has
262
252
  rescue StandardError
263
253
  has
264
254
  end
@@ -286,16 +276,14 @@ module Cns
286
276
  # }
287
277
  # @param (see trades_us)
288
278
  # @return [Hash] dados ledger kraken
289
- def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private')
290
- uri = 'Ledgers'
291
- non = nnc
279
+ def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private', uri = 'Ledgers', non = nnc)
292
280
  res = JSON.parse(
293
281
  Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
294
282
  symbolize_names: true
295
283
  )[:result]
296
284
  has.merge!(res[:ledger])
297
- sleep 2
298
- res[:ledger].count > 0 ? ledger_us(ofs + res[:ledger].count, has) : has
285
+ sleep(2)
286
+ res[:ledger].count.positive? ? ledger_us(ofs + res[:ledger].count, has) : has
299
287
  rescue StandardError
300
288
  has
301
289
  end
@@ -434,13 +422,13 @@ module Cns
434
422
  # @param [Integer] non continually-increasing unsigned integer
435
423
  # @return [Hash] headers necessarios para pedido HTTP da exchange bitcoinde
436
424
  def hde(qde, non = nnc)
437
- key = ENV['BITCOINDE_API_KEY']
425
+ key = ENV.fetch('BITCOINDE_API_KEY', nil)
438
426
  {
439
427
  'X-API-KEY': key,
440
428
  'X-API-NONCE': non,
441
429
  'X-API-SIGNATURE': OpenSSL::HMAC.hexdigest(
442
430
  'sha256',
443
- ENV['BITCOINDE_API_SECRET'],
431
+ ENV.fetch('BITCOINDE_API_SECRET', nil),
444
432
  ['GET', qde, key, non, Digest::MD5.hexdigest('')].join('#')
445
433
  )
446
434
  }
@@ -476,11 +464,11 @@ module Cns
476
464
  # @return [Hash] headers necessarios para pedido HTTP da exchange kraken
477
465
  def hus(qus, ops)
478
466
  {
479
- 'api-key': ENV['KRAKEN_API_KEY'],
467
+ 'api-key': ENV.fetch('KRAKEN_API_KEY', nil),
480
468
  'api-sign': Base64.strict_encode64(
481
469
  OpenSSL::HMAC.digest(
482
470
  'sha512',
483
- Base64.decode64(ENV['KRAKEN_API_SECRET']),
471
+ Base64.decode64(ENV.fetch('KRAKEN_API_SECRET', nil)),
484
472
  ['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
485
473
  )
486
474
  )
data/lib/cns/bigquery.rb CHANGED
@@ -6,7 +6,7 @@ require('bigdecimal/util')
6
6
  # @author Hernani Rodrigues Vaz
7
7
  module Cns
8
8
  BD = 'hernanirvaz.coins'
9
- FO = File.expand_path('~/' + File.basename($0) + '.log')
9
+ FO = File.expand_path("~/#{File.basename($PROGRAM_NAME)}.log")
10
10
 
11
11
  # classe para processar bigquery
12
12
  class Bigquery
@@ -52,18 +52,18 @@ module Cns
52
52
 
53
53
  # @return [String] texto inicial transacoes
54
54
  def trs_ini
55
- Time.now.strftime("TRANSACOES %Y-%m-%d %H:%M:%S ")
55
+ Time.now.strftime('TRANSACOES %Y-%m-%d %H:%M:%S ')
56
56
  end
57
57
 
58
58
  # insere (caso existam) dados novos kraken/bitcoinde/paymium/therock/etherscan/greymass no bigquery
59
59
  def processa_tudo
60
- str = processa_us + ", " + processa_de + ", " + processa_eth + ", " + processa_eos
60
+ str = "#{processa_us}, #{processa_de}, #{processa_eth}, #{processa_eos}"
61
61
  puts(trs_ini + str)
62
62
  end
63
63
 
64
64
  # insere (caso existam) dados novos kraken/etherscan no bigquery
65
65
  def processa_wkrk
66
- str = processa_us + ", " + processa_eth
66
+ str = "#{processa_us}, #{processa_eth}"
67
67
  puts(trs_ini + str)
68
68
  end
69
69
 
@@ -85,12 +85,12 @@ module Cns
85
85
  #
86
86
  # @return [String] linhas & tabelas afetadas
87
87
  def processa_eth
88
- str = "ETH"
89
- str += format(" %<n>i netht", n: dml(netht_ins)) if apies.novtx.count > 0
90
- str += format(" %<n>i nethi", n: dml(nethi_ins)) if apies.novix.count > 0
91
- str += format(" %<n>i nethp", n: dml(nethp_ins)) if apies.novpx.count > 0
92
- str += format(" %<n>i nethw", n: dml(nethw_ins)) if apies.novwx.count > 0
93
- str += format(" %<n>i nethk", n: dml(nethk_ins)) if apies.novkx.count > 0
88
+ str = 'ETH'
89
+ str += format(' %<n>i netht', n: dml(netht_ins)) if apies.novtx.count.positive?
90
+ str += format(' %<n>i nethi', n: dml(nethi_ins)) if apies.novix.count.positive?
91
+ str += format(' %<n>i nethp', n: dml(nethp_ins)) if apies.novpx.count.positive?
92
+ str += format(' %<n>i nethw', n: dml(nethw_ins)) if apies.novwx.count.positive?
93
+ str += format(' %<n>i nethk', n: dml(nethk_ins)) if apies.novkx.count.positive?
94
94
  str
95
95
  end
96
96
 
@@ -98,12 +98,12 @@ module Cns
98
98
  #
99
99
  # @return [String] linhas & tabelas afetadas
100
100
  def processa_ethc
101
- str = "ETH"
102
- str += format(" %<n>i netht", n: dml(netbt_ins)) if apiesc.novtx.count > 0
103
- str += format(" %<n>i nethi", n: dml(netbi_ins)) if apiesc.novix.count > 0
104
- str += format(" %<n>i nethp", n: dml(netbp_ins)) if apiesc.novpx.count > 0
105
- str += format(" %<n>i nethw", n: dml(netbw_ins)) if apiesc.novwx.count > 0
106
- str += format(" %<n>i nethk", n: dml(netbk_ins)) if apiesc.novkx.count > 0
101
+ str = 'ETH'
102
+ str += format(' %<n>i netht', n: dml(netbt_ins)) if apiesc.novtx.count.positive?
103
+ str += format(' %<n>i nethi', n: dml(netbi_ins)) if apiesc.novix.count.positive?
104
+ str += format(' %<n>i nethp', n: dml(netbp_ins)) if apiesc.novpx.count.positive?
105
+ str += format(' %<n>i nethw', n: dml(netbw_ins)) if apiesc.novwx.count.positive?
106
+ str += format(' %<n>i nethk', n: dml(netbk_ins)) if apiesc.novkx.count.positive?
107
107
  str
108
108
  end
109
109
 
@@ -111,9 +111,9 @@ module Cns
111
111
  #
112
112
  # @return [String] linhas & tabelas afetadas
113
113
  def processa_us
114
- str = "KRAKEN"
115
- str += format(" %<n>i ust", n: dml(ust_ins)) if apius.trades.count > 0
116
- str += format(" %<n>i usl", n: dml(usl_ins)) if apius.ledger.count > 0
114
+ str = 'KRAKEN'
115
+ str += format(' %<n>i ust', n: dml(ust_ins)) if apius.trades.count.positive?
116
+ str += format(' %<n>i usl', n: dml(usl_ins)) if apius.ledger.count.positive?
117
117
  str
118
118
  end
119
119
 
@@ -121,9 +121,9 @@ module Cns
121
121
  #
122
122
  # @return [String] linhas & tabelas afetadas
123
123
  def processa_de
124
- str = "BITCOINDE"
125
- str += format(" %<n>i det", n: dml(det_ins)) if apide.trades.count > 0
126
- str += format(" %<n>i del", n: dml(del_ins)) if apide.ledger.count > 0
124
+ str = 'BITCOINDE'
125
+ str += format(' %<n>i det', n: dml(det_ins)) if apide.trades.count.positive?
126
+ str += format(' %<n>i del', n: dml(del_ins)) if apide.ledger.count.positive?
127
127
  str
128
128
  end
129
129
 
@@ -131,8 +131,8 @@ module Cns
131
131
  #
132
132
  # @return [String] linhas & tabelas afetadas
133
133
  def processa_eos
134
- str = "EOS"
135
- str += format(" %<n>i eos ", n: dml(eost_ins)) if apigm.novax.count > 0
134
+ str = 'EOS'
135
+ str += format(' %<n>i eos ', n: dml(eost_ins)) if apigm.novax.count.positive?
136
136
  str
137
137
  end
138
138
 
@@ -182,7 +182,7 @@ module Cns
182
182
 
183
183
  # @return [Etherscan] API blockchain ETH
184
184
  def apiesc
185
- @apies ||= Etherscan.new(
185
+ @apiesc ||= Etherscan.new(
186
186
  {
187
187
  wb: sql("select * from #{BD}.wetc order by ax"),
188
188
  ni: sql("select * from #{BD}.netci"),
@@ -197,20 +197,14 @@ module Cns
197
197
 
198
198
  # @return [Greymass] API blockchain EOS
199
199
  def apigm
200
- @apigm ||= Greymass.new(
201
- {
202
- wb: sql("select * from #{BD}.weos order by ax"),
203
- nt: sql("select * from #{BD}.neosx")
204
- },
205
- ops
206
- )
200
+ @apigm ||= Greymass.new({ wb: sql("select * from #{BD}.weos order by ax"), nt: sql("select * from #{BD}.neosx") }, ops)
207
201
  end
208
202
 
209
203
  # @return [Kraken] API exchange kraken
210
204
  def apius
211
205
  @apius ||= Kraken.new(
212
206
  {
213
- sl: sql("select * from #{BD}.cuss")[0],
207
+ sl: sql("select * from #{BD}.cuss").first,
214
208
  nt: sql("select * from #{BD}.cust order by time,txid"),
215
209
  nl: sql("select * from #{BD}.cusl order by time,txid")
216
210
  },
@@ -222,7 +216,7 @@ module Cns
222
216
  def apide
223
217
  @apide ||= Bitcoinde.new(
224
218
  {
225
- sl: sql("select * from #{BD}.cdes")[0],
219
+ sl: sql("select * from #{BD}.cdes").first,
226
220
  nt: sql("select * from #{BD}.cdet order by time,txid"),
227
221
  nl: sql("select * from #{BD}.cdel order by time,txid")
228
222
  },
@@ -233,13 +227,13 @@ module Cns
233
227
  # @return [String] comando insert SQL formatado netht (norml)
234
228
  def bnetht_ins
235
229
  "insert #{BD}.netht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
236
- 'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias) VALUES'
230
+ 'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias) VALUES'
237
231
  end
238
232
 
239
233
  # @return [String] comando insert SQL formatado nethi (internas)
240
234
  def bnethi_ins
241
235
  "insert #{BD}.nethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
242
- 'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode) VALUES'
236
+ 'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode) VALUES'
243
237
  end
244
238
 
245
239
  # @return [String] comando insert SQL formatado nethp (block)
@@ -255,68 +249,68 @@ module Cns
255
249
  # @return [String] comando insert SQL formatado nethk (token)
256
250
  def bnethk_ins
257
251
  "insert #{BD}.nethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
258
- 'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias) VALUES'
252
+ 'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias) VALUES'
259
253
  end
260
254
 
261
255
  # @return [String] comando insert SQL formatado netht (norml)
262
256
  def netht_ins
263
- "#{bnetht_ins}#{apies.novtx.map { |obj| netht_1val(obj) }.join(',')}"
257
+ "#{bnetht_ins}#{apies.novtx.map { |obj| netht_val(obj) }.join(',')}"
264
258
  end
265
259
 
266
260
  # @return [String] comando insert SQL formatado nethi (internas)
267
261
  def nethi_ins
268
- "#{bnethi_ins}#{apies.novix.map { |obj| nethi_1val(obj) }.join(',')}"
262
+ "#{bnethi_ins}#{apies.novix.map { |obj| nethi_val(obj) }.join(',')}"
269
263
  end
270
264
 
271
265
  # @return [String] comando insert SQL formatado nethp (block)
272
266
  def nethp_ins
273
- "#{bnethp_ins}#{apies.novpx.map { |obj| nethp_1val(obj) }.join(',')}"
267
+ "#{bnethp_ins}#{apies.novpx.map { |obj| nethp_val(obj) }.join(',')}"
274
268
  end
275
269
 
276
270
  # @return [String] comando insert SQL formatado nethw (withdrawals)
277
271
  def nethw_ins
278
- "#{bnethw_ins}#{apies.novwx.map { |obj| nethw_1val(obj) }.join(',')}"
272
+ "#{bnethw_ins}#{apies.novwx.map { |obj| nethw_val(obj) }.join(',')}"
279
273
  end
280
274
 
281
275
  # @return [String] comando insert SQL formatado nethk (token)
282
276
  def nethk_ins
283
- "#{bnethk_ins}#{apies.novkx.map { |obj| nethk_1val(obj) }.join(',')}"
277
+ "#{bnethk_ins}#{apies.novkx.map { |obj| nethk_val(obj) }.join(',')}"
284
278
  end
285
279
 
286
280
  # @return [String] comando insert SQL formatado netht (norml)
287
281
  def netbt_ins
288
- "#{bnetht_ins}#{apiesc.novtx.map { |obj| netht_1val(obj) }.join(',')}"
282
+ "#{bnetht_ins}#{apiesc.novtx.map { |obj| netht_val(obj) }.join(',')}"
289
283
  end
290
284
 
291
285
  # @return [String] comando insert SQL formatado nethi (internas)
292
286
  def netbi_ins
293
- "#{bnethi_ins}#{apiesc.novix.map { |obj| nethi_1val(obj) }.join(',')}"
287
+ "#{bnethi_ins}#{apiesc.novix.map { |obj| nethi_val(obj) }.join(',')}"
294
288
  end
295
289
 
296
290
  # @return [String] comando insert SQL formatado nethp (block)
297
291
  def netbp_ins
298
- "#{bnethp_ins}#{apiesc.novpx.map { |obj| nethp_1val(obj) }.join(',')}"
292
+ "#{bnethp_ins}#{apiesc.novpx.map { |obj| nethp_val(obj) }.join(',')}"
299
293
  end
300
294
 
301
295
  # @return [String] comando insert SQL formatado nethw (withdrawals)
302
296
  def netbw_ins
303
- "#{bnethw_ins}#{apiesc.novwx.map { |obj| nethw_1val(obj) }.join(',')}"
297
+ "#{bnethw_ins}#{apiesc.novwx.map { |obj| nethw_val(obj) }.join(',')}"
304
298
  end
305
299
 
306
300
  # @return [String] comando insert SQL formatado nethk (token)
307
301
  def netbk_ins
308
- "#{bnethk_ins}#{apiesc.novkx.map { |obj| nethk_1val(obj) }.join(',')}"
302
+ "#{bnethk_ins}#{apiesc.novkx.map { |obj| nethk_val(obj) }.join(',')}"
309
303
  end
310
304
 
311
305
  # @return [String] comando insert SQL formatado eos
312
306
  def eost_ins
313
307
  "insert #{BD}.neost(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
314
- ") VALUES#{apigm.novax.map { |obj| eost_1val(obj) }.join(',')}"
308
+ ") VALUES#{apigm.novax.map { |obj| eost_val(obj) }.join(',')}"
315
309
  end
316
310
 
317
311
  # @return [String] comando insert SQL formatado det (trades)
318
312
  def det_ins
319
- "insert #{BD}.cdet(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_1val(obj) }.join(',')}"
313
+ "insert #{BD}.cdet(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_val(obj) }.join(',')}"
320
314
  end
321
315
 
322
316
  # @return [String] comando insert SQL formatado del (ledger)
@@ -327,195 +321,152 @@ module Cns
327
321
  # @return [String] comando insert SQL formatado ust (trades)
328
322
  def ust_ins
329
323
  "insert #{BD}.cust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
330
- "VALUES#{apius.trades.map { |key, val| ust_1val(key, val) }.join(',')}"
324
+ "VALUES#{apius.trades.map { |key, val| ust_val(key, val) }.join(',')}"
331
325
  end
332
326
 
333
327
  # @return [String] comando insert SQL formatado usl (ledger)
334
328
  def usl_ins
335
329
  "insert #{BD}.cusl(txid,refid,time,type,aclass,asset,amount,fee) " \
336
- "VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
330
+ "VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
337
331
  end
338
332
 
339
333
  # @example (see Apibc#norml_es)
340
334
  # @param [Hash] htx transacao norml etherscan
341
335
  # @return [String] valores formatados netht (norml parte1)
342
- def netht_1val(htx)
343
- "(#{Integer(htx[:blockNumber])}," \
344
- "#{Integer(htx[:timeStamp])}," \
345
- "'#{htx[:hash]}'," \
346
- "#{Integer(htx[:nonce])}," \
347
- "'#{htx[:blockHash]}'," \
348
- "#{Integer(htx[:transactionIndex])}," \
349
- "'#{htx[:from]}'," \
350
- "'#{htx[:to]}'," \
351
- "'#{htx[:iax]}'," \
352
- "#{netht_2val(htx)}"
353
- end
354
-
355
- # @param (see netht_1val)
356
- # @return [String] valores formatados netht (norml parte2)
357
- def netht_2val(htx)
336
+ def netht_val(htx)
358
337
  txr = htx[:txreceipt_status]
359
- "cast('#{htx[:value]}' as numeric)," \
360
- "cast('#{htx[:gas]}' as numeric)," \
361
- "cast('#{htx[:gasPrice]}' as numeric)," \
362
- "cast('#{htx[:gasUsed]}' as numeric)," \
363
- "#{Integer(htx[:isError])}," \
364
- "#{txr.length.zero? ? 'null' : txr}," \
365
- "#{netht_3val(htx)}"
366
- end
367
-
368
- # @param (see netht_1val)
369
- # @return [String] valores formatados netht (norml parte3)
370
- def netht_3val(htx)
371
338
  cta = htx[:contractAddress]
372
339
  inp = htx[:input]
373
- "#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
374
- "#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
375
- "#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
340
+ "(#{Integer(htx[:blockNumber])}," \
341
+ "#{Integer(htx[:timeStamp])}," \
342
+ "'#{htx[:hash]}'," \
343
+ "#{Integer(htx[:nonce])}," \
344
+ "'#{htx[:blockHash]}'," \
345
+ "#{Integer(htx[:transactionIndex])}," \
346
+ "'#{htx[:from]}'," \
347
+ "'#{htx[:to]}'," \
348
+ "'#{htx[:iax]}'," \
349
+ "cast('#{htx[:value]}' as numeric)," \
350
+ "cast('#{htx[:gas]}' as numeric)," \
351
+ "cast('#{htx[:gasPrice]}' as numeric)," \
352
+ "cast('#{htx[:gasUsed]}' as numeric)," \
353
+ "#{Integer(htx[:isError])}," \
354
+ "#{txr.empty? ? 'null' : txr}," \
355
+ "#{inp.empty? ? 'null' : "'#{inp}'"}," \
356
+ "#{cta.empty? ? 'null' : "'#{cta}'"}," \
357
+ "#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
376
358
  end
377
359
 
378
360
  # @example (see Apibc#inter_es)
379
361
  # @param [Hash] htx transacao internas etherscan
380
362
  # @return [String] valores formatados nethi (internas parte1)
381
- def nethi_1val(htx)
363
+ def nethi_val(htx)
382
364
  cta = htx[:contractAddress]
383
- "(#{Integer(htx[:blockNumber])}," \
384
- "#{Integer(htx[:timeStamp])}," \
385
- "'#{htx[:hash]}'," \
386
- "'#{htx[:from]}'," \
387
- "'#{htx[:to]}'," \
388
- "'#{htx[:iax]}'," \
389
- "cast('#{htx[:value]}' as numeric)," \
390
- "#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
391
- "#{nethi_2val(htx)}"
392
- end
393
-
394
- # @param (see nethi_1val)
395
- # @return [String] valores formatados nethi (internas parte2)
396
- def nethi_2val(htx)
397
365
  inp = htx[:input]
398
366
  tid = htx[:traceId]
399
367
  txr = htx[:errCode]
400
- "#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
401
- "'#{htx[:type]}'," \
402
- "cast('#{htx[:gas]}' as numeric)," \
403
- "cast('#{htx[:gasUsed]}' as numeric)," \
404
- "#{tid.length.zero? ? 'null' : "'#{tid}'"}," \
405
- "#{Integer(htx[:isError])}," \
406
- "#{txr.length.zero? ? 'null' : txr})"
368
+ "(#{Integer(htx[:blockNumber])}," \
369
+ "#{Integer(htx[:timeStamp])}," \
370
+ "'#{htx[:hash]}'," \
371
+ "'#{htx[:from]}'," \
372
+ "'#{htx[:to]}'," \
373
+ "'#{htx[:iax]}'," \
374
+ "cast('#{htx[:value]}' as numeric)," \
375
+ "#{cta.empty? ? 'null' : "'#{cta}'"}," \
376
+ "#{inp.empty? ? 'null' : "'#{inp}'"}," \
377
+ "'#{htx[:type]}'," \
378
+ "cast('#{htx[:gas]}' as numeric)," \
379
+ "cast('#{htx[:gasUsed]}' as numeric)," \
380
+ "#{tid.empty? ? 'null' : "'#{tid}'"}," \
381
+ "#{Integer(htx[:isError])}," \
382
+ "#{txr.empty? ? 'null' : txr})"
407
383
  end
408
384
 
409
385
  # @example (see Apibc#block_es)
410
386
  # @param [Hash] htx transacao block etherscan
411
387
  # @return [String] valores formatados nethi (block parte1)
412
- def nethp_1val(htx)
388
+ def nethp_val(htx)
413
389
  "(#{Integer(htx[:blockNumber])}," \
414
- "#{Integer(htx[:timeStamp])}," \
415
- "cast('#{htx[:blockReward]}' as numeric)," \
416
- "'#{htx[:iax]}')"
390
+ "#{Integer(htx[:timeStamp])}," \
391
+ "cast('#{htx[:blockReward]}' as numeric)," \
392
+ "'#{htx[:iax]}')"
417
393
  end
418
394
 
419
395
  # @example (see Apibc#block_es)
420
396
  # @param [Hash] htx transacao withdrawals etherscan
421
397
  # @return [String] valores formatados nethi (withdrawals parte1)
422
- def nethw_1val(htx)
398
+ def nethw_val(htx)
423
399
  "(#{Integer(htx[:withdrawalIndex])}," \
424
- "#{Integer(htx[:validatorIndex])}," \
425
- "'#{htx[:address]}'," \
426
- "cast('#{htx[:amount]}' as numeric)," \
427
- "#{Integer(htx[:blockNumber])}," \
428
- "#{Integer(htx[:timestamp])})"
400
+ "#{Integer(htx[:validatorIndex])}," \
401
+ "'#{htx[:address]}'," \
402
+ "cast('#{htx[:amount]}' as numeric)," \
403
+ "#{Integer(htx[:blockNumber])}," \
404
+ "#{Integer(htx[:timestamp])})"
429
405
  end
430
406
 
431
407
  # @example (see Apibc#token_es)
432
408
  # @param [Hash] hkx token event etherscan
433
409
  # @return [String] valores formatados nethk (token parte1)
434
- def nethk_1val(hkx)
435
- "(#{Integer(hkx[:blockNumber])}," \
436
- "#{Integer(hkx[:timeStamp])}," \
437
- "'#{hkx[:hash]}'," \
438
- "#{Integer(hkx[:nonce])}," \
439
- "'#{hkx[:blockHash]}'," \
440
- "#{Integer(hkx[:transactionIndex])}," \
441
- "'#{hkx[:from]}'," \
442
- "'#{hkx[:to]}'," \
443
- "'#{hkx[:iax]}'," \
444
- "#{nethk_2val(hkx)}"
445
- end
446
-
447
- # @param (see nethk_1val)
448
- # @return [String] valores formatados nethk (token parte2)
449
- def nethk_2val(hkx)
450
- "cast('#{hkx[:value]}' as numeric)," \
451
- "'#{hkx[:tokenName]}'," \
452
- "'#{hkx[:tokenSymbol]}'," \
453
- "#{Integer(hkx[:tokenDecimal])}," \
454
- "cast('#{hkx[:gas]}' as numeric)," \
455
- "cast('#{hkx[:gasPrice]}' as numeric)," \
456
- "cast('#{hkx[:gasUsed]}' as numeric)," \
457
- "#{nethk_3val(hkx)}"
458
- end
459
-
460
- # @param (see nethk_1val)
461
- # @return [String] valores formatados nethk (token parte3)
462
- def nethk_3val(hkx)
410
+ def nethk_val(hkx)
463
411
  cta = hkx[:contractAddress]
464
412
  inp = hkx[:input]
465
- "#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
466
- "#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
467
- "#{Integer(ops[:h][hkx[:blockNumber]] || 0)})"
413
+ "(#{Integer(hkx[:blockNumber])}," \
414
+ "#{Integer(hkx[:timeStamp])}," \
415
+ "'#{hkx[:hash]}'," \
416
+ "#{Integer(hkx[:nonce])}," \
417
+ "'#{hkx[:blockHash]}'," \
418
+ "#{Integer(hkx[:transactionIndex])}," \
419
+ "'#{hkx[:from]}'," \
420
+ "'#{hkx[:to]}'," \
421
+ "'#{hkx[:iax]}'," \
422
+ "cast('#{hkx[:value]}' as numeric)," \
423
+ "'#{hkx[:tokenName]}'," \
424
+ "'#{hkx[:tokenSymbol]}'," \
425
+ "#{Integer(hkx[:tokenDecimal])}," \
426
+ "cast('#{hkx[:gas]}' as numeric)," \
427
+ "cast('#{hkx[:gasPrice]}' as numeric)," \
428
+ "cast('#{hkx[:gasUsed]}' as numeric)," \
429
+ "#{inp.empty? ? 'null' : "'#{inp}'"}," \
430
+ "#{cta.empty? ? 'null' : "'#{cta}'"}," \
431
+ "#{Integer(ops[:h][hkx[:blockNumber]] || 0)})"
468
432
  end
469
433
 
470
434
  # @example (see Apibc#ledger_gm)
471
435
  # @param [Hash] hlx ledger greymass
472
436
  # @return [String] valores formatados para insert eos (parte1)
473
- def eost_1val(hlx)
437
+ def eost_val(hlx)
474
438
  act = hlx[:action_trace][:act]
475
- "(#{hlx[:global_action_seq]}," \
476
- "#{hlx[:account_action_seq]}," \
477
- "#{hlx[:block_num]}," \
478
- "DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
479
- "'#{act[:account]}'," \
480
- "'#{act[:name]}'," \
481
- "#{eost_2val(hlx, act)}"
482
- end
483
-
484
- # @param (see eost_1val)
485
- # @param [Hash] act dados da acao
486
- # @return [String] valores formatados para insert eos (parte2)
487
- def eost_2val(hlx, act)
488
439
  dat = act[:data]
489
440
  qtd = dat[:quantity].to_s
490
441
  str = dat[:memo].inspect
491
- "'#{dat[:from]}'," \
492
- "'#{dat[:to]}'," \
493
- "'#{hlx[:iax]}'," \
494
- "#{qtd.to_d},'#{qtd[/[[:upper:]]+/]}'," \
495
- "nullif('#{str.gsub(/['"]/, '')}','nil')," \
496
- "#{ops[:h][String(hlx[:itx])] || 0})"
442
+ "(#{hlx[:global_action_seq]}," \
443
+ "#{hlx[:account_action_seq]}," \
444
+ "#{hlx[:block_num]}," \
445
+ "DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
446
+ "'#{act[:account]}'," \
447
+ "'#{act[:name]}'," \
448
+ "'#{dat[:from]}'," \
449
+ "'#{dat[:to]}'," \
450
+ "'#{hlx[:iax]}'," \
451
+ "#{qtd.to_d},'#{qtd[/[[:upper:]]+/]}'," \
452
+ "nullif('#{str.gsub(/['"]/, '')}','nil')," \
453
+ "#{ops[:h][String(hlx[:itx])] || 0})"
497
454
  end
498
455
 
499
456
  # @example (see Apice#trades_de)
500
457
  # @param [Hash] htx trade bitcoinde
501
458
  # @return [String] valores formatados det (trades parte1)
502
- def det_1val(htx)
459
+ def det_val(htx)
503
460
  "('#{htx[:trade_id]}'," \
504
- "DATETIME(TIMESTAMP('#{htx[:successfully_finished_at]}'))," \
505
- "'#{htx[:type]}'," \
506
- "'#{htx[:trading_partner_information][:username]}'," \
507
- "#{det_2val(htx)}"
508
- end
509
-
510
- # @param (see det_1val)
511
- # @return [String] valores formatados det (trades parte2)
512
- def det_2val(htx)
513
- 'cast(' \
514
- "#{htx[:type] == 'buy' ? htx[:amount_currency_to_trade_after_fee] : "-#{htx[:amount_currency_to_trade]}"}" \
515
- ' as numeric),' \
516
- "cast(#{htx[:volume_currency_to_pay_after_fee]} as numeric)," \
517
- "DATETIME(TIMESTAMP('#{htx[:trade_marked_as_paid_at]}'))," \
518
- "#{Integer(ops[:h][htx[:trade_id]] || 0)})"
461
+ "DATETIME(TIMESTAMP('#{htx[:successfully_finished_at]}'))," \
462
+ "'#{htx[:type]}'," \
463
+ "'#{htx[:trading_partner_information][:username]}'," \
464
+ 'cast(' \
465
+ "#{htx[:type] == 'buy' ? htx[:amount_currency_to_trade_after_fee] : "-#{htx[:amount_currency_to_trade]}"} " \
466
+ 'as numeric),' \
467
+ "cast(#{htx[:volume_currency_to_pay_after_fee]} as numeric)," \
468
+ "DATETIME(TIMESTAMP('#{htx[:trade_marked_as_paid_at]}'))," \
469
+ "#{Integer(ops[:h][htx[:trade_id]] || 0)})"
519
470
  end
520
471
 
521
472
  # @example (see Apice#deposits_de)
@@ -525,208 +476,50 @@ module Cns
525
476
  def del_val(hlx)
526
477
  tip = hlx[:tp]
527
478
  "(#{hlx[:txid]}," \
528
- "DATETIME(TIMESTAMP('#{hlx[:time].iso8601}'))," \
529
- "'#{tip}'," \
530
- "'#{hlx[:add]}'," \
531
- "'#{hlx[:moe]}'," \
532
- "cast(#{tip == 'withdrawal' ? '-' : ''}#{hlx[:qt]} as numeric)," \
533
- "cast(#{hlx[:fee]} as numeric))"
479
+ "DATETIME(TIMESTAMP('#{hlx[:time].iso8601}'))," \
480
+ "'#{tip}'," \
481
+ "'#{hlx[:add]}'," \
482
+ "'#{hlx[:moe]}'," \
483
+ "cast(#{tip == 'withdrawal' ? '-' : ''}#{hlx[:qt]} as numeric)," \
484
+ "cast(#{hlx[:fee]} as numeric))"
534
485
  end
535
486
 
536
487
  # @example (see Apice#trades_us)
537
488
  # @param [String] idx identificador transacao
538
489
  # @param [Hash] htx trade kraken
539
490
  # @return [String] valores formatados ust (trades parte1)
540
- def ust_1val(idx, htx)
541
- "('#{idx}'," \
542
- "'#{htx[:ordertxid]}'," \
543
- "'#{htx[:pair]}'," \
544
- "PARSE_DATETIME('%s', '#{String(htx[:time].round)}')," \
545
- "'#{htx[:type]}'," \
546
- "'#{htx[:ordertype]}'," \
547
- "cast(#{htx[:price]} as numeric)," \
548
- "cast(#{htx[:cost]} as numeric)," \
549
- "cast(#{htx[:fee]} as numeric)," \
550
- "#{ust_2val(idx, htx)}"
551
- end
552
-
553
- # @param (see ust_1val)
554
- # @return [String] valores formatados ust (trades parte2)
555
- def ust_2val(idx, htx)
491
+ def ust_val(idx, htx)
556
492
  msc = htx[:misc].to_s
557
- "cast(#{htx[:vol]} as numeric)," \
558
- "cast(#{htx[:margin]} as numeric)," \
559
- "#{msc.empty? ? 'null' : "'#{msc}'"}," \
560
- "'#{apius.ledger.select { |_, val| val[:refid] == idx }.keys.join(',') || ''}'," \
561
- "#{Integer(ops[:h][idx] || 0)})"
493
+ "('#{idx}'," \
494
+ "'#{htx[:ordertxid]}'," \
495
+ "'#{htx[:pair]}'," \
496
+ "PARSE_DATETIME('%s', '#{String(htx[:time].round)}')," \
497
+ "'#{htx[:type]}'," \
498
+ "'#{htx[:ordertype]}'," \
499
+ "cast(#{htx[:price]} as numeric)," \
500
+ "cast(#{htx[:cost]} as numeric)," \
501
+ "cast(#{htx[:fee]} as numeric)," \
502
+ "cast(#{htx[:vol]} as numeric)," \
503
+ "cast(#{htx[:margin]} as numeric)," \
504
+ "#{msc.empty? ? 'null' : "'#{msc}'"}," \
505
+ "'#{apius.ledger.select { |_, val| val[:refid] == idx }.keys.join(',') || ''}'," \
506
+ "#{Integer(ops[:h][idx] || 0)})"
562
507
  end
563
508
 
564
509
  # @example (see Apice#ledger_us)
565
- # @param idx (see ust_1val)
510
+ # @param idx (see ust_val)
566
511
  # @param [Hash] hlx ledger kraken
567
512
  # @return [String] valores formatados usl (ledger)
568
513
  def usl_val(idx, hlx)
569
514
  acl = hlx[:aclass].to_s
570
515
  "('#{idx}'," \
571
- "'#{hlx[:refid]}'," \
572
- "PARSE_DATETIME('%s', '#{String(hlx[:time].round)}')," \
573
- "'#{hlx[:type]}'," \
574
- "#{acl.empty? ? 'null' : "'#{acl}'"}," \
575
- "'#{hlx[:asset]}'," \
576
- "cast(#{hlx[:amount]} as numeric)," \
577
- "cast(#{hlx[:fee]} as numeric))"
578
- end
579
-
580
- # @return [Paymium] API exchange paymium
581
- # def apifr
582
- # @apifr ||= Paymium.new(
583
- # {
584
- # sl: sql("select * from #{BD}.frsl")[0],
585
- # nl: sql("select uuid txid,tipo,valor,moe,time,dias from #{BD}.fr order by time,1")
586
- # },
587
- # ops
588
- # )
589
- # end
590
- #
591
- # @return [TheRock] API exchange therock
592
- # def apimt
593
- # @apimt ||= TheRock.new(
594
- # {
595
- # sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.mtsl")[0],
596
- # nl: sql("select id txid,time,type,valor,moe,pair,note,dias from #{BD}.mt order by time,1")
597
- # },
598
- # ops
599
- # )
600
- # end
601
- #
602
- # @return [String] comando insert SQL formatado fr (ledger)
603
- # def frl_ins
604
- # "insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
605
- # end
606
- #
607
- # @return [String] comando insert SQL formatado fr (ledger)
608
- # def mtl_ins
609
- # "insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
610
- # "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
611
- # end
612
- #
613
- # @example (see Apice#ledger_fr)
614
- # @param [Hash] hlx ledger paymium
615
- # @return [String] valores formatados frl (ledger)
616
- # def frl_val(hlx)
617
- # uid = hlx[:uuid]
618
- # "('#{uid}'," \
619
- # "'#{hlx[:name]}'," \
620
- # "cast(#{hlx[:amount]} as numeric)," \
621
- # "'#{hlx[:currency]}'," \
622
- # "PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
623
- # "#{Integer(ops[:h][uid] || 0)})"
624
- # end
625
- #
626
- # @example (see Apice#ledger_mt)
627
- # @param [Hash] hlx ledger therock
628
- # @return [String] valores formatados mtl (ledger parte1)
629
- # def mtl_1val(hlx)
630
- # fid = hlx[:fund_id].to_s
631
- # "(#{hlx[:id]}," \
632
- # "DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
633
- # "'#{hlx[:type]}'," \
634
- # "cast(#{hlx[:price]} as numeric)," \
635
- # "'#{hlx[:currency]}'," \
636
- # "#{fid.empty? ? 'null' : "'#{fid}'"}," \
637
- # "#{mtl_2val(hlx)}"
638
- # end
639
- #
640
- # @param (see mtl_1val)
641
- # @return [String] valores formatados mtl (ledger parte2)
642
- # def mtl_2val(hlx)
643
- # nte = hlx[:note].to_s
644
- # tid = hlx[:trade_id].to_s
645
- # "#{nte.empty? ? 'null' : "'#{nte}'"}," \
646
- # "#{tid.empty? ? 'null' : tid.to_s}," \
647
- # "#{Integer(ops[:h][String(hlx[:id])] || 0)})"
648
- # end
649
- #
650
- # @example (see Beaconchain#formata_saldos)
651
- # @param (see Beaconchain#formata_saldos)
652
- # @return [String] valores formatados etht (norml parte1)
653
- # def eth2bh_1val(htb)
654
- # "(#{Integer(htb[:balance])}," \
655
- # "#{Integer(htb[:effectivebalance])}," \
656
- # "#{Integer(htb[:epoch])}," \
657
- # "#{Integer(htb[:validatorindex])})"
658
- # end
659
- # @return [Beaconchain] API blockchain ETH2
660
- # def apibc
661
- # @apibc ||= Beaconchain.new(
662
- # {
663
- # wb: sql("select * from #{BD}.walletEth2 order by 1"),
664
- # nb: sql("select itx,iax from #{BD}.eth2bhx")
665
- # },
666
- # ops
667
- # )
668
- # end
669
- # @return [String] comando insert SQL formatado eth2bh
670
- # def eth2bh_ins
671
- # "insert #{BD}.eth2bh(balance,effectivebalance,epoch,validatorindex" \
672
- # ") VALUES#{apibc.nov[0..1000].map { |obj| eth2bh_1val(obj) }.join(',')}"
673
- # end
674
- # insere transacoes exchange paymium/therock novas na tabela fr/mt (ledger)
675
- # def processa_frmt
676
- # puts(format("%<n>4i LEDGER\tPAYMIUM\t\tINSERIDAS fr", n: apifr.ledger.empty? ? 0 : dml(frl_ins)))
677
- # puts(format("%<n>4i LEDGER\tTHEROCK\t\tINSERIDAS mt", n: apimt.ledger.empty? ? 0 : dml(mtl_ins)))
678
- # end
679
- # insere historico sados novos na tabela eth2bh
680
- # def processa_bc
681
- # puts(format("%<n>4i ATTESTATIONS INSERIDAS eth2at", n: apibc.novtx.empty? ? 0 : dml(eth2at_ins)))
682
- # puts(format("%<n>4i PROPOSALS INSERIDAS eth2pr", n: apibc.novkx.empty? ? 0 : dml(eth2pr_ins)))
683
- # puts(format("%<n>4i BALANCES\tETH2\t\tINSERIDOS eth2bh", n: apibc.nov.empty? ? 0 : dml(eth2bh_ins)))
684
- # end
685
- # def eth2at_ins
686
- # "insert #{BD}.eth2at(attesterslot,committeeindex,epoch,inclusionslot,status,validatorindex" \
687
- # ") VALUES#{apibc.novtx.map { |obj| eth2at_1val(obj) }.join(',')}"
688
- # end
689
- # def eth2pr_ins
690
- # "insert #{BD}.eth2pr(attestationscount,attesterslashingscount,blockroot,depositscount,epoch," \
691
- # 'eth1data_blockhash,eth1data_depositcount,eth1data_depositroot,graffiti,graffiti_text,parentroot,' \
692
- # 'proposer,proposerslashingscount,randaoreveal,signature,slot,stateroot,status,voluntaryexitscount' \
693
- # ") VALUES#{apibc.novkx.map { |obj| eth2pr_1val(obj) }.join(',')}"
694
- # end
695
- # def eth2at_1val(htx)
696
- # "(#{Integer(htx[:attesterslot])}," \
697
- # "#{Integer(htx[:committeeindex])}," \
698
- # "#{Integer(htx[:epoch])}," \
699
- # "#{Integer(htx[:inclusionslot])}," \
700
- # "#{Integer(htx[:status])}," \
701
- # "#{Integer(htx[:validatorindex])})"
702
- # end
703
- # def eth2pr_1val(htx)
704
- # "(#{Integer(htx[:attestationscount])}," \
705
- # "#{Integer(htx[:attesterslashingscount])}," \
706
- # "'#{htx[:blockroot]}'," \
707
- # "#{Integer(htx[:depositscount])}," \
708
- # "#{Integer(htx[:epoch])}," \
709
- # "'#{htx[:eth1data_blockhash]}'," \
710
- # "#{eth2pr_2val(htx)}"
711
- # end
712
- # def eth2pr_2val(htx)
713
- # grf = htx[:graffiti_text]
714
- # "#{Integer(htx[:eth1data_depositcount])}," \
715
- # "'#{htx[:eth1data_depositroot]}'," \
716
- # "'#{htx[:graffiti]}'," \
717
- # "#{grf.length.zero? ? 'null' : "'#{grf}'"}," \
718
- # "'#{htx[:parentroot]}'," \
719
- # "#{Integer(htx[:proposer])}," \
720
- # "#{eth2pr_3val(htx)}"
721
- # end
722
- # def eth2pr_3val(htx)
723
- # "#{Integer(htx[:proposerslashingscount])}," \
724
- # "'#{htx[:randaoreveal]}'," \
725
- # "'#{htx[:signature]}'," \
726
- # "#{Integer(htx[:slot])}," \
727
- # "'#{htx[:stateroot]}'," \
728
- # "#{Integer(htx[:status])}," \
729
- # "#{Integer(htx[:voluntaryexitscount])})"
730
- # end
516
+ "'#{hlx[:refid]}'," \
517
+ "PARSE_DATETIME('%s', '#{String(hlx[:time].round)}')," \
518
+ "'#{hlx[:type]}'," \
519
+ "#{acl.empty? ? 'null' : "'#{acl}'"}," \
520
+ "'#{hlx[:asset]}'," \
521
+ "cast(#{hlx[:amount]} as numeric)," \
522
+ "cast(#{hlx[:fee]} as numeric))"
523
+ end
731
524
  end
732
525
  end
data/lib/cns/bitcoinde.rb CHANGED
@@ -50,11 +50,7 @@ module Cns
50
50
 
51
51
  # @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
52
52
  def exd
53
- @exd ||= {
54
- sl: api.account_de,
55
- tt: api.trades_de,
56
- tl: api.deposits_de + api.withdrawals_de
57
- }
53
+ @exd ||= { sl: api.account_de, tt: api.trades_de, tl: api.deposits_de + api.withdrawals_de }
58
54
  end
59
55
 
60
56
  # @return [Array<String>] lista txid dos trades novos
data/lib/cns/etherscan.rb CHANGED
@@ -104,7 +104,7 @@ module Cns
104
104
  acc = abc[:account].downcase
105
105
  {
106
106
  ax: acc,
107
- sl: (abc[:balance].to_d / 10**18),
107
+ sl: (abc[:balance].to_d / (10**18)),
108
108
  tx: filtrar_tx(acc, api.norml_es(acc)),
109
109
  ix: filtrar_tx(acc, api.inter_es(acc)),
110
110
  px: filtrar_px(acc, api.block_es(acc)),
@@ -153,7 +153,7 @@ module Cns
153
153
  ary.map { |omp| omp.merge(itx: Integer(omp[:blockNumber]), iax: add) }
154
154
  end
155
155
 
156
- #dt: Time.at(Integer(htx[:timeStamp])),
156
+ # dt: Time.at(Integer(htx[:timeStamp])),
157
157
  # @return [Array<Hash>] lista ordenada transacoes normais novas
158
158
  def sortx
159
159
  novtx.sort { |ant, prx| ant[:srx] <=> prx[:srx] }
@@ -210,29 +210,21 @@ module Cns
210
210
  # @param [Hash] hjn dados juntos bigquery & etherscan
211
211
  # @return [String] texto formatado duma carteira
212
212
  def formata_carteira_simples(hjn)
213
- format(
214
- '%<s1>-6.6s %<s2>-42.42s ',
215
- s1: hjn[:id],
216
- s2: hjn[:ax]
217
- ) + formata_valores_simples(hjn)
213
+ format('%<s1>-6.6s %<s2>-42.42s ', s1: hjn[:id], s2: hjn[:ax]) + formata_valores_simples(hjn)
218
214
  end
219
215
 
220
216
  # @param [Hash] hjn dados juntos bigquery & etherscan
221
217
  # @return [String] texto formatado duma carteira
222
218
  def formata_carteira(hjn)
223
- format(
224
- '%<s1>-6.6s %<s2>-10.10s ',
225
- s1: hjn[:id],
226
- s2: formata_enderec1(hjn[:ax], 10)
227
- ) + formata_valores(hjn)
219
+ format('%<s1>-6.6s %<s2>-10.10s ', s1: hjn[:id], s2: formata_enderec1(hjn[:ax], 10)) + formata_valores(hjn)
228
220
  end
229
221
 
230
222
  # @param (see formata_carteira)
231
223
  # @return [String] texto formatado valores duma carteira
232
224
  def formata_valores_simples(hjn)
233
- #id address etherscan bigquery
234
- #me-app 0x27c7f54e48956a906af2cbfbc8684b437776403d 22.377364 22.377364 OK
235
- #mm-hot 0x534029b6371dc4453dd750bc1198181f55c859fe 4.556609 4.556609 OK
225
+ # id address etherscan bigquery
226
+ # me-app 0x27c7f54e48956a906af2cbfbc8684b437776403d 22.377364 22.377364 OK
227
+ # mm-hot 0x534029b6371dc4453dd750bc1198181f55c859fe 4.556609 4.556609 OK
236
228
  format(
237
229
  '%<v1>13.6f %<v2>13.6f %<ok>-3s',
238
230
  v1: hjn[:es],
@@ -244,9 +236,9 @@ module Cns
244
236
  # @param (see formata_carteira)
245
237
  # @return [String] texto formatado valores duma carteira
246
238
  def formata_valores(hjn)
247
- #id address etherscan tn ti tb tk tw bigquery tn ti tb tk tw
248
- #me-app 0x27c..b43 22.3774 31 6 0 16 2190 22.3774 25 6 0 16 2190 OK
249
- #mm-hot 0x534..81f 4.5566 182 18 74 7 51 4.5566 33 18 74 6 51 OK
239
+ # id address etherscan tn ti tb tk tw bigquery tn ti tb tk tw
240
+ # me-app 0x27c..b43 22.3774 31 6 0 16 2190 22.3774 25 6 0 16 2190 OK
241
+ # mm-hot 0x534..81f 4.5566 182 18 74 7 51 4.5566 33 18 74 6 51 OK
250
242
  format(
251
243
  '%<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',
252
244
  v1: hjn[:es],
@@ -296,7 +288,7 @@ module Cns
296
288
  ini = Integer(max / 2)
297
289
  inf = max % 2
298
290
  hid = bqd[:wb].select { |obj| obj[:ax] == add }.first
299
- ndd = hid ? hid[:id] + '-' + add : add
291
+ ndd = hid ? "#{hid[:id]}-#{add}" : add
300
292
  "#{ndd[0, ini - 3]}..#{ndd[-inf - ini - 3..]}"
301
293
  end
302
294
 
@@ -310,7 +302,7 @@ module Cns
310
302
  fr: formata_enderec2(htx[:from], 20),
311
303
  to: formata_enderec2(htx[:to], 20),
312
304
  dt: Time.at(Integer(htx[:timeStamp])),
313
- vl: (htx[:value].to_d / 10**18).round(10)
305
+ vl: (htx[:value].to_d / (10**18)).round(10)
314
306
  )
315
307
  end
316
308
 
@@ -323,7 +315,7 @@ module Cns
323
315
  bn: htx[:blockNumber],
324
316
  fr: formata_enderec2(htx[:iax], 41),
325
317
  dt: Time.at(Integer(htx[:timeStamp])),
326
- vl: (htx[:blockReward].to_d / 10**18).round(10)
318
+ vl: (htx[:blockReward].to_d / (10**18)).round(10)
327
319
  )
328
320
  end
329
321
 
@@ -337,7 +329,7 @@ module Cns
337
329
  fr: formata_enderec2(hkx[:from], 20),
338
330
  to: formata_enderec2(hkx[:to], 20),
339
331
  dt: Time.at(Integer(hkx[:timeStamp])),
340
- vl: (hkx[:value].to_d / 10**18).round(10),
332
+ vl: (hkx[:value].to_d / (10**18)).round(10),
341
333
  sy: hkx[:tokenSymbol]
342
334
  )
343
335
  end
@@ -351,7 +343,7 @@ module Cns
351
343
  vi: htx[:validatorIndex],
352
344
  bn: htx[:blockNumber],
353
345
  dt: Time.at(Integer(htx[:timestamp])),
354
- vl: (htx[:amount].to_d / 10**9).round(10)
346
+ vl: (htx[:amount].to_d / (10**9)).round(10)
355
347
  )
356
348
  end
357
349
 
data/lib/cns/greymass.rb CHANGED
@@ -58,7 +58,7 @@ module Cns
58
58
  xbq = wbq[:ax]
59
59
  {
60
60
  ax: xbq,
61
- sl: greymass_sl(xbq).inject(:+),
61
+ sl: greymass_sl(xbq).reduce(:+),
62
62
  tx: filtrar_tx(xbq, api.ledger_gm(xbq))
63
63
  }
64
64
  end
data/lib/cns/kraken.rb CHANGED
@@ -27,12 +27,12 @@ module Cns
27
27
 
28
28
  # @return [Hash] trades kraken novos
29
29
  def trades
30
- @trades ||= exd[:kt].select { |key, _| kyt.include?(key) }
30
+ @trades ||= exd[:kt].slice(*kyt)
31
31
  end
32
32
 
33
33
  # @return [Hash] ledger kraken novos
34
34
  def ledger
35
- @ledger ||= exd[:kl].select { |key, _| kyl.include?(key) }
35
+ @ledger ||= exd[:kl].slice(*kyl)
36
36
  end
37
37
 
38
38
  # @return [String] texto saldos & transacoes & ajuste dias
@@ -50,11 +50,7 @@ module Cns
50
50
 
51
51
  # @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
52
52
  def exd
53
- @exd ||= {
54
- sl: api.account_us,
55
- kt: api.trades_us,
56
- kl: api.ledger_us
57
- }
53
+ @exd ||= { sl: api.account_us, kt: api.trades_us, kl: api.ledger_us }
58
54
  end
59
55
 
60
56
  # @return [Array<String>] lista txid dos trades novos
data/lib/cns/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '0.7.9'
4
+ VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-02-12 00:00:00.000000000 Z
10
+ date: 2025-02-16 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -80,20 +79,6 @@ dependencies:
80
79
  - - ">="
81
80
  - !ruby/object:Gem::Version
82
81
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rufo
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
82
  - !ruby/object:Gem::Dependency
98
83
  name: solargraph
99
84
  requirement: !ruby/object:Gem::Requirement
@@ -210,14 +195,13 @@ files:
210
195
  - lib/cns/greymass.rb
211
196
  - lib/cns/kraken.rb
212
197
  - lib/cns/version.rb
213
- - ruby-lint.yml
214
198
  homepage: https://github.com/hernanirvaz/cns
215
199
  licenses:
216
200
  - MIT
217
201
  metadata:
218
202
  homepage_uri: https://github.com/hernanirvaz/cns
219
203
  yard.run: yard
220
- post_install_message:
204
+ rubygems_mfa_required: 'true'
221
205
  rdoc_options: []
222
206
  require_paths:
223
207
  - lib
@@ -232,8 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
216
  - !ruby/object:Gem::Version
233
217
  version: '0'
234
218
  requirements: []
235
- rubygems_version: 3.3.7
236
- signing_key:
219
+ rubygems_version: 3.6.3
237
220
  specification_version: 4
238
221
  summary: Arquiva transactions etherscan/greymass/bitcoinde/kraken/paymium/therock
239
222
  no bigquery.
data/ruby-lint.yml DELETED
@@ -1,10 +0,0 @@
1
- ---
2
- analysis_classes:
3
- - argument_amount
4
- - pedantics
5
- - shadowing_variables
6
- # - undefined_methods
7
- # - undefined_variables
8
- # - unused_variables
9
- - useless_equality_checks
10
-