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
# 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)
    res.body.strip.split("\n").compact
      .select { |i| /^[a-f0-9]{16}$/.match?(i) }
      .reject { |i| @wallets.acq(Zold::Id.new(i), &:exists?) }
      .each { |i| pull(i) }
  end
end