Class: Zold::List

Inherits:
Object
  • Object
show all
Includes:
ThreadBadge
Defined in:
lib/zold/commands/list.rb

Overview

LIST command

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, copies:, log: Log::NULL) ⇒ List

Returns a new instance of List.



38
39
40
41
42
# File 'lib/zold/commands/list.rb', line 38

def initialize(wallets:, copies:, log: Log::NULL)
  @wallets = wallets
  @copies = copies
  @log = log
end

Instance Method Details

#run(_ = []) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zold/commands/list.rb', line 44

def run(_ = [])
  total = 0
  txns = 0
  size = 0
  balance = Amount::ZERO
  @wallets.all.sort.each do |id|
    total += 1
    cps = Copies.new(File.join(@copies, id))
    @wallets.acq(id) do |wallet|
      msg = "#{wallet.mnemo} #{cps.all.count}c"
      msg += " (net:#{wallet.network})" if wallet.network != Wallet::MAINET
      txns += wallet.txns.count
      balance += wallet.balance
      size += wallet.size
      @log.info(msg)
    end
  end
  @log.info("#{total} wallets, #{txns} transactions, #{Size.new(size)}, #{balance} in total")
end