zold 0.16.22 → 0.16.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/commands/fetch.rb +3 -1
- data/lib/zold/commands/push.rb +1 -1
- data/lib/zold/node/front.rb +36 -55
- data/lib/zold/patch.rb +3 -4
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_fetch.rb +3 -3
- data/test/commands/test_pull.rb +1 -0
- data/test/node/test_front.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5128884745aa60eecc3b94b20b184ce5e297cf96d9550f12a20bccfa5445b01
|
4
|
+
data.tar.gz: 4e1403a766b2e41e99de13956a38a32fc299cc77e81047bc96c80019cb3feb53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9821efb88ba25bd9836794cba697a2342978cfda9281c7507f4d08a5b44d6b4c68535da47311b3cfe44a0cab05e6a94fec7a773414e73242ba98862abd3c2f91
|
7
|
+
data.tar.gz: 2e3ff0c904aab956251070dfb01573022da6af3bfb9904df325c384d25795c184266c3b25826130eb91f01ce421db9cc6db5435e917f7a013180d076d9511597
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -104,7 +104,9 @@ Available options:"
|
|
104
104
|
return 0
|
105
105
|
end
|
106
106
|
uri = "/wallet/#{id}"
|
107
|
-
|
107
|
+
size = r.http(uri + '/size').get
|
108
|
+
r.assert_code(200, size)
|
109
|
+
res = r.http(uri).get(timeout: 2 + size.body.to_i * 0.01 / 1024)
|
108
110
|
raise "Wallet #{id} not found" if res.code == '404'
|
109
111
|
r.assert_code(200, res)
|
110
112
|
json = JsonPage.new(res.body, uri).to_hash
|
data/lib/zold/commands/push.rb
CHANGED
@@ -92,7 +92,7 @@ total score for #{id} is #{total}")
|
|
92
92
|
IO.read(wallet.path)
|
93
93
|
end
|
94
94
|
uri = "/wallet/#{id}"
|
95
|
-
response = r.http(uri).put(content, timeout:
|
95
|
+
response = r.http(uri).put(content, timeout: 2 + content.length * 0.01 / 1024)
|
96
96
|
@wallets.find(id) do |wallet|
|
97
97
|
if response.code == '304'
|
98
98
|
@log.info("#{r}: same version of #{wallet.mnemo} there, in #{Age.new(start, limit: 0.5)}")
|
data/lib/zold/node/front.rb
CHANGED
@@ -218,10 +218,7 @@ in #{Age.new(@start, limit: 1)}")
|
|
218
218
|
end
|
219
219
|
|
220
220
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})} do
|
221
|
-
|
222
|
-
id = Id.new(params[:id])
|
223
|
-
copy_of(id) do |wallet|
|
224
|
-
content_type('application/json')
|
221
|
+
fetch('application/json') do |wallet|
|
225
222
|
pretty(
|
226
223
|
version: settings.opts['expose-version'],
|
227
224
|
alias: settings.node_alias,
|
@@ -232,7 +229,7 @@ in #{Age.new(@start, limit: 1)}")
|
|
232
229
|
mtime: wallet.mtime.utc.iso8601,
|
233
230
|
size: wallet.size,
|
234
231
|
digest: wallet.digest,
|
235
|
-
copies: Copies.new(File.join(settings.copies, id)).all.count,
|
232
|
+
copies: Copies.new(File.join(settings.copies, wallet.id)).all.count,
|
236
233
|
balance: wallet.balance.to_i,
|
237
234
|
body: File.new(wallet.path).read
|
238
235
|
)
|
@@ -240,10 +237,7 @@ in #{Age.new(@start, limit: 1)}")
|
|
240
237
|
end
|
241
238
|
|
242
239
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16}).json} do
|
243
|
-
|
244
|
-
id = Id.new(params[:id])
|
245
|
-
copy_of(id) do |wallet|
|
246
|
-
content_type('application/json')
|
240
|
+
fetch('application/json') do |wallet|
|
247
241
|
pretty(
|
248
242
|
version: settings.opts['expose-version'],
|
249
243
|
alias: settings.node_alias,
|
@@ -261,46 +255,35 @@ in #{Age.new(@start, limit: 1)}")
|
|
261
255
|
end
|
262
256
|
|
263
257
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/balance} do
|
264
|
-
|
265
|
-
id = Id.new(params[:id])
|
266
|
-
copy_of(id) do |wallet|
|
267
|
-
content_type 'text/plain'
|
268
|
-
wallet.balance.to_i.to_s
|
269
|
-
end
|
258
|
+
fetch { |w| w.balance.to_i.to_s }
|
270
259
|
end
|
271
260
|
|
272
261
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/key} do
|
273
|
-
|
274
|
-
id = Id.new(params[:id])
|
275
|
-
copy_of(id) do |wallet|
|
276
|
-
content_type 'text/plain'
|
277
|
-
wallet.key.to_pub
|
278
|
-
end
|
262
|
+
fetch { |w| w.key.to_pub }
|
279
263
|
end
|
280
264
|
|
281
265
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/mtime} do
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
266
|
+
fetch { |w| w.mtime.utc.iso8601.to_s }
|
267
|
+
end
|
268
|
+
|
269
|
+
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/size} do
|
270
|
+
fetch { |w| w.size.to_s }
|
271
|
+
end
|
272
|
+
|
273
|
+
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/age} do
|
274
|
+
fetch { |w| w.age.to_s }
|
275
|
+
end
|
276
|
+
|
277
|
+
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/mnemo} do
|
278
|
+
fetch(&:mnemo)
|
288
279
|
end
|
289
280
|
|
290
281
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/digest} do
|
291
|
-
|
292
|
-
id = Id.new(params[:id])
|
293
|
-
copy_of(id) do |wallet|
|
294
|
-
content_type 'text/plain'
|
295
|
-
wallet.digest
|
296
|
-
end
|
282
|
+
fetch(&:digest)
|
297
283
|
end
|
298
284
|
|
299
285
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})\.txt} do
|
300
|
-
|
301
|
-
id = Id.new(params[:id])
|
302
|
-
copy_of(id) do |wallet|
|
303
|
-
content_type 'text/plain'
|
286
|
+
fetch do |wallet|
|
304
287
|
[
|
305
288
|
wallet.network,
|
306
289
|
wallet.protocol,
|
@@ -313,7 +296,7 @@ in #{Age.new(@start, limit: 1)}")
|
|
313
296
|
"Balance: #{wallet.balance.to_zld(8)} ZLD (#{wallet.balance.to_i} zents)",
|
314
297
|
"Transactions: #{wallet.txns.count}",
|
315
298
|
"Taxes: #{Tax.new(wallet).paid} paid, the debt is #{Tax.new(wallet).debt}",
|
316
|
-
"File size: #{wallet.size} bytes (#{Copies.new(File.join(settings.copies, id)).all.count} copies)",
|
299
|
+
"File size: #{wallet.size} bytes (#{Copies.new(File.join(settings.copies, wallet.id)).all.count} copies)",
|
317
300
|
"Modified: #{wallet.mtime.utc.iso8601} (#{Age.new(wallet.mtime.utc.iso8601)} ago)",
|
318
301
|
"Digest: #{wallet.digest}"
|
319
302
|
].join("\n")
|
@@ -321,20 +304,12 @@ in #{Age.new(@start, limit: 1)}")
|
|
321
304
|
end
|
322
305
|
|
323
306
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})\.bin} do
|
324
|
-
|
325
|
-
id = Id.new(params[:id])
|
326
|
-
copy_of(id) do |wallet|
|
327
|
-
content_type 'text/plain'
|
328
|
-
IO.read(wallet.path)
|
329
|
-
end
|
307
|
+
fetch { |w| IO.read(w.path) }
|
330
308
|
end
|
331
309
|
|
332
310
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/copies} do
|
333
|
-
|
334
|
-
|
335
|
-
copy_of(id) do
|
336
|
-
content_type 'text/plain'
|
337
|
-
copies = Copies.new(File.join(settings.copies, id))
|
311
|
+
fetch do |wallet|
|
312
|
+
copies = Copies.new(File.join(settings.copies, wallet.id))
|
338
313
|
copies.load.map do |c|
|
339
314
|
"#{c[:name]}: #{c[:host]}:#{c[:port]} #{c[:score]} #{c[:time].utc.iso8601}"
|
340
315
|
end.join("\n") +
|
@@ -348,13 +323,10 @@ in #{Age.new(@start, limit: 1)}")
|
|
348
323
|
end
|
349
324
|
|
350
325
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/copy/(?<name>[0-9]+)} do
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
copy_of(id) do
|
355
|
-
copy = Copies.new(File.join(settings.copies, id)).all.find { |c| c[:name] == name }
|
326
|
+
fetch do |wallet|
|
327
|
+
name = params[:name]
|
328
|
+
copy = Copies.new(File.join(settings.copies, wallet.id)).all.find { |c| c[:name] == name }
|
356
329
|
error 404 if copy.nil?
|
357
|
-
content_type 'text/plain'
|
358
330
|
IO.read(copy[:path])
|
359
331
|
end
|
360
332
|
end
|
@@ -485,6 +457,15 @@ in #{Age.new(@start, limit: 1)}")
|
|
485
457
|
end
|
486
458
|
end
|
487
459
|
|
460
|
+
def fetch(type = 'text/plain')
|
461
|
+
error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
|
462
|
+
id = Id.new(params[:id])
|
463
|
+
copy_of(id) do |wallet|
|
464
|
+
content_type(type)
|
465
|
+
yield wallet
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
488
469
|
def copy_of(id)
|
489
470
|
Tempfile.open([id.to_s, Wallet::EXT]) do |f|
|
490
471
|
settings.wallets.find(id) do |wallet|
|
data/lib/zold/patch.rb
CHANGED
@@ -94,11 +94,11 @@ module Zold
|
|
94
94
|
next
|
95
95
|
end
|
96
96
|
if !txn.sign.nil? && !txn.sign.empty?
|
97
|
-
@log.error("RSA signature is redundant at ##{txn.id} of #{wallet.id}: #{txn.to_text}")
|
97
|
+
@log.error("RSA signature is redundant at ##{txn.id} of #{wallet.id}: \"#{txn.to_text}\"")
|
98
98
|
next
|
99
99
|
end
|
100
100
|
unless wallet.prefix?(txn.prefix)
|
101
|
-
@log.error("Payment prefix '#{txn.prefix}' doesn't match with the key of #{wallet.id}: #{txn.to_text}")
|
101
|
+
@log.error("Payment prefix '#{txn.prefix}' doesn't match with the key of #{wallet.id}: \"#{txn.to_text}\"")
|
102
102
|
next
|
103
103
|
end
|
104
104
|
unless @wallets.find(txn.bnf, &:exists?)
|
@@ -106,8 +106,7 @@ module Zold
|
|
106
106
|
next
|
107
107
|
end
|
108
108
|
unless @wallets.find(txn.bnf) { |p| p.includes_negative?(txn.id, wallet.id) }
|
109
|
-
@log.error("Paying wallet #{txn.bnf} doesn't have transaction
|
110
|
-
among #{payer.txns.count} transactions: #{txn.to_text}")
|
109
|
+
@log.error("Paying wallet #{txn.bnf} doesn't have this transaction: \"#{txn.to_text}\"")
|
111
110
|
next
|
112
111
|
end
|
113
112
|
end
|
data/lib/zold/version.rb
CHANGED
data/test/commands/test_fetch.rb
CHANGED
@@ -44,6 +44,8 @@ class TestFetch < Zold::Test
|
|
44
44
|
def test_fetches_wallet
|
45
45
|
FakeHome.new(log: test_log).run do |home|
|
46
46
|
wallet = home.create_wallet
|
47
|
+
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}/size")
|
48
|
+
.to_return(status: 200, body: wallet.size.to_s)
|
47
49
|
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return(
|
48
50
|
status: 200,
|
49
51
|
body: {
|
@@ -52,9 +54,7 @@ class TestFetch < Zold::Test
|
|
52
54
|
'mtime': Time.now.utc.iso8601
|
53
55
|
}.to_json
|
54
56
|
)
|
55
|
-
stub_request(:get, "http://localhost:81/wallet/#{wallet.id}").to_return(
|
56
|
-
status: 404
|
57
|
-
)
|
57
|
+
stub_request(:get, "http://localhost:81/wallet/#{wallet.id}/size").to_return(status: 404)
|
58
58
|
remotes = home.remotes
|
59
59
|
remotes.add('localhost', 4096)
|
60
60
|
remotes.add('localhost', 81)
|
data/test/commands/test_pull.rb
CHANGED
@@ -39,6 +39,7 @@ class TestPull < Zold::Test
|
|
39
39
|
remotes.add('localhost', 4096)
|
40
40
|
json = home.create_wallet_json
|
41
41
|
id = Zold::JsonPage.new(json).to_hash['id']
|
42
|
+
stub_request(:get, "http://localhost:4096/wallet/#{id}/size").to_return(status: 200, body: '10000')
|
42
43
|
stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 200, body: json)
|
43
44
|
Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: test_log).run(
|
44
45
|
['--ignore-this-stupid-option', 'pull', id.to_s]
|
data/test/node/test_front.rb
CHANGED
@@ -156,6 +156,9 @@ class FrontTest < Zold::Test
|
|
156
156
|
"/wallet/#{wallet.id}/key",
|
157
157
|
"/wallet/#{wallet.id}/mtime",
|
158
158
|
"/wallet/#{wallet.id}/digest",
|
159
|
+
"/wallet/#{wallet.id}/size",
|
160
|
+
"/wallet/#{wallet.id}/age",
|
161
|
+
"/wallet/#{wallet.id}/mnemo",
|
159
162
|
"/wallet/#{wallet.id}.bin",
|
160
163
|
"/wallet/#{wallet.id}/copies"
|
161
164
|
].each do |u|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|