Class: Zold::Routines::Reconcile

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

Overview

R

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2018 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(opts, wallets, remotes, copies, address, log: Log::NULL) ⇒ Reconcile

Returns a new instance of Reconcile.



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

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

Instance Method Details

#exec(_ = 0) ⇒ Object



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

def exec(_ = 0)
  sleep(20 * 60) unless @opts['routine-immediately']
  @remotes.iterate(@log) do |r|
    next unless r.master?
    next if r.to_mnemo == @address
    res = r.http('/wallets').get
    r.assert_code(200, res)
    missing = res.body.strip.split("\n").compact
      .select { |i| /^[a-f0-9]{16}$/.match?(i) }
      .reject { |i| @wallets.acq(Zold::Id.new(i), &:exists?) }
    missing.each { |i| pull(i) }
    if missing.empty?
      log.info("Nothing to reconcile with #{r}, we are good at #{@address}")
    else
      @log.info("Reconcile routine pulled #{missing.count} wallets from #{r}")
    end
  end
end