Class: Zold::Routines::Spread

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/commands/routines/spread.rb

Overview

Spread them

Instance Method Summary collapse

Constructor Details

#initialize(opts, wallets, remotes, log: Log::Quiet.new) ⇒ Spread

Returns a new instance of Spread.



36
37
38
39
40
41
# File 'lib/zold/commands/routines/spread.rb', line 36

def initialize(opts, wallets, remotes, log: Log::Quiet.new)
  @opts = opts
  @wallets = wallets
  @remotes = remotes
  @log = log
end

Instance Method Details

#exec(_ = 0) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zold/commands/routines/spread.rb', line 43

def exec(_ = 0)
  return if @remotes.all.empty?
  if @opts['routine-immediately']
    @log.info('Spreading the wallets immediately, because of --routine-immediately')
  else
    sleep(60)
  end
  ids = @wallets.all.sample(10)
  Push.new(wallets: @wallets, remotes: @remotes, log: @log).run(
    ['push', "--network=#{@opts['network']}"] + ids.map(&:to_s)
  )
  if ids.empty?
    @log.info("Spread didn't push any wallets, we are empty")
  else
    @log.info("Spread #{ids.count} random wallets out of #{@wallets.all.count}: #{ids.join(', ')}")
  end
end