class Zold::Stress::Pool
Pool
of wallets.
Public Class Methods
new(wallets:, remotes:, copies:, stats:, opts:, log: Zold::Log::NULL, vlog: Zold::Log::NULL)
click to toggle source
# File lib/zold/stress/pool.rb, line 40 def initialize(wallets:, remotes:, copies:, stats:, opts:, log: Zold::Log::NULL, vlog: Zold::Log::NULL) @wallets = wallets @remotes = remotes @copies = copies @log = log @vlog = vlog @opts = opts @stats = stats end
Public Instance Methods
rebuild()
click to toggle source
# File lib/zold/stress/pool.rb, line 51 def rebuild raise "There are no wallets in the pool at #{@wallets.path}, at least one is needed" if @wallets.all.empty? balances = @wallets.all .map { |id| { id: id, balance: @wallets.acq(id, &:balance) } } .sort_by { |h| h[:balance] } .reverse balances.last([balances.count - @opts['pool'], 0].max).each do |h| Zold::Remove.new(wallets: @wallets, log: @vlog).run( ['remove', h[:id].to_s] ) end Tempfile.open do |f| File.write(f, @wallets.acq(balances[0][:id], &:key).to_s) while @wallets.all.count < @opts['pool'] Zold::Create.new(wallets: @wallets, log: @vlog, remotes: nil).run( ['create', "--public-key=#{f.path}", "--network=#{@opts['network']}", '--skip-test'] + @opts.arguments ) end end return if balances.find { |b| b[:balance].positive? } raise "There is not a single wallet among #{balances.count} with a positive balance, in #{@wallets.path}:\n\ #{balances.map { |b| "#{b[:id]}: #{b[:balance]}" }.join("\n")}" end