cns 0.9.5 → 0.9.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e6f05fc2c2fc0c7c1e34cda63d18338f37db37957be5f1af27c60041cd761b5
4
- data.tar.gz: bab915764960144e4b713348958b173524f81ba42eb53d2d0df1242c2721d194
3
+ metadata.gz: 60e46e5d964570303d66901fde56320d6102a12ff0f53495d420dc73fc5c5045
4
+ data.tar.gz: fbc9a980fe5be810ee82c541ecbd769feae8ea87e84a9a2d80c356e0e8b313a0
5
5
  SHA512:
6
- metadata.gz: 78336dc2f0cc71f52a0fffcdc0a520e62fb8b77bee5173a18c21de958f0f17df2a7042d21a344a324b1cc3861bab978b6e3a66b96aba66981bd147571e8a5fdc
7
- data.tar.gz: cd747260647643fc61a7ac298a716489df77f71a130571f3360efe5a4268a7e27644150b6c7649d395fd900777439e78d98892a315c5423ba4fd8649eb3c2fd1
6
+ metadata.gz: 425413cbc19a0cbd77889e32a8cac2ba934cf32c9775e2c3bfd891d732f81c025b9f89b92e87211980b4f1e6a318a968fe369b46add18a3c133316b46ec64ceb
7
+ data.tar.gz: 3cd4b50b92b93d31abe4795d1887a24dd358ba4d7aee75edb0ff2329a0ff5b722217547dc77b2aaa944b002c3d22b3107b4a561eea4c8209e8a0a6936ad0448f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.9.5)
4
+ cns (0.9.6)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
data/lib/cns/apibc.rb CHANGED
@@ -20,6 +20,8 @@ module Cns
20
20
  # @param [Array<String>] addresses List of ETH addresses (max 20)
21
21
  # @return [Array<Hash>] List of addresses with balances
22
22
  def account_es(addresses)
23
+ return [] if addresses.empty?
24
+
23
25
  res = es_req('balancemulti', addresses.join(','), 1, tag: 'latest')
24
26
  res[:status] == '1' ? res[:result] || [] : []
25
27
  end
@@ -93,8 +95,7 @@ module Cns
93
95
  # @param [Hash] prm Additional request parameters
94
96
  # @return [Hash] Parsed API response
95
97
  def es_req(act, add, pag = 1, prm = {})
96
- prm = {module: 'account', action: act, address: add, page: pag, apikey: @esky}.merge(prm)
97
- parse_json(@escn.get('/api', prm))
98
+ parse_json(@escn.get('/api', prm.merge(module: 'account', action: act, address: add, page: pag, apikey: @esky)))
98
99
  rescue Faraday::Error
99
100
  {status: '0'}
100
101
  end
@@ -141,6 +142,8 @@ module Cns
141
142
  # @param [Faraday::Response] res API response
142
143
  # @return [Hash] Parsed JSON or empty hash on error
143
144
  def parse_json(res)
145
+ return {} if res.body.to_s.empty?
146
+
144
147
  JSON.parse(res.body, symbolize_names: true) || {}
145
148
  rescue JSON::ParserError
146
149
  {}
@@ -150,12 +153,12 @@ module Cns
150
153
  # @param [String] url Base URL for the API
151
154
  # @return [Faraday::Connection] Configured Faraday connection
152
155
  def connection(url)
153
- Faraday.new(url) do |conn|
154
- conn.request(:json)
155
- conn.headers = {accept: 'application/json', user_agent: 'blockchain-api-client'}
156
- conn.options.timeout = 30
157
- conn.options.open_timeout = 10
158
- conn.adapter(Faraday.default_adapter)
156
+ Faraday.new(url) do |c|
157
+ c.request(:json)
158
+ c.headers = {accept: 'application/json', user_agent: 'blockchain-api-client'}
159
+ c.options.timeout = 30
160
+ c.options.open_timeout = 10
161
+ c.adapter(Faraday.default_adapter)
159
162
  end
160
163
  end
161
164
  end
data/lib/cns/apice.rb CHANGED
@@ -91,10 +91,10 @@ module Cns
91
91
  # @param [Hash] trx transacao
92
92
  # @return [Hash] transacao uniformizada
93
93
  def us_unif(key, trx)
94
- t = Integer(trx[:time])
94
+ t = trx[:time].to_i
95
95
  trx.merge(txid: key.to_s, srx: t, time: Time.at(t))
96
- rescue StandardError
97
- {}
96
+ rescue ArgumentError
97
+ trx.merge(txid: key.to_s, srx: 0, time: Time.at(0))
98
98
  end
99
99
 
100
100
  # Generic paginated request handler for Kraken
@@ -167,14 +167,14 @@ module Cns
167
167
  # Generate a continually-increasing unsigned integer nonce from the current Unix Time
168
168
  # @return [Integer] Nonce value
169
169
  def nnc
170
- Integer(Float(Time.now) * 1e6)
170
+ Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond).to_i
171
171
  end
172
172
 
173
173
  # Uniformly format a deposit from Bitcoin.de
174
174
  # @param [Hash] has Deposit data from Bitcoin.de
175
175
  # @return [Hash] deposito uniformizado bitcoinde
176
176
  def deposit_unif(has)
177
- {add: has[:address], time: Time.parse(has[:created_at]), qtd: has[:amount].to_d, nxid: Integer(has[:deposit_id])}.merge(tp: 'deposit', moe: 'BTC', fee: 0.to_d)
177
+ {add: has[:address], time: Time.parse(has[:created_at]), qtd: has[:amount].to_d, nxid: has[:deposit_id].to_i}.merge(tp: 'deposit', moe: 'BTC', fee: 0.to_d)
178
178
  end
179
179
 
180
180
  # Uniformly format a withdrawal from Bitcoin.de
@@ -186,7 +186,7 @@ module Cns
186
186
  time: Time.parse(has[:transferred_at]),
187
187
  qtd: -1 * has[:amount].to_d,
188
188
  fee: has[:network_fee].to_d,
189
- nxid: Integer(has[:withdrawal_id]),
189
+ nxid: has[:withdrawal_id].to_i,
190
190
  tp: 'withdrawal',
191
191
  moe: 'BTC'
192
192
  }
data/lib/cns/bigquery.rb CHANGED
@@ -29,7 +29,7 @@ module Cns
29
29
  hust: %i[txid ordertxid pair time type ordertype price cost fee vol margin misc ledgers],
30
30
  cusl: %w[txid refid time type aclass asset amount fee],
31
31
  husl: %i[txid refid time type aclass asset amount fee]
32
- }
32
+ }.freeze
33
33
  # para testes bigquery
34
34
  TL = {
35
35
  ins: 'INSERT',
@@ -37,15 +37,14 @@ module Cns
37
37
  est: '', # ' limit 226',
38
38
  esi: '', # ' limit 22',
39
39
  esp: '', # ' limit 72',
40
- esw: '', # ' limit 2299',
40
+ esw: '', # ' limit 2320',
41
41
  esk: '', # ' limit 20',
42
42
  gmt: '', # ' limit 1091',
43
43
  ust: '', # ' limit 182',
44
44
  usl: '', # ' limit 448',
45
45
  det: '', # ' limit 27',
46
46
  del: '' # ' limit 16'
47
-
48
- }
47
+ }.freeze
49
48
 
50
49
  # classe para processar bigquery
51
50
  class Bigquery
@@ -254,9 +253,7 @@ module Cns
254
253
 
255
254
  # @return [String] SQL integer formatting
256
255
  def fin(value)
257
- Integer(value || 0).to_s
258
- rescue StandardError
259
- '0'
256
+ value.to_i.to_s
260
257
  end
261
258
 
262
259
  # @return [String] SQL timestamp formatting
data/lib/cns/bitcoinde.rb CHANGED
@@ -130,7 +130,7 @@ module Cns
130
130
  # @return [Hash] transaccao filtrada
131
131
  def pdes(key, itm)
132
132
  tym = ptm(itm[key])
133
- itm.merge(srx: Integer(tym), key => tym)
133
+ itm.merge(srx: tym.to_i, key => tym)
134
134
  end
135
135
 
136
136
  # @param [Array<Hash>] htx trade bitcoinde
data/lib/cns/etherscan.rb CHANGED
@@ -18,36 +18,36 @@ module Cns
18
18
  header: "\ntx normal from to data valor",
19
19
  sork: :srx,
20
20
  adjk: :hash
21
- },
21
+ }.freeze,
22
22
  internal: {
23
23
  new: :novnethi,
24
24
  format: :foti,
25
25
  header: "\ntx intern from to data valor",
26
26
  sork: :srx,
27
27
  adjk: :hash
28
- },
28
+ }.freeze,
29
29
  block: {
30
30
  new: :novnethp,
31
31
  format: :fop,
32
32
  header: "\ntx block address data valor",
33
33
  sork: :itx,
34
34
  adjk: :blockNumber
35
- },
35
+ }.freeze,
36
36
  token: {
37
37
  new: :novnethk,
38
38
  format: :fok,
39
39
  header: "\ntx token from to data valor moeda",
40
40
  sork: :srx,
41
41
  adjk: :hash
42
- },
42
+ }.freeze,
43
43
  withdrawal: {
44
44
  new: :novnethw,
45
45
  format: :fow,
46
46
  header: "\nwithdrawal validator data valor",
47
47
  sork: :itx,
48
48
  adjk: :withdrawalIndex
49
- }
50
- }
49
+ }.freeze
50
+ }.freeze
51
51
 
52
52
  # @param [Hash] dad todos os dados bigquery
53
53
  # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
@@ -166,7 +166,7 @@ module Cns
166
166
  return 'erro' if max < 7
167
167
 
168
168
  max -= 2
169
- ini = Integer(max / 2) + 4
169
+ ini = (max / 2).to_i + 4
170
170
  inf = max % 2
171
171
  "#{add[0, ini - 3]}..#{add[-inf - ini + 5..]}"
172
172
  end
@@ -180,7 +180,7 @@ module Cns
180
180
  return 'erro' if max < 7
181
181
 
182
182
  max -= 2
183
- ini = Integer(max / 2)
183
+ ini = (max / 2).to_i
184
184
  inf = max % 2
185
185
  hid = bqd[:wb].find { |o| o[:ax] == add }
186
186
  ndd = hid ? "#{hid[:id]}-#{add}" : add
@@ -234,29 +234,31 @@ module Cns
234
234
  # @param [Hash] htx transacao
235
235
  # @return [Hash] transaccao filtrada
236
236
  def pess(htx)
237
- tym = Integer(htx[:timeStamp])
237
+ tym = htx[:timeStamp].to_i
238
238
  htx.merge(srx: tym, timeStamp: Time.at(tym))
239
+ rescue ArgumentError
240
+ htx.merge(srx: 0, timeStamp: Time.at(0))
239
241
  end
240
242
 
241
243
  # @param add (see foe1)
242
244
  # @param [Array<Hash>] ary lista transacoes normal(t)/(i)nternal/to(k)en
243
245
  # @return [Array<Hash>] lista transacoes filtrada
244
246
  def ftik(add, ary)
245
- ary.map { |o| pess(o).merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d) }
247
+ ary.map { |o| pess(o).merge(itx: o[:hash].to_s, iax: add, value: o[:value].to_d) }
246
248
  end
247
249
 
248
250
  # @param add (see foe1)
249
251
  # @param [Array<Hash>] ary lista transacoes (p)roduced blocks
250
252
  # @return [Array<Hash>] lista transacoes filtrada
251
253
  def fppp(add, ary)
252
- ary.map { |o| o.merge(itx: Integer(o[:blockNumber]), iax: add, blockReward: o[:blockReward].to_d, timeStamp: Time.at(Integer(o[:timeStamp]))) }
254
+ ary.map { |o| o.merge(itx: o[:blockNumber].to_i, iax: add, blockReward: o[:blockReward].to_d, timeStamp: Time.at(o[:timeStamp].to_i)) }
253
255
  end
254
256
 
255
257
  # @param add (see foe1)
256
258
  # @param [Array<Hash>] ary lista transacoes (w)ithdrawals
257
259
  # @return [Array<Hash>] lista transacoes filtrada
258
260
  def fwww(add, ary)
259
- ary.map { |o| o.merge(itx: Integer(o[:withdrawalIndex]), iax: add, amount: o[:amount].to_d, timeStamp: Time.at(Integer(o[:timestamp]))) }
261
+ ary.map { |o| o.merge(itx: o[:withdrawalIndex].to_i, iax: add, amount: o[:amount].to_d, timeStamp: Time.at(o[:timestamp].to_i)) }
260
262
  end
261
263
 
262
264
  # @param [Hash] aes account etherscan
data/lib/cns/greymass.rb CHANGED
@@ -17,7 +17,7 @@ module Cns
17
17
  header: "\nsequence num from to accao data valor moeda",
18
18
  sork: :itx,
19
19
  adjk: :itx
20
- }
20
+ }.freeze
21
21
 
22
22
  # @param [Hash] dad todos os dados bigquery
23
23
  # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
@@ -77,7 +77,7 @@ module Cns
77
77
  # @param (see foct)
78
78
  # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
79
79
  def ok?(hjn)
80
- hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
80
+ hjn[:bs].round(6) == hjn[:es].round(6) && hjn[:bt].count == hjn[:et].count
81
81
  end
82
82
 
83
83
  # @param [Hash] hlx ledger greymass
@@ -104,8 +104,8 @@ module Cns
104
104
  # @return [Array<BigDecimal>] lista recursos - liquido, net, spu
105
105
  def peosa(add)
106
106
  hac = api.account_gm(add)
107
- htr = hac[:total_resources]
108
- [hac[:core_liquid_balance].to_d, htr[:net_weight].to_d, htr[:cpu_weight].to_d]
107
+ htr = hac.fetch(:total_resources, {})
108
+ [hac[:core_liquid_balance]&.to_d || 0.to_d, htr[:net_weight]&.to_d || 0.to_d, htr[:cpu_weight]&.to_d || 0.to_d]
109
109
  end
110
110
 
111
111
  # @param add (see peosa)
@@ -122,7 +122,7 @@ module Cns
122
122
  quantity: qtd.to_d,
123
123
  account: act[:account],
124
124
  to: adt[:to],
125
- memo: String(adt[:memo]).gsub(/\p{C}/, ''), # remove Non-Printable Characters
125
+ memo: adt[:memo].to_s.gsub(/\p{C}/, ''), # remove Non-Printable Characters
126
126
  moe: qtd[/[[:upper:]]+/],
127
127
  itx: t[:global_action_seq],
128
128
  iax: add,
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.9.5'
4
+ VERSION = '0.9.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz