Class: MixinBot::NodeCLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/mixin_bot/cli/node.rb

Constant Summary collapse

UI =
::CLI::UI

Instance Method Summary collapse

Instance Method Details

#listallnodesObject



12
13
14
15
16
17
18
# File 'lib/mixin_bot/cli/node.rb', line 12

def listallnodes
  return unless ensure_mixin_command_exist

  o, e, _s = Open3.capture3('mixin -n 35.188.235.212:8239 listallnodes')
  log e unless e.empty?
  log o
end

#mintObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mixin_bot/cli/node.rb', line 25

def mint
  c = (Date.today - Date.new(2019, 2, 28)).to_i + 1
  distributions = []
  UI::Spinner.spin('Listing mint distributions') do |spinner|
    o, _e, _s = Open3.capture3(
      'mixin',
      '-n',
      options[:node],
      'listmintdistributions',
      '-c',
      c.to_s
    )
    distributions = eval o
    spinner.update_title "#{distributions.size} mint distributions listed"
  end

  tx = ''
  UI::Spinner.spin('Finding transaction') do |spinner|
    index = distributions.index(&->(d) { d[:batch] == options[:batch] })
    tx = distributions[index][:transaction]
    spinner.update_title "Transaction hash found: #{tx}"
  end

  UI::Spinner.spin('Fetching transaction') do |spinner|
    o, _e, _s = Open3.capture3(
      'mixin',
      '-n',
      options[:node],
      'gettransaction',
      '-x',
      tx
    )
    tx = eval o
    spinner.update_title "#{tx[:outputs].size} transaction outputs found"
  end

  tx[:outputs].each_with_index do |output, index|
    address = ''
    UI::Spinner.spin("Checking output index: #{index}") do |spinner|
      o, _e, _s = Open3.capture3(
        'mixin',
        'decryptghostkey',
        '--key',
        output[:keys].first,
        '--mask',
        output[:mask],
        '--view',
        options[:view]
      )
      address = o.chomp
      spinner.update_title "Index #{index} Address: #{address}"
    end
    log "Found Utxo: #{index}" if address == options[:address]
  end
end