cns 2.0.12 → 2.1.0

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: f6d06adebecd7ff5ca91d6b1cb1a5968f4b1f2f1c46bf6c9f782e774625ed1bf
4
- data.tar.gz: 84130719d89078105b1881a49b31f4d6da369fdb8fd4fbc24c01ad99212cf95f
3
+ metadata.gz: 6d3c5ea610822521264f6ac8cd2451afd8ab7656f9777ca86ccdb31a57804f53
4
+ data.tar.gz: cfd83658df0c1811173bcc95ee05ea34e9129a3aa30e8235215afe606e7a7626
5
5
  SHA512:
6
- metadata.gz: 3ec07918664fa8435d84617bb4c07dc8f512cbc6e6d67a8f6343f3d814815a0762956d24e89e73f13f389dd73b4ac92f05196141d66c5603790a3966d9e1d6d7
7
- data.tar.gz: 4351369d1dd638aabadcc32b787a261d69c6582de293b43e269bc0680e8bac9eb3a5b370120809720cecd7cddc285dbe99ebba7081a6af78338933ae7180acd4
6
+ metadata.gz: efd61d0b9cfda59966fc5a0d68b5edaf3f316b791f78d0f93c28b1d5a04bcb00d033d4400f8f5be2d8ba5d53248abd42411ae5757c8e2526844b2c3454c5dadb
7
+ data.tar.gz: 556ac9835dabd3810d6bb34a690bdb9339a7d64070f678239b094c3b6afc8f3e036ead6b5195044aee06b237fbbb71df532ccc682bd73b877e5b1e5415511b5e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (2.0.12)
4
+ cns (2.1.0)
5
5
  curb
6
6
  faraday
7
7
  faraday-retry
@@ -96,7 +96,7 @@ GEM
96
96
  multi_json (~> 1.11)
97
97
  os (>= 0.9, < 2.0)
98
98
  signet (>= 0.16, < 2.a)
99
- jaro_winkler (1.6.1)
99
+ jaro_winkler (1.7.0)
100
100
  json (2.18.1)
101
101
  jwt (3.1.2)
102
102
  base64
@@ -145,7 +145,7 @@ GEM
145
145
  reverse_markdown (3.0.2)
146
146
  nokogiri
147
147
  rexml (3.4.4)
148
- rubocop (1.84.1)
148
+ rubocop (1.84.2)
149
149
  json (~> 2.3)
150
150
  language_server-protocol (~> 3.17.0.2)
151
151
  lint_roller (~> 1.1.0)
data/lib/cns/apibc.rb CHANGED
@@ -9,11 +9,9 @@ module Cns
9
9
  # classe para acesso dados blockchains
10
10
  class Apibc
11
11
  ESPS = 10_000 # Etherscan maximum records per page
12
- GMPS = 100 # Greymass maximum actions per request
13
12
 
14
13
  def initialize
15
14
  @escn = bccn('https://api.etherscan.io')
16
- @gmcn = bccn('https://eos.greymass.com')
17
15
  @esky = ENV.fetch('ETHERSCAN_API_KEY', nil)
18
16
  @blks = {} # Cache to store block numbers so we don't ask API repeatedly
19
17
  end
@@ -73,33 +71,6 @@ module Cns
73
71
  pag_es_req('tokentx', add, prm)
74
72
  end
75
73
 
76
- # Get EOS account information
77
- # @param [String] add EOS account name
78
- # @return [Hash] Account details with resources
79
- def account_gm(add)
80
- res = gm_req('/v1/chain/get_account', account_name: add)
81
- res[:core_liquid_balance]&.to_d&.positive? ? res : gm_erro
82
- end
83
-
84
- # Get complete transaction history for EOS account
85
- # @param (see account_gm)
86
- # @return [Array<Hash>] lista completa transacoes greymass
87
- def ledger_gm(add)
88
- trx = []
89
- pos = 0
90
- loop do
91
- res = gm_req('/v1/history/get_actions', account_name: add, pos: pos, offset: GMPS)
92
- bth = Array(res[:actions])
93
- trx.concat(bth)
94
- break if bth.size < GMPS
95
-
96
- pos += GMPS
97
- end
98
- trx
99
- rescue StandardError
100
- trx
101
- end
102
-
103
74
  private
104
75
 
105
76
  # Calculate (and cache) the block number for N days ago
@@ -163,22 +134,6 @@ module Cns
163
134
  trx
164
135
  end
165
136
 
166
- # Make a request to the Greymass API
167
- # @param [String] url API endpoint
168
- # @param [Hash] pyl Request payload
169
- # @return [Hash] Parsed API response
170
- def gm_req(url, pyl)
171
- pjsn(@gmcn.post(url) { |r| r.body = pyl })
172
- rescue Faraday::Error
173
- gm_erro
174
- end
175
-
176
- # Default error response for Greymass API
177
- # @return [Hash] Error response with zeroed values
178
- def gm_erro
179
- {core_liquid_balance: 0, total_resources: {net_weight: 0, cpu_weight: 0}}
180
- end
181
-
182
137
  # Safely parse JSON response
183
138
  # @param [Faraday::Response] res API response
184
139
  # @return [Hash] Parsed JSON or empty hash on error
data/lib/cns/bigquery.rb CHANGED
@@ -23,8 +23,6 @@ module Cns
23
23
  hethw: %i[withdrawalIndex validatorIndex address amount blockNumber timeStamp],
24
24
  nethk: %w[txhash blocknumber timestamp nonce blockhash transactionindex axfrom axto iax value tokenname tokensymbol tokendecimal gas gasprice gasused input contractaddress dias],
25
25
  hethk: %i[hash blockNumber timeStamp nonce blockHash transactionIndex from to iax value tokenName tokenSymbol tokenDecimal gas gasPrice gasUsed input contractAddress],
26
- neost: %w[gseq aseq bnum time contract action acfrom acto iax amount moeda memo dias],
27
- heost: %i[global_action_seq account_action_seq block_num block_time account name from to iax quantity moe memo],
28
26
  cdet: %w[txid time tp user btc eur dtc dias],
29
27
  hdet: %i[trade_id successfully_finished_at type username btc eur trade_marked_as_paid_at],
30
28
  cdel: %w[txid time tp add moe qt fee],
@@ -43,7 +41,6 @@ module Cns
43
41
  esp: '', # limit 72',
44
42
  esw: '', # limit 2350',
45
43
  esk: '', # limit 20',
46
- gmt: '', # limit 1091',
47
44
  ust: '', # limit 182',
48
45
  usl: '', # limit 448',
49
46
  det: '', # limit 27',
@@ -68,7 +65,7 @@ module Cns
68
65
  @ops = pop.transform_keys(&:to_sym)
69
66
  end
70
67
 
71
- # mostra situacao completa entre kraken/bitcoinde/paymium/therock/etherscan/greymass & bigquery
68
+ # mostra situacao completa entre kraken/bitcoinde/etherscan & bigquery
72
69
  def mtudo
73
70
  [apius, apide, apies].each(&:mresumo)
74
71
  end
@@ -88,7 +85,7 @@ module Cns
88
85
  Time.now.strftime('TRANSACOES %Y-%m-%d %H:%M:%S')
89
86
  end
90
87
 
91
- # insere dados novos kraken/bitcoinde/etherscan/greymass no bigquery
88
+ # insere dados novos kraken/bitcoinde/etherscan no bigquery
92
89
  def ptudo
93
90
  puts("#{tct} #{pus}, #{pde}, #{peth(apies)}")
94
91
  end
@@ -126,11 +123,6 @@ module Cns
126
123
  dmo(apide, %w[BITCOINDE], %i[cdet cdel])
127
124
  end
128
125
 
129
- # @return [String] linhas & tabelas afetadas
130
- def peos
131
- dmo(apigm, %w[EOS], %i[neost])
132
- end
133
-
134
126
  # @return [Etherscan] API blockchain ETH
135
127
  def apieg(prx)
136
128
  Etherscan.new(
@@ -156,11 +148,6 @@ module Cns
156
148
  apieg('netc')
157
149
  end
158
150
 
159
- # @return [Greymass] API blockchain EOS
160
- memoize def apigm
161
- Greymass.new({wb: sql("SELECT * FROM #{BD}.weos ORDER BY ax"), nt: sql("SELECT * FROM #{BD}.neosx#{TL[:gmt]}")}, ops)
162
- end
163
-
164
151
  # @return [Kraken] API exchange kraken
165
152
  memoize def apius
166
153
  Kraken.new({sl: sql("SELECT * FROM #{BD}.cuss").first, nt: sql("SELECT * FROM #{BD}.cust#{TL[:ust]}"), nl: sql("SELECT * FROM #{BD}.cusl#{TL[:usl]}")}, ops)
@@ -264,7 +251,6 @@ module Cns
264
251
  vls =
265
252
  kys.map do |k|
266
253
  case k
267
- when :account_action_seq, :block_num, :blockNumber, :global_action_seq, :isError, :nonce, :timeStamp, :tokenDecimal, :transactionIndex, :nxid, :txreceipt_status, :validatorIndex, :withdrawalIndex then fin(hsh[k])
268
254
  when :amount, :btc, :cost, :fee, :gas, :gasPrice, :gasUsed, :margin, :price, :quantity, :value, :vol, :eur, :blockReward, :qtd then fnm(hsh[k])
269
255
  when :block_time, :successfully_finished_at, :time, :trade_marked_as_paid_at then fts(hsh[k])
270
256
  when :memo, :input, :misc then fqe(hsh[k])
@@ -305,12 +291,6 @@ module Cns
305
291
  fvals(htx, TB[:hethk], :hash)
306
292
  end
307
293
 
308
- # @param [Hash] htx ledger greymass
309
- # @return [String] valores formatados neost
310
- def neost_val(htx)
311
- fvals(htx, TB[:heost], :global_action_seq)
312
- end
313
-
314
294
  # @param [Hash] htx trades bitcoinde
315
295
  # @return [String] valores formatados cdet
316
296
  def cdet_val(htx)
data/lib/cns/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '2.0.12'
4
+ VERSION = '2.1.0'
5
5
  end
data/lib/cns.rb CHANGED
@@ -5,7 +5,6 @@ require('cns/apibc')
5
5
  require('cns/apice')
6
6
  require('cns/bigquery')
7
7
  require('cns/etherscan')
8
- require('cns/greymass')
9
8
  require('cns/bitcoinde')
10
9
  require('cns/kraken')
11
10
  require('cns/version')
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: 2.0.12
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
@@ -220,7 +220,6 @@ files:
220
220
  - lib/cns/bigquery.rb
221
221
  - lib/cns/bitcoinde.rb
222
222
  - lib/cns/etherscan.rb
223
- - lib/cns/greymass.rb
224
223
  - lib/cns/kraken.rb
225
224
  - lib/cns/version.rb
226
225
  homepage: https://github.com/hernanirvaz/cns
data/lib/cns/greymass.rb DELETED
@@ -1,189 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require('bigdecimal/util')
4
- require('memoist')
5
-
6
- # @author Hernani Rodrigues Vaz
7
- module Cns
8
- # classe para processar transacoes do greymass
9
- class Greymass
10
- extend Memoist
11
- # @return [Array<Hash>] todos os dados bigquery
12
- # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
13
- attr_reader :bqd, :ops
14
-
15
- TT = {sork: :itx, adjk: :itx}.freeze
16
-
17
- # @param [Hash] dad todos os dados bigquery
18
- # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
19
- # @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
20
- # @option pop [Boolean] :v (false) mostra dados transacoes?
21
- # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
22
- def initialize(dad, pop)
23
- @bqd = dad
24
- @ops = pop.transform_keys(&:to_sym)
25
- end
26
-
27
- # Display summary of wallets, transactions, and adjustment days configuration
28
- def mresumo
29
- return unless bqexd.any?
30
-
31
- puts("\naddress greymass ntx bigquery ntx")
32
- bqexd.each { |e| puts(foct(e)) }
33
- mtransacoes_novas
34
- mconfiguracao_ajuste_dias
35
- end
36
-
37
- private
38
-
39
- # mosta transacoes novas
40
- def mtransacoes_novas
41
- return unless ops[:v] && novxt.any?
42
-
43
- puts("\nsequence num from to accao data valor moeda")
44
- novxt.sort_by { |s| -s[TT[:sork]] }.each { |t| puts(fol(t)) }
45
- end
46
-
47
- # mostra configuration text for adjusting days
48
- def mconfiguracao_ajuste_dias
49
- return unless novxt.any?
50
-
51
- puts("\nstring ajuste dias\n-h=#{novxt.sort_by { |s| -s[TT[:sork]] }.map { |t| "#{t[TT[:adjk]]}:0" }.join(' ')}")
52
- end
53
-
54
- # Format wallet summary text
55
- # @param [Hash] hjn dados juntos bigquery & greymass
56
- # @return [String] texto formatado duma carteira
57
- def foct(hjn)
58
- format(
59
- '%<address>-12.12s %<greymass_value>14.4f %<greymass_tx_count>4i %<bigquery_value>14.4f %<bigquery_tx_count>4i %<status>-3s',
60
- address: hjn[:ax],
61
- greymass_value: hjn[:es],
62
- greymass_tx_count: hjn[:et].count,
63
- bigquery_value: hjn[:bs],
64
- bigquery_tx_count: hjn[:bt].count,
65
- status: ok?(hjn) ? 'OK' : 'NOK'
66
- )
67
- end
68
-
69
- # Check if wallet has new transactions
70
- # @param (see foct)
71
- # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
72
- def ok?(hjn)
73
- hjn[:bs].round(6) == hjn[:es].round(6) && hjn[:bt].count == hjn[:et].count
74
- end
75
-
76
- # Format transaction text
77
- # @param [Hash] hlx ledger greymass
78
- # @return [String] texto formatado
79
- def fol(hlx)
80
- format(
81
- '%<sequence>12i %<from>-12.12s %<to>-12.12s %<action>-10.10s %<date>10.10s %<value>12.4f %<symbol>-6.6s',
82
- sequence: hlx[:itx],
83
- from: hlx[:from],
84
- to: hlx[:to],
85
- action: hlx[:name],
86
- date: hlx[:block_time].strftime('%F'),
87
- value: hlx[:quantity],
88
- symbol: hlx[:moe]
89
- )
90
- end
91
-
92
- # Determine if all transactions should be shown
93
- # @return [Boolean] mostra todas/novas transacoes
94
- def show_all?
95
- ops[:t] || false
96
- end
97
-
98
- # Fetch EOS account resources
99
- # @param [String] add EOS account name
100
- # @return [Array<BigDecimal>] lista recursos - liquido, net, spu
101
- def peosa(add)
102
- hac = api.account_gm(add)
103
- htr = hac.fetch(:total_resources, {})
104
- [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]
105
- end
106
-
107
- # Process and filter EOS transactions
108
- # @param add (see peosa)
109
- # @param [Array<Hash>] ary lista transacoes
110
- # @return [Array<Hash>] lista transacoes filtrada
111
- def peost(add, ary)
112
- ary.map do |t|
113
- act = t[:action_trace][:act]
114
- adt = act[:data]
115
- qtd = adt[:quantity].to_s
116
- t.merge(
117
- name: act[:name],
118
- from: adt[:from],
119
- quantity: qtd.to_d,
120
- account: act[:account],
121
- to: adt[:to],
122
- memo: adt[:memo].to_s.gsub(/\p{C}/, ''), # remove Non-Printable Characters
123
- moe: qtd[/[[:upper:]]+/],
124
- itx: t[:global_action_seq],
125
- iax: add,
126
- block_time: Time.parse(t[:block_time])
127
- )
128
- end
129
- end
130
-
131
- # Fetch Greymass data for a wallet
132
- # @param [Hash] wbq wallet bigquery
133
- # @return [Hash] dados greymass - address, saldo & transacoes
134
- def gmd(wbq)
135
- xbq = wbq[:ax]
136
- {ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq))}
137
- end
138
-
139
- # Combine BigQuery and Greymass data
140
- # @param wbq (see gmd)
141
- # @param [Hash] hgm dados greymass - address, saldo & transacoes
142
- # @return [Hash] dados juntos bigquery & greymass
143
- def bqgmd(wbq, hgm)
144
- xbq = wbq[:ax]
145
- {
146
- id: wbq[:id],
147
- ax: xbq,
148
- bs: wbq[:sl],
149
- bt: bqd[:nt].select { |o| o[:iax] == xbq },
150
- es: hgm[:sl],
151
- et: hgm[:tx]
152
- }
153
- end
154
-
155
- # Lazy Greymass API Initialization
156
- # @return [Apibc] API instance
157
- memoize def api
158
- Apibc.new
159
- end
160
-
161
- # Fetch all Greymass data
162
- # @return [Hash] Hash of Greymass data indexed by address
163
- memoize def exd
164
- bqd[:wb].map { |o| gmd(o) }.to_h { |h| [h[:ax], h] }
165
- end
166
-
167
- # Fetch combined BigQuery and Greymass data
168
- # @return [Array<Hash>] Combined data list
169
- memoize def bqexd
170
- bqd[:wb].map { |b| bqgmd(b, exd[b[:ax]]) }
171
- end
172
-
173
- # @return [Array<Integer>] indices transacoes bigquery
174
- memoize def bqkyt
175
- show_all? ? [] : bqd[:nt].map { |i| i[:itx] }
176
- end
177
-
178
- # @return [Array<Integer>] indices transacoes novas (greymass - bigquery)
179
- memoize def exkyt
180
- exd.values.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqkyt
181
- end
182
-
183
- # Get new transactions
184
- # @return [Array<Hash>] List of new transactions
185
- memoize def novxt
186
- exd.values.map { |t| t[:tx].select { |o| exkyt.include?(o[:itx]) } }.flatten.uniq { |i| i[:itx] }
187
- end
188
- end
189
- end