cns 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,19 @@
2
2
 
3
3
  # @author Hernani Rodrigues Vaz
4
4
  module Cns
5
- # classe para processar carteiras & transacoes normais e tokens
5
+ # classe para processar transacoes do etherscan
6
6
  class Etherscan
7
+ # @return [String] texto carteiras & transacoes & ajuste dias
8
+ def mostra_resumo
9
+ return unless dados.count.positive?
10
+
11
+ puts("\nid address etherscan nm tk bigquery nm tk")
12
+ dados.each { |e| puts(formata_carteira(e)) }
13
+ mostra_transacao_norml
14
+ mostra_transacao_token
15
+ mostra_configuracao_ajuste_dias
16
+ end
17
+
7
18
  # @param [Hash] hjn dados juntos bigquery & etherscan
8
19
  # @return [String] texto formatado duma carteira
9
20
  def formata_carteira(hjn)
@@ -19,12 +30,12 @@ module Cns
19
30
  def formata_valores(hjn)
20
31
  format(
21
32
  '%<v1>11.6f %<n1>2i %<n3>2i %<v2>12.6f %<n2>2i %<n4>2i %<ok>-3s',
22
- v1: hjn[:bs],
23
- n1: hjn[:bt].count,
24
- n3: hjn[:bk].count,
25
- v2: hjn[:es],
26
- n2: hjn[:et].count,
27
- n4: hjn[:ek].count,
33
+ v1: hjn[:es],
34
+ n1: hjn[:et].count,
35
+ n3: hjn[:ek].count,
36
+ v2: hjn[:bs],
37
+ n2: hjn[:bt].count,
38
+ n4: hjn[:bk].count,
28
39
  ok: ok?(hjn) ? 'OK' : 'NOK'
29
40
  )
30
41
  end
@@ -42,12 +53,13 @@ module Cns
42
53
  # @return [String] endereco formatado
43
54
  def formata_endereco(add, max)
44
55
  i = Integer((max - 2) / 2)
45
- e = (max <= 20 ? dbq[:wb].select { |s| s[:ax] == add }.first : nil) || { id: add }
56
+ e = (max <= 20 ? bqd[:wb].select { |s| s[:ax] == add }.first : nil) || { id: add }
46
57
  max < 7 ? 'erro' : "#{e[:id][0, i - 3]}..#{add[-i - 3..]}"
47
58
  end
48
59
 
49
- # @param [Hash] htx transacao normal
50
- # @return [String] texto formatado transacao normal
60
+ # @example (see Apibc#norml_es)
61
+ # @param [Hash] htx transacao normal etherscan
62
+ # @return [String] texto formatado transacao normal etherscan
51
63
  def formata_transacao_norml(htx)
52
64
  format(
53
65
  '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>17.6f',
@@ -59,8 +71,9 @@ module Cns
59
71
  )
60
72
  end
61
73
 
62
- # @param [Hash] hkx transacao token
63
- # @return [String] texto formatado transacao token
74
+ # @example (see Apibc#token_es)
75
+ # @param [Hash] hkx transacao token etherscan
76
+ # @return [String] texto formatado transacao token etherscan
64
77
  def formata_transacao_token(hkx)
65
78
  format(
66
79
  '%<bn>9i %<fr>-20.20s %<to>-20.20s %<dt>10.10s %<vl>11.3f %<sy>-5.5s',
@@ -73,17 +86,6 @@ module Cns
73
86
  )
74
87
  end
75
88
 
76
- # @return [String] texto carteiras & transacoes & ajuste dias
77
- def mostra_resumo
78
- return unless dados.count.positive?
79
-
80
- puts("\nid address bigquery nm tk etherscan nm tk")
81
- dados.each { |e| puts(formata_carteira(e)) }
82
- mostra_transacao_norml
83
- mostra_transacao_token
84
- mostra_configuracao_ajuste_dias
85
- end
86
-
87
89
  # @return [String] texto transacoes normais
88
90
  def mostra_transacao_norml
89
91
  return unless ops[:v] && novtx.count.positive?
@@ -6,10 +6,10 @@ require('bigdecimal/util')
6
6
  module Cns
7
7
  # (see Greymass)
8
8
  class Greymass
9
- # @return [Apigm] API greymass
9
+ # @return [Apibc] API blockchains
10
10
  attr_reader :api
11
11
  # @return [Array<Hash>] todos os dados bigquery
12
- attr_reader :dbq
12
+ attr_reader :bqd
13
13
  # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
14
14
  attr_reader :ops
15
15
 
@@ -20,56 +20,57 @@ module Cns
20
20
  # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
21
21
  # @return [Greymass] API greymass - processar transacoes
22
22
  def initialize(dad, pop)
23
- @api = Apigm.new
24
- @dbq = dad
23
+ @api = Apibc.new
24
+ @bqd = dad
25
25
  @ops = pop
26
26
  end
27
27
 
28
+ # @return [Array<Hash>] lista transacoes novas
29
+ def novax
30
+ @novax ||= bcd.map { |e| e[:tx].select { |s| idt.include?(s[:itx]) } }.flatten
31
+ end
32
+
28
33
  # @return [Array<String>] lista dos meus enderecos
29
34
  def lax
30
- @lax ||= dbq[:wb].map { |h| h[:ax] }
35
+ @lax ||= bqd[:wb].map { |h| h[:ax] }
31
36
  end
32
37
 
33
38
  # @return [Array<Hash>] todos os dados greymass - saldos & transacoes
34
- def dbc
35
- @dbc ||= dbq[:wb].map { |e| base_bc(e) }
39
+ def bcd
40
+ @bcd ||= bqd[:wb].map { |e| base_bc(e) }
36
41
  end
37
42
 
38
43
  # @return [Array<Hash>] todos os dados juntos bigquery & greymass
39
44
  def dados
40
- @dados ||= dbq[:wb].map { |b| bq_bc(b, dbc.select { |s| b[:ax] == s[:ax] }.first) }
45
+ @dados ||= bqd[:wb].map { |b| bq_bc(b, bcd.select { |s| b[:ax] == s[:ax] }.first) }
41
46
  end
42
47
 
43
48
  # @return [Array<Integer>] lista indices transacoes novas
44
- def bnt
45
- @bnt ||= (dbc.map { |e| e[:tx].map { |n| n[:itx] } }.flatten - (ops[:t] ? [] : dbq[:nt].map { |t| t[:itx] }))
46
- end
47
-
48
- # @return [Array<Hash>] lista transacoes novas
49
- def novax
50
- @novax ||= dbc.map { |e| e[:tx].select { |s| bnt.include?(s[:itx]) } }.flatten
49
+ def idt
50
+ @idt ||= (bcd.map { |e| e[:tx].map { |n| n[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |t| t[:itx] }))
51
51
  end
52
52
 
53
- # @param [Hash] hbq dados bigquery wallet
53
+ # @example (see Apibc#account_gm)
54
+ # @param [Hash] wbq wallet bigquery
54
55
  # @return [Hash] dados greymass - address, saldo & transacoes
55
- def base_bc(hbq)
56
- a = hbq[:ax]
56
+ def base_bc(wbq)
57
+ a = wbq[:ax]
57
58
  {
58
59
  ax: a,
59
60
  sl: greymass_sl(a).inject(:+),
60
- tx: filtrar_tx(a, api.all_tx(a))
61
+ tx: filtrar_tx(a, api.ledger_gm(a))
61
62
  }
62
63
  end
63
64
 
64
- # @param hbq (see base_bc)
65
- # @param [Hash] hbc dados greymass
65
+ # @param wbq (see base_bc)
66
+ # @param [Hash] hbc dados greymass - address, saldo & transacoes
66
67
  # @return [Hash] dados juntos bigquery & greymass
67
- def bq_bc(hbq, hbc)
68
+ def bq_bc(wbq, hbc)
68
69
  {
69
- id: hbq[:id],
70
- ax: hbq[:ax],
71
- bs: hbq[:sl],
72
- bt: dbq[:nt].select { |t| t[:iax] == hbq[:ax] },
70
+ id: wbq[:id],
71
+ ax: wbq[:ax],
72
+ bs: wbq[:sl],
73
+ bt: bqd[:nt].select { |t| t[:iax] == wbq[:ax] },
73
74
  es: hbc[:sl],
74
75
  et: hbc[:tx]
75
76
  }
@@ -78,7 +79,7 @@ module Cns
78
79
  # @param (see filtrar_tx)
79
80
  # @return [Array<BigDecimal>] lista recursos - liquido, net, spu
80
81
  def greymass_sl(add)
81
- v = api.account(account_name: add)
82
+ v = api.account_gm(add)
82
83
  [
83
84
  v[:core_liquid_balance].to_d,
84
85
  v[:total_resources][:net_weight].to_d,
@@ -86,9 +87,9 @@ module Cns
86
87
  ]
87
88
  end
88
89
 
89
- # @param [String] add endereco carteira EOS
90
- # @param [Array<Hash>] ary lista das transacoes
91
- # @return [Array<Hash>] lista transacoes ligadas a uma carteira filtrada
90
+ # @param add (see Apibc#account_gm)
91
+ # @param [Array<Hash>] ary lista transacoes
92
+ # @return [Array<Hash>] lista transacoes filtrada
92
93
  def filtrar_tx(add, ary)
93
94
  # elimina transferencia from: (lax) to: (add) - esta transferencia aparece em from: (add) to: (lax)
94
95
  # adiciona chave indice itx & adiciona identificador da carteira iax
@@ -2,18 +2,28 @@
2
2
 
3
3
  # @author Hernani Rodrigues Vaz
4
4
  module Cns
5
- # classe para processar carteiras & transacoes
5
+ # classe para processar transacoes do greymass
6
6
  class Greymass
7
+ # @return [String] texto carteiras & transacoes & ajuste dias
8
+ def mostra_resumo
9
+ return unless dados.count.positive?
10
+
11
+ puts("\naddress greymass ntx bigquery ntx")
12
+ dados.each { |e| puts(formata_carteira(e)) }
13
+ mostra_transacoes_novas
14
+ mostra_configuracao_ajuste_dias
15
+ end
16
+
7
17
  # @param [Hash] hjn dados juntos bigquery & greymass
8
18
  # @return [String] texto formatado duma carteira
9
19
  def formata_carteira(hjn)
10
20
  format(
11
21
  '%<s1>-12.12s %<v1>14.4f %<n1>4i %<v2>14.4f %<n2>4i %<ok>-3s',
12
22
  s1: hjn[:ax],
13
- v1: hjn[:bs],
14
- n1: hjn[:bt].count,
15
- v2: hjn[:es],
16
- n2: hjn[:et].count,
23
+ v1: hjn[:es],
24
+ n1: hjn[:et].count,
25
+ v2: hjn[:bs],
26
+ n2: hjn[:bt].count,
17
27
  ok: ok?(hjn) ? 'OK' : 'NOK'
18
28
  )
19
29
  end
@@ -24,47 +34,38 @@ module Cns
24
34
  hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
25
35
  end
26
36
 
27
- # @param [Hash] htx transacao
28
- # @return [String] texto formatado transacao
29
- def formata_transacao(htx)
37
+ # @example (see Apibc#ledger_gm)
38
+ # @param [Hash] hlx ledger greymass
39
+ # @return [String] texto formatado ledger greymass
40
+ def formata_ledger(hlx)
30
41
  format(
31
42
  '%<bn>12i %<fr>-12.12s %<to>-12.12s %<ac>-10.10s %<dt>10.10s %<vl>12.4f %<sy>-6.6s',
32
- bn: htx[:itx],
33
- fr: act_data(htx)[:from],
34
- to: act_data(htx)[:to],
35
- ac: act(htx)[:name],
36
- dt: Date.parse(htx[:block_time]),
37
- vl: act_data_quantity(htx).to_d,
38
- sy: act_data_quantity(htx)[/[[:upper:]]+/]
43
+ bn: hlx[:itx],
44
+ fr: act_data(hlx)[:from],
45
+ to: act_data(hlx)[:to],
46
+ ac: act(hlx)[:name],
47
+ dt: Date.parse(hlx[:block_time]),
48
+ vl: act_data_quantity(hlx).to_d,
49
+ sy: act_data_quantity(hlx)[/[[:upper:]]+/]
39
50
  )
40
51
  end
41
52
 
42
- # @param (see formata_transacao)
53
+ # @param (see formata_ledger)
43
54
  # @return [Hash] dados da acao
44
- def act(htx)
45
- htx[:action_trace][:act]
55
+ def act(hlx)
56
+ hlx[:action_trace][:act]
46
57
  end
47
58
 
48
- # @param (see formata_transacao)
59
+ # @param (see formata_ledger)
49
60
  # @return [Hash] dados da acao
50
- def act_data(htx)
51
- act(htx)[:data]
61
+ def act_data(hlx)
62
+ act(hlx)[:data]
52
63
  end
53
64
 
54
- # @param (see formata_transacao)
65
+ # @param (see formata_ledger)
55
66
  # @return [String] dados da quantidade
56
- def act_data_quantity(htx)
57
- act_data(htx)[:quantity].to_s
58
- end
59
-
60
- # @return [String] texto carteiras & transacoes & ajuste dias
61
- def mostra_resumo
62
- return unless dados.count.positive?
63
-
64
- puts("\naddress bigquery ntx greymass ntx")
65
- dados.each { |e| puts(formata_carteira(e)) }
66
- mostra_transacoes_novas
67
- mostra_configuracao_ajuste_dias
67
+ def act_data_quantity(hlx)
68
+ act_data(hlx)[:quantity].to_s
68
69
  end
69
70
 
70
71
  # @return [String] texto transacoes
@@ -72,7 +73,7 @@ module Cns
72
73
  return unless ops[:v] && novax.count.positive?
73
74
 
74
75
  puts("\nsequence num from to accao data valor moeda")
75
- sorax.each { |e| puts(formata_transacao(e)) }
76
+ sorax.each { |e| puts(formata_ledger(e)) }
76
77
  end
77
78
 
78
79
  # @return [String] texto configuracao ajuste dias das transacoes
@@ -4,12 +4,12 @@ require('bigdecimal/util')
4
4
 
5
5
  # @author Hernani Rodrigues Vaz
6
6
  module Cns
7
- # classe para processar saldos & transacoes trades e ledger
7
+ # classe para processar transacoes trades/ledger do kraken
8
8
  class Kraken
9
9
  # @return [Apius] API kraken
10
10
  attr_reader :api
11
11
  # @return [Array<Hash>] todos os dados bigquery
12
- attr_reader :dbq
12
+ attr_reader :bqd
13
13
  # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
14
14
  attr_reader :ops
15
15
 
@@ -20,59 +20,71 @@ module Cns
20
20
  # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
21
21
  # @return [Kraken] API kraken - obter saldos & transacoes trades e ledger
22
22
  def initialize(dad, pop)
23
- # API kraken base
24
- @api = Apius.new
25
- @dbq = dad
23
+ @api = Apice.new
24
+ @bqd = dad
26
25
  @ops = pop
27
26
  end
28
27
 
28
+ # @return [Hash] trades kraken novos
29
+ def trades
30
+ @trades ||= exd[:kt].select { |k, _| kyt.include?(k) }
31
+ end
32
+
33
+ # @return [Hash] ledger kraken novos
34
+ def ledger
35
+ @ledger ||= exd[:kl].select { |k, _| kyl.include?(k) }
36
+ end
37
+
38
+ # @return [String] texto saldos & transacoes & ajuste dias
39
+ def mostra_resumo
40
+ puts("\nKRAKEN\ntipo kraken bigquery")
41
+ exd[:sl].each { |k, v| puts(formata_saldos(k, v)) }
42
+ mostra_totais
43
+
44
+ mostra_trades
45
+ mostra_ledger
46
+ return if trades.empty?
47
+
48
+ puts("\nstring ajuste dias dos trades\n-h=#{kyt.map { |e| "#{e}:0" }.join(' ')}")
49
+ end
50
+
29
51
  # @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
30
52
  def exd
31
53
  @exd ||= {
32
- sl: api.account,
33
- kt: api.trades,
34
- kl: api.ledger
54
+ sl: api.account_us,
55
+ kt: api.trades_us,
56
+ kl: api.ledger_us
35
57
  }
36
58
  end
37
59
 
38
- # @return [Array<String>] lista txid de transacoes trades
60
+ # @return [Array<String>] lista txid dos trades novos
39
61
  def kyt
40
- @kyt ||= exd[:kt].keys - (ops[:t] ? [] : dbq[:nt].map { |e| e[:txid].to_sym })
62
+ @kyt ||= exd[:kt].keys - (ops[:t] ? [] : bqd[:nt].map { |e| e[:txid].to_sym })
41
63
  end
42
64
 
43
- # @return [Array<String>] lista txid de transacoes ledger
65
+ # @return [Array<String>] lista txid dos ledger novos
44
66
  def kyl
45
- @kyl ||= exd[:kl].keys - (ops[:t] ? [] : dbq[:nl].map { |e| e[:txid].to_sym })
46
- end
47
-
48
- # @return [Hash] transacoes trades
49
- def trades
50
- @trades ||= exd[:kt].select { |k, _| kyt.include?(k) }
67
+ @kyl ||= exd[:kl].keys - (ops[:t] ? [] : bqd[:nl].map { |e| e[:txid].to_sym })
51
68
  end
52
69
 
53
- # @return [Hash] transacoes ledger
54
- def ledger
55
- @ledger ||= exd[:kl].select { |k, _| kyl.include?(k) }
56
- end
57
-
58
- # @example (see Apius#account)
70
+ # @example (see Apice#account_us)
59
71
  # @param [String] moe codigo kraken da moeda
60
72
  # @param [BigDecimal] sal saldo kraken da moeda
61
- # @return [String] texto formatado saldos (kraken/bigquery) & iguais/ok/nok?
73
+ # @return [String] texto formatado saldos
62
74
  def formata_saldos(moe, sal)
63
- t = dbq[:sl][moe.downcase.to_sym].to_d
75
+ t = bqd[:sl][moe.downcase.to_sym].to_d
64
76
  format(
65
77
  '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
66
78
  mo: moe.upcase,
67
- kr: sal,
79
+ kr: sal.to_d,
68
80
  bq: t,
69
- ok: t == sal ? 'OK' : 'NOK'
81
+ ok: t == sal.to_d ? 'OK' : 'NOK'
70
82
  )
71
83
  end
72
84
 
73
- # @example (see Apius#trades)
85
+ # @example (see Apice#trades_us)
74
86
  # @param (see Bigquery#ust_val1)
75
- # @return [String] texto formatado transacao trade
87
+ # @return [String] texto formatado trade
76
88
  def formata_trades(idx, htx)
77
89
  format(
78
90
  '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-8.8s %<pr>8.2f %<vl>15.7f %<co>8.2f',
@@ -86,9 +98,9 @@ module Cns
86
98
  )
87
99
  end
88
100
 
89
- # @example (see Apius#ledger)
101
+ # @example (see Apice#ledger_us)
90
102
  # @param (see Bigquery#usl_val)
91
- # @return [String] texto formatado transacao ledger
103
+ # @return [String] texto formatado ledger
92
104
  def formata_ledger(idx, hlx)
93
105
  format(
94
106
  '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-4.4s %<pr>18.7f %<vl>18.7f',
@@ -101,16 +113,15 @@ module Cns
101
113
  )
102
114
  end
103
115
 
104
- # @return [String] texto saldos & transacoes & ajuste dias
105
- def mostra_resumo
106
- puts("\nKRAKEN\nmoeda saldo kraken saldo bigquery")
107
- exd[:sl].each { |k, v| puts(formata_saldos(k, v.to_d)) }
116
+ # @return [String] texto totais numero de transacoes
117
+ def mostra_totais
118
+ a = exd[:kt].count
119
+ b = bqd[:nt].count
120
+ c = exd[:kl].count
121
+ d = bqd[:nl].count
108
122
 
109
- mostra_trades
110
- mostra_ledger
111
- return unless trades.count.positive?
112
-
113
- puts("\nstring ajuste dias dos trades\n-h=#{kyt.map { |e| "#{e}:0" }.join(' ')}")
123
+ puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: a, b: b, o: a == b ? 'OK' : 'NOK')}")
124
+ puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: c, d: d, o: c == d ? 'OK' : 'NOK')}")
114
125
  end
115
126
 
116
127
  # @return [String] texto transacoes trades