lib/zold/commands/fetch.rb in zold-0.6.4 vs lib/zold/commands/fetch.rb in zold-0.7
- old
+ new
@@ -34,11 +34,12 @@
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
# License:: MIT
module Zold
# FETCH pulling command
class Fetch
- def initialize(remotes:, copies:, log: Log::Quiet.new)
+ def initialize(wallets:, remotes:, copies:, log: Log::Quiet.new)
+ @wallets = wallets
@remotes = remotes
@copies = copies
@log = log
end
@@ -80,29 +81,33 @@
@log.info("#{address} ignored because of --ignore-node")
return false
end
uri = URI("#{r[:home]}wallet/#{id}")
res = Http.new(uri).get
+ if res.code == '404'
+ @log.info("#{address} wallet #{Rainbow('not found').red}")
+ return false
+ end
unless res.code == '200'
@log.error("#{address} #{Rainbow(res.code).red}/#{res.message} at #{uri}")
return false
end
json = JSON.parse(res.body)
score = Score.parse_json(json['score'])
unless score.valid?
- @log.error("#{address}: invalid score")
+ @log.error("#{address}: invalid score: #{score}")
return false
end
if score.expired?
- @log.error("#{address}: score expired")
+ @log.error("#{address}: score expired: #{score}")
return false
end
if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
- @log.error("#{address} score is too weak: #{score.strength} (<#{Score::STRENGTH})")
+ @log.error("#{address} score is too weak (#{score.strength}<#{Score::STRENGTH}): #{score}")
return false
end
cps.add(json['body'], score.host, score.port, score.value)
- @log.info("#{address} #{json['body'].length}b/#{Rainbow(score.value).green} (v.#{json['version']})")
+ @log.info("#{address} #{json['body'].length}b/#{Rainbow(score.value).green} (#{json['version']})")
true
end
end
end