class MixinBot::NodeCLI

Constants

UI

github.com/Shopify/cli-ui

Public Instance Methods

listallnodes() click to toggle source
# 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
mint() click to toggle source
# 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

Private Instance Methods

command?(name) click to toggle source
# File lib/mixin_bot/cli/node.rb, line 90
def command?(name)
  `which #{name}`
  $CHILD_STATUS.success?
end
ensure_mixin_command_exist() click to toggle source
# File lib/mixin_bot/cli/node.rb, line 83
def ensure_mixin_command_exist
  return true if command?('mixin')

  log UI.fmt '{{x}} `mixin` command is not valid!'
  log UI.fmt 'Please install mixin software and provide a executable `mixin` command'
end
log(obj) click to toggle source
# File lib/mixin_bot/cli/node.rb, line 95
def log(obj)
  if options[:pretty]
    if obj.is_a? String
      puts obj
    else
      ap obj
    end
  else
    puts obj.inspect
  end
end