Class: ItsyBtc::Commands::BalanceCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/itsy-btc/commands/balance_command.rb

Instance Attribute Summary

Attributes inherited from Command

#wallet

Instance Method Summary collapse

Methods inherited from Command

args, name, summary

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/itsy-btc/commands/balance_command.rb', line 7

def run
  if @wallet.nil?
    puts "No wallet found! Use `itsy init` to create one."
    exit
  end

  entries = @wallet.entries
  if entries.empty?
    puts "This wallet has no addresses."
  else
    total = entries.map { |e| Lookup.balance(e.address) || exit }.inject(:+)
    puts ItsyBtc.format_value(total) + " BTC"
  end
end