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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25ddd38e296465dbb600bfd58681aacb8a957f683bf33c7a9fe29e5ba02fbf90
4
- data.tar.gz: db0590b2def1d612b9e21d4e40ca4c11260c04b622431e8132af8e29f602ced5
3
+ metadata.gz: d5128884745aa60eecc3b94b20b184ce5e297cf96d9550f12a20bccfa5445b01
4
+ data.tar.gz: 4e1403a766b2e41e99de13956a38a32fc299cc77e81047bc96c80019cb3feb53
5
5
  SHA512:
6
- metadata.gz: bac8ee84186954992bb51ad8e89f7c75efb8a65c014ec8ca48603abc5c7cf9e5b4d16a33aa7c466b30ca6b0004e3c3b170369cf9da56eb4accc34774d201cc50
7
- data.tar.gz: 1065f0c6ae8d17c8c714277c80b65e4ba0bfe34745e53e41200562884d1984af22f91f840182114306a53b31b3859173bc00239d9e61b171dceb3118821c300a
6
+ metadata.gz: 9821efb88ba25bd9836794cba697a2342978cfda9281c7507f4d08a5b44d6b4c68535da47311b3cfe44a0cab05e6a94fec7a773414e73242ba98862abd3c2f91
7
+ data.tar.gz: 2e3ff0c904aab956251070dfb01573022da6af3bfb9904df325c384d25795c184266c3b25826130eb91f01ce421db9cc6db5435e917f7a013180d076d9511597
@@ -104,7 +104,9 @@ Available options:"
104
104
  return 0
105
105
  end
106
106
  uri = "/wallet/#{id}"
107
- res = r.http(uri).get(timeout: 60)
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
@@ -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: 60)
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)}")
@@ -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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
283
- id = Id.new(params[:id])
284
- copy_of(id) do |wallet|
285
- content_type 'text/plain'
286
- wallet.mtime.utc.iso8601.to_s
287
- end
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
334
- id = Id.new(params[:id])
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
- error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch']
352
- id = Id.new(params[:id])
353
- name = params[:name]
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 ##{txn.id} \
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
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.16.22'
28
+ VERSION = '0.16.23'
29
29
  PROTOCOL = 2
30
30
  end
@@ -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)
@@ -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]
@@ -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.22
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-12 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace