zold 0.10.5 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Procfile +1 -1
- data/lib/zold/commands/fetch.rb +5 -4
- data/lib/zold/commands/merge.rb +12 -2
- data/lib/zold/commands/push.rb +4 -4
- data/lib/zold/commands/remote.rb +4 -4
- data/lib/zold/commands/taxes.rb +3 -4
- data/lib/zold/http.rb +21 -2
- data/lib/zold/key.rb +4 -0
- data/lib/zold/patch.rb +0 -3
- data/lib/zold/remotes.rb +9 -0
- data/lib/zold/version.rb +1 -1
- data/test/test_http.rb +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc808990a7aeb6946114017c4754f6534493faab
|
4
|
+
data.tar.gz: 4c8f152bc663c64613fb864c0900977a60a613b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1783a36f812fa552685868137567afbc671a1e8c27eef28e4b0421075872c3425c104b4c1defbc9107c095054b1dde86e9807b9c6ab33b927936dfaef32a60c7
|
7
|
+
data.tar.gz: 4f423df3b48d43f2018678c511139cbc2e6fb109508739f345cebf84c4ce71d7628982d04a8923a13e0416eae23095fc24ac17da3fbc9f71f39184b69ad32cff
|
data/Procfile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
web: LC_ALL=UTF-8 ./bin/zold node --no-colors --verbose --trace --bind-port=$PORT --port=80 --host=b1.zold.io --threads=
|
1
|
+
web: LC_ALL=UTF-8 ./bin/zold node --no-colors --verbose --trace --bind-port=$PORT --port=80 --host=b1.zold.io --threads=0 --invoice=JKFq17yipfjLtX@0000000000000000 --never-reboot
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -72,20 +72,21 @@ Available options:"
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def fetch_one(id, r, cps, opts)
|
75
|
+
start = Time.now
|
75
76
|
if opts['ignore-node'].include?(r.to_s)
|
76
77
|
@log.info("#{r} ignored because of --ignore-node")
|
77
78
|
return false
|
78
79
|
end
|
79
80
|
res = r.http("/wallet/#{id}").get
|
80
81
|
raise "Wallet #{id} not found" if res.code == '404'
|
81
|
-
|
82
|
+
r.assert_code(200, res)
|
82
83
|
json = JSON.parse(res.body)
|
83
84
|
score = Score.parse_json(json['score'])
|
84
|
-
|
85
|
-
raise "Score expired #{score}" if score.expired?
|
85
|
+
r.assert_valid_score(score)
|
86
86
|
raise "Score is too weak #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
87
87
|
cps.add(json['body'], score.host, score.port, score.value)
|
88
|
-
@log.info("#{r} #{json['body'].length}b/#{Rainbow(score.value).green} (#{json['version']})
|
88
|
+
@log.info("#{r} #{json['body'].length}b/#{Rainbow(score.value).green} (#{json['version']}) \
|
89
|
+
in #{(Time.now - start).round(2)}s")
|
89
90
|
end
|
90
91
|
end
|
91
92
|
end
|
data/lib/zold/commands/merge.rb
CHANGED
@@ -63,9 +63,19 @@ Available options:"
|
|
63
63
|
raise 'There are no remote copies, try FETCH first' if cps.all.empty?
|
64
64
|
cps = cps.all.sort_by { |c| c[:score] }.reverse
|
65
65
|
patch = Patch.new
|
66
|
-
|
66
|
+
main = Wallet.new(cps[0][:path])
|
67
|
+
patch.start(main)
|
67
68
|
cps[1..-1].each do |c|
|
68
|
-
|
69
|
+
extra = Wallet.new(c[:path])
|
70
|
+
if extra.network != main.network
|
71
|
+
@log.error("The wallet is from a different network '#{wallet.version}', ours is '#{@network}'")
|
72
|
+
next
|
73
|
+
end
|
74
|
+
if extra.key != main.key
|
75
|
+
@log.error('Public key mismatch')
|
76
|
+
next
|
77
|
+
end
|
78
|
+
patch.join(extra)
|
69
79
|
end
|
70
80
|
modified = patch.save(wallet.path, overwrite: true)
|
71
81
|
if modified
|
data/lib/zold/commands/push.rb
CHANGED
@@ -58,18 +58,18 @@ Available options:"
|
|
58
58
|
def push(wallet, _)
|
59
59
|
total = 0
|
60
60
|
@remotes.iterate(@log) do |r|
|
61
|
+
start = Time.now
|
61
62
|
response = r.http("/wallet/#{wallet.id}").put(File.read(wallet.path))
|
62
63
|
if response.code == '304'
|
63
64
|
@log.info("#{r}: same version there")
|
64
65
|
next
|
65
66
|
end
|
66
|
-
|
67
|
+
r.assert_code(200, response)
|
67
68
|
json = JSON.parse(response.body)['score']
|
68
69
|
score = Score.parse_json(json)
|
69
|
-
|
70
|
-
raise "Expired score #{score}" if score.expired?
|
70
|
+
r.assert_valid_score(score)
|
71
71
|
raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
|
72
|
-
@log.info("#{r} accepted: #{Rainbow(score.value).green}")
|
72
|
+
@log.info("#{r} accepted in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green}")
|
73
73
|
total += score.value
|
74
74
|
end
|
75
75
|
@log.info("Total score is #{total}")
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -116,12 +116,12 @@ Available options:"
|
|
116
116
|
def update(opts, deep = true)
|
117
117
|
capacity = []
|
118
118
|
@remotes.iterate(@log) do |r|
|
119
|
+
start = Time.now
|
119
120
|
res = r.http('/remotes').get
|
120
|
-
|
121
|
+
r.assert_code(200, res)
|
121
122
|
json = JSON.parse(res.body)
|
122
123
|
score = Score.parse_json(json['score'])
|
123
|
-
|
124
|
-
raise "Expired score #{score}" if score.expired?
|
124
|
+
r.assert_valid_score(score)
|
125
125
|
raise "Score too weak: #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
126
126
|
raise "Masqueraded as #{score.host}:#{score.port}" if r.host != score.host || r.port != score.port
|
127
127
|
@remotes.rescore(score.host, score.port, score.value)
|
@@ -131,7 +131,7 @@ Available options:"
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
capacity << { host: score.host, port: score.port, count: json['all'].count }
|
134
|
-
@log.info("#{r}: #{Rainbow(score.value).green} (#{json['version']})")
|
134
|
+
@log.info("#{r}: #{Rainbow(score.value).green} (#{json['version']}) in #{(Time.now - start).round(2)}")
|
135
135
|
end
|
136
136
|
max_capacity = capacity.map { |c| c[:count] }.max || 0
|
137
137
|
capacity.each do |c|
|
data/lib/zold/commands/taxes.rb
CHANGED
@@ -119,14 +119,13 @@ Available options:"
|
|
119
119
|
best = []
|
120
120
|
@remotes.iterate(@log) do |r|
|
121
121
|
res = r.http.get
|
122
|
-
|
122
|
+
r.assert_code(200, res)
|
123
123
|
json = JSON.parse(res.body)
|
124
124
|
score = Score.parse_json(json['score'])
|
125
|
-
|
126
|
-
raise "Expired score #{score}" if score.expired?
|
125
|
+
r.assert_valid_score(score)
|
127
126
|
raise "Score is too weak (<#{Score::STRENGTH}) #{score}" if score.strength < Score::STRENGTH
|
128
127
|
raise "Score is too small (<#{Tax::EXACT_SCORE})" if score.value < Tax::EXACT_SCORE
|
129
|
-
@log.info("#{
|
128
|
+
@log.info("#{r}: #{Rainbow(score.value).green}")
|
130
129
|
best << score
|
131
130
|
end
|
132
131
|
best.sort_by(&:value).reverse
|
data/lib/zold/http.rb
CHANGED
@@ -50,7 +50,7 @@ module Zold
|
|
50
50
|
http.read_timeout = 5
|
51
51
|
return http.request_get(@uri.path, headers)
|
52
52
|
rescue StandardError => e
|
53
|
-
|
53
|
+
Error.new(e)
|
54
54
|
end
|
55
55
|
|
56
56
|
def put(body)
|
@@ -64,11 +64,30 @@ module Zold
|
|
64
64
|
)
|
65
65
|
)
|
66
66
|
rescue StandardError => e
|
67
|
-
|
67
|
+
Error.new(e)
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
71
71
|
|
72
|
+
# The error, if connection fails
|
73
|
+
class Error
|
74
|
+
def initialize(ex)
|
75
|
+
@ex = ex
|
76
|
+
end
|
77
|
+
|
78
|
+
def body
|
79
|
+
@ex.message + "\n" + @ex.backtrace.join("\n\t")
|
80
|
+
end
|
81
|
+
|
82
|
+
def code
|
83
|
+
'599'
|
84
|
+
end
|
85
|
+
|
86
|
+
def message
|
87
|
+
@ex.message
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
72
91
|
def headers
|
73
92
|
headers = {
|
74
93
|
'User-Agent': "Zold #{VERSION}",
|
data/lib/zold/key.rb
CHANGED
data/lib/zold/patch.rb
CHANGED
@@ -37,9 +37,6 @@ module Zold
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def join(wallet)
|
40
|
-
if wallet.network != @network
|
41
|
-
raise "The wallet is from a different network '#{wallet.version}', ours is '#{@network}'"
|
42
|
-
end
|
43
40
|
negative = @txns.select { |t| t.amount.negative? }
|
44
41
|
max = negative.empty? ? 0 : negative.max_by(&:id).id
|
45
42
|
wallet.txns.each do |txn|
|
data/lib/zold/remotes.rb
CHANGED
@@ -61,6 +61,15 @@ module Zold
|
|
61
61
|
def to_s
|
62
62
|
"#{@host}:#{@port}"
|
63
63
|
end
|
64
|
+
|
65
|
+
def assert_code(code, response)
|
66
|
+
raise "#{response.code} \"#{response.message}\" at \"#{response.body}\"" unless response.code.to_i == code
|
67
|
+
end
|
68
|
+
|
69
|
+
def assert_valid_score(score)
|
70
|
+
raise "Invalid score #{score}" unless score.valid?
|
71
|
+
raise "Expired score #{score}" if score.expired?
|
72
|
+
end
|
64
73
|
end
|
65
74
|
|
66
75
|
def initialize(file, farm = Farm::Empty.new)
|
data/lib/zold/version.rb
CHANGED
data/test/test_http.rb
CHANGED
@@ -31,7 +31,16 @@ require_relative '../lib/zold/http'
|
|
31
31
|
class TestHttp < Minitest::Test
|
32
32
|
def test_pings_broken_uri
|
33
33
|
stub_request(:get, 'http://bad-host/').to_return(status: 500)
|
34
|
-
|
34
|
+
res = Zold::Http.new(URI('http://bad-host/')).get
|
35
|
+
assert_equal('500', res.code)
|
36
|
+
assert_equal('', res.body)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_pings_with_exception
|
40
|
+
stub_request(:get, 'http://exception/').to_return { raise 'Intentionally' }
|
41
|
+
res = Zold::Http.new(URI('http://exception/')).get
|
42
|
+
assert_equal('599', res.code)
|
43
|
+
assert(res.body.include?('Intentionally'))
|
35
44
|
end
|
36
45
|
|
37
46
|
def test_pings_live_uri
|