zold 0.31.5 → 0.31.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codecov.yml +20 -0
  3. data/.github/workflows/pdd.yml +11 -0
  4. data/.github/workflows/rake.yml +23 -0
  5. data/.github/workflows/xcop.yml +11 -0
  6. data/.rubocop.yml +9 -5
  7. data/.ruby-version +1 -1
  8. data/.rultor.yml +4 -5
  9. data/.simplecov +15 -19
  10. data/Dockerfile +1 -1
  11. data/Gemfile +13 -13
  12. data/Guardfile +1 -1
  13. data/README.md +0 -5
  14. data/Rakefile +1 -1
  15. data/bin/zold +1 -1
  16. data/features/step_definitions/steps.rb +5 -5
  17. data/features/support/env.rb +1 -1
  18. data/fixtures/merge/asserts.rb +1 -1
  19. data/fixtures/merge/into_no_wallet/assert.rb +1 -1
  20. data/fixtures/merge/legacy_negatives_stay/assert.rb +2 -2
  21. data/fixtures/merge/missed_wallets/assert.rb +2 -2
  22. data/fixtures/merge/negative_overwriting/assert.rb +1 -1
  23. data/fixtures/merge/negatives_in_between/assert.rb +2 -2
  24. data/fixtures/merge/random_expenses/assert.rb +2 -2
  25. data/fixtures/merge/simple_case/assert.rb +1 -1
  26. data/fixtures/merge/unconfirmed_income/assert.rb +1 -1
  27. data/lib/zold/age.rb +1 -1
  28. data/lib/zold/amount.rb +3 -3
  29. data/lib/zold/cached_wallets.rb +1 -1
  30. data/lib/zold/commands/args.rb +1 -1
  31. data/lib/zold/commands/calculate.rb +2 -2
  32. data/lib/zold/commands/clean.rb +1 -1
  33. data/lib/zold/commands/create.rb +6 -2
  34. data/lib/zold/commands/diff.rb +3 -3
  35. data/lib/zold/commands/fetch.rb +3 -3
  36. data/lib/zold/commands/invoice.rb +1 -1
  37. data/lib/zold/commands/list.rb +1 -1
  38. data/lib/zold/commands/merge.rb +4 -4
  39. data/lib/zold/commands/next.rb +1 -1
  40. data/lib/zold/commands/node.rb +3 -3
  41. data/lib/zold/commands/pay.rb +2 -2
  42. data/lib/zold/commands/propagate.rb +2 -2
  43. data/lib/zold/commands/pull.rb +1 -1
  44. data/lib/zold/commands/push.rb +1 -1
  45. data/lib/zold/commands/remote.rb +1 -1
  46. data/lib/zold/commands/remove.rb +1 -1
  47. data/lib/zold/commands/routines/audit.rb +7 -8
  48. data/lib/zold/commands/routines/gc.rb +1 -1
  49. data/lib/zold/commands/routines/reconcile.rb +1 -1
  50. data/lib/zold/commands/routines/reconnect.rb +1 -1
  51. data/lib/zold/commands/routines/retire.rb +1 -1
  52. data/lib/zold/commands/routines.rb +1 -1
  53. data/lib/zold/commands/show.rb +5 -6
  54. data/lib/zold/commands/taxes.rb +2 -2
  55. data/lib/zold/commands/thread_badge.rb +1 -1
  56. data/lib/zold/copies.rb +4 -4
  57. data/lib/zold/dir_items.rb +2 -2
  58. data/lib/zold/endless.rb +3 -5
  59. data/lib/zold/gem.rb +1 -1
  60. data/lib/zold/hands.rb +4 -4
  61. data/lib/zold/head.rb +1 -1
  62. data/lib/zold/hexnum.rb +1 -1
  63. data/lib/zold/http.rb +5 -4
  64. data/lib/zold/hungry_wallets.rb +2 -2
  65. data/lib/zold/id.rb +3 -5
  66. data/lib/zold/json_page.rb +2 -2
  67. data/lib/zold/key.rb +5 -5
  68. data/lib/zold/log.rb +7 -7
  69. data/lib/zold/metronome.rb +2 -2
  70. data/lib/zold/node/async_entrance.rb +9 -9
  71. data/lib/zold/node/entrance.rb +5 -5
  72. data/lib/zold/node/farm.rb +4 -4
  73. data/lib/zold/node/farmers.rb +2 -4
  74. data/lib/zold/node/front.rb +23 -19
  75. data/lib/zold/node/journaled_pipeline.rb +6 -6
  76. data/lib/zold/node/nodup_entrance.rb +1 -1
  77. data/lib/zold/node/nospam_entrance.rb +2 -2
  78. data/lib/zold/node/pipeline.rb +6 -6
  79. data/lib/zold/node/safe_entrance.rb +2 -2
  80. data/lib/zold/node/soft_error.rb +1 -1
  81. data/lib/zold/node/spread_entrance.rb +3 -3
  82. data/lib/zold/node/sync_entrance.rb +1 -1
  83. data/lib/zold/node/trace.rb +1 -1
  84. data/lib/zold/patch.rb +14 -15
  85. data/lib/zold/prefixes.rb +1 -1
  86. data/lib/zold/remotes.rb +4 -6
  87. data/lib/zold/signature.rb +1 -1
  88. data/lib/zold/size.rb +1 -1
  89. data/lib/zold/sync_wallets.rb +1 -1
  90. data/lib/zold/tax.rb +6 -4
  91. data/lib/zold/thread_pool.rb +3 -3
  92. data/lib/zold/tree_wallets.rb +1 -1
  93. data/lib/zold/txn.rb +26 -19
  94. data/lib/zold/txns.rb +1 -1
  95. data/lib/zold/upgrades.rb +2 -2
  96. data/lib/zold/verbose_thread.rb +2 -2
  97. data/lib/zold/version.rb +2 -2
  98. data/lib/zold/version_file.rb +1 -1
  99. data/lib/zold/wallet.rb +3 -3
  100. data/lib/zold/wallets.rb +6 -1
  101. data/lib/zold.rb +1 -1
  102. data/renovate.json +6 -0
  103. data/test/commands/routines/test_audit.rb +2 -2
  104. data/test/commands/routines/test_gc.rb +2 -2
  105. data/test/commands/routines/test_reconcile.rb +2 -2
  106. data/test/commands/routines/test_reconnect.rb +2 -2
  107. data/test/commands/routines/test_retire.rb +2 -2
  108. data/test/commands/test_alias.rb +1 -1
  109. data/test/commands/test_calculate.rb +1 -1
  110. data/test/commands/test_clean.rb +4 -4
  111. data/test/commands/test_create.rb +1 -1
  112. data/test/commands/test_diff.rb +5 -5
  113. data/test/commands/test_fetch.rb +21 -21
  114. data/test/commands/test_invoice.rb +1 -1
  115. data/test/commands/test_list.rb +1 -1
  116. data/test/commands/test_merge.rb +11 -11
  117. data/test/commands/test_node.rb +1 -1
  118. data/test/commands/test_pay.rb +4 -4
  119. data/test/commands/test_propagate.rb +1 -1
  120. data/test/commands/test_pull.rb +1 -1
  121. data/test/commands/test_push.rb +1 -1
  122. data/test/commands/test_remote.rb +2 -2
  123. data/test/commands/test_remove.rb +1 -1
  124. data/test/commands/test_show.rb +1 -1
  125. data/test/commands/test_taxes.rb +2 -2
  126. data/test/fake_home.rb +4 -3
  127. data/test/node/fake_entrance.rb +1 -1
  128. data/test/node/fake_node.rb +2 -2
  129. data/test/node/test_async_entrance.rb +6 -4
  130. data/test/node/test_entrance.rb +4 -4
  131. data/test/node/test_farm.rb +2 -2
  132. data/test/node/test_farmers.rb +1 -1
  133. data/test/node/test_front.rb +4 -4
  134. data/test/node/test_nodup_entrance.rb +2 -2
  135. data/test/node/test_nospam_entrance.rb +1 -1
  136. data/test/node/test_safe_entrance.rb +3 -3
  137. data/test/node/test_spread_entrance.rb +2 -2
  138. data/test/node/test_sync_entrance.rb +1 -1
  139. data/test/node/test_trace.rb +1 -1
  140. data/test/test__helper.rb +5 -4
  141. data/test/test_age.rb +2 -2
  142. data/test/test_amount.rb +1 -1
  143. data/test/test_cached_wallets.rb +3 -3
  144. data/test/test_copies.rb +6 -6
  145. data/test/test_dir_items.rb +2 -4
  146. data/test/test_gem.rb +1 -1
  147. data/test/test_hands.rb +1 -1
  148. data/test/test_hexnum.rb +1 -1
  149. data/test/test_http.rb +5 -5
  150. data/test/test_hungry_wallets.rb +1 -1
  151. data/test/test_id.rb +1 -1
  152. data/test/test_json_page.rb +1 -1
  153. data/test/test_key.rb +5 -5
  154. data/test/test_log.rb +1 -1
  155. data/test/test_metronome.rb +2 -1
  156. data/test/test_patch.rb +9 -9
  157. data/test/test_prefixes.rb +1 -1
  158. data/test/test_remotes.rb +2 -2
  159. data/test/test_signature.rb +1 -1
  160. data/test/test_size.rb +1 -1
  161. data/test/test_sync_wallets.rb +1 -1
  162. data/test/test_tax.rb +4 -4
  163. data/test/test_thread_pool.rb +1 -1
  164. data/test/test_tree_wallets.rb +1 -1
  165. data/test/test_txn.rb +2 -2
  166. data/test/test_upgrades.rb +4 -4
  167. data/test/test_verbose_thread.rb +1 -1
  168. data/test/test_wallet.rb +14 -14
  169. data/test/test_wallets.rb +1 -1
  170. data/test/test_zold.rb +2 -2
  171. data/test/upgrades/test_delete_banned_wallets.rb +1 -1
  172. data/test/upgrades/test_protocol_up.rb +1 -1
  173. data/upgrades/2.rb +1 -1
  174. data/upgrades/delete_banned_wallets.rb +2 -2
  175. data/upgrades/move_wallets_into_tree.rb +1 -1
  176. data/upgrades/protocol_up.rb +3 -3
  177. data/upgrades/rename_foreign_wallets.rb +2 -2
  178. data/zold.gemspec +21 -24
  179. metadata +40 -117
  180. data/.github/CODE_OF_CONDUCT.md +0 -76
  181. data/.github/CONTRIBUTING.md +0 -11
  182. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  183. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -51,9 +51,9 @@ module Zold
51
51
 
52
52
  def to_json
53
53
  @entrance.to_json.merge(
54
- 'queue': @queue.size,
55
- 'threads': @pool.count,
56
- 'queue_limit': @queue_limit
54
+ queue: @queue.size,
55
+ threads: @pool.count,
56
+ queue_limit: @queue_limit
57
57
  )
58
58
  end
59
59
 
@@ -69,7 +69,7 @@ module Zold
69
69
  File.delete(file)
70
70
  end
71
71
  end
72
- @log.info("#{@queue.size} wallets pre-loaded into async_entrace from #{@dir}") unless @queue.size.zero?
72
+ @log.info("#{@queue.size} wallets pre-loaded into async_entrace from #{@dir}") unless @queue.empty?
73
73
  @entrance.start do
74
74
  (0..@threads).map do |i|
75
75
  @pool.add do
@@ -100,7 +100,7 @@ module Zold
100
100
  uuid = SecureRandom.uuid
101
101
  file = File.join(@dir, "#{id}-#{uuid}#{Wallet::EXT}")
102
102
  next if File.exist?(file)
103
- IO.write(file, body)
103
+ File.write(file, body)
104
104
  @queue << { id: id, file: file }
105
105
  @log.debug("Added #{id}/#{Size.new(body.length)} to the queue at pos.#{@queue.size} \
106
106
  in #{Age.new(start, limit: 0.05)}")
@@ -122,7 +122,7 @@ module Zold
122
122
  end
123
123
 
124
124
  def safe_read(file)
125
- IO.read(file)
125
+ File.read(file)
126
126
  rescue Errno::ENOENT
127
127
  ''
128
128
  end
@@ -131,11 +131,11 @@ module Zold
131
131
  start = Time.now
132
132
  item = @queue.pop
133
133
  Thread.current.thread_variable_set(:wallet, item[:id].to_s)
134
- body = IO.read(item[:file])
134
+ body = File.read(item[:file])
135
135
  FileUtils.rm_f(item[:file])
136
136
  @entrance.push(item[:id], body)
137
137
  @log.debug("Pushed #{item[:id]}/#{Size.new(body.length)} to #{@entrance.class.name} \
138
- in #{Age.new(start, limit: 0.1)}#{@queue.size.zero? ? '' : "(#{@queue.size} still in the queue)"}")
138
+ in #{Age.new(start, limit: 0.1)}#{@queue.empty? ? '' : "(#{@queue.size} still in the queue)"}")
139
139
  end
140
140
  end
141
141
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -47,10 +47,10 @@ module Zold
47
47
 
48
48
  def to_json
49
49
  {
50
- 'history': @history.join(', '),
51
- 'history_size': @history.count,
52
- 'speed': @speed.empty? ? 0 : (@speed.inject(&:+) / @speed.count),
53
- 'pipeline': @pipeline.to_json
50
+ history: @history.join(', '),
51
+ history_size: @history.count,
52
+ speed: @speed.empty? ? 0 : (@speed.inject(&:+) / @speed.count),
53
+ pipeline: @pipeline.to_json
54
54
  }
55
55
  end
56
56
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -156,7 +156,7 @@ at #{host}:#{port}, strength is #{@strength}")
156
156
  save(host, port, threads, [Score.new(host: host, port: port, invoice: @invoice, strength: @strength)])
157
157
  scores = load
158
158
  free = scores.reject { |s| @threads.exists?(s.to_mnemo) }
159
- @pipeline << free[0] if @pipeline.size.zero? && !free.empty?
159
+ @pipeline << free[0] if @pipeline.empty? && !free.empty?
160
160
  after = scores.map(&:value).max.to_i
161
161
  return unless before != after && !after.zero?
162
162
  @log.debug("#{Thread.current.name}: best score of #{scores.count} is #{scores[0].reduced(4)}")
@@ -202,12 +202,12 @@ at #{host}:#{port}, strength is #{@strength}")
202
202
  .map(&:to_s)
203
203
  .uniq
204
204
  .join("\n")
205
- Futex.new(@cache).open { |f| IO.write(f, body) }
205
+ Futex.new(@cache).open { |f| File.write(f, body) }
206
206
  end
207
207
 
208
208
  def load
209
209
  return [] unless File.exist?(@cache)
210
- Futex.new(@cache).open(false) { |f| IO.readlines(f, "\n") }.reject(&:empty?).map do |t|
210
+ Futex.new(@cache).open(false) { |f| File.readlines(f, "\n") }.reject(&:empty?).map do |t|
211
211
  Score.parse(t)
212
212
  rescue StandardError => e
213
213
  @log.error(Backtrace.new(e).to_s)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -110,10 +110,8 @@ for #{score.value}/#{score.strength} at #{score.host}:#{score.port}")
110
110
  loop do
111
111
  begin
112
112
  buffer << stdout.read_nonblock(16 * 1024)
113
- # rubocop:disable Lint/HandleExceptions
114
113
  rescue IO::WaitReadable
115
- # rubocop:enable Lint/HandleExceptions
116
- # nothing to do here
114
+ # nothing to do here
117
115
  rescue StandardError => e
118
116
  @log.error(buffer)
119
117
  raise e
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -20,7 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- STDOUT.sync = true
23
+ $stdout.sync = true
24
24
 
25
25
  require 'get_process_mem'
26
26
  require 'thin'
@@ -187,7 +187,7 @@ from #{request.ip} in #{Age.new(@start, limit: 1)}")
187
187
  error(400, "Log not found at #{settings.nohup_log}") unless File.exist?(settings.nohup_log)
188
188
  response.headers['Content-Type'] = 'text/plain'
189
189
  response.headers['Content-Disposition'] = "attachment; filename='#{File.basename(settings.nohup_log)}'"
190
- IO.read(settings.nohup_log)
190
+ File.read(settings.nohup_log)
191
191
  end
192
192
 
193
193
  get '/favicon.ico' do
@@ -228,8 +228,10 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
228
228
  end,
229
229
  platform: RUBY_PLATFORM,
230
230
  load: settings.zache.get(:load, lifetime: settings.opts['no-cache'] ? 0 : 60) do
231
- require 'usagewatch_ext'
232
- Object.const_defined?('Usagewatch') ? Usagewatch.uw_load.to_f : 0.0
231
+ # doesn't work with Ruby 3.0+
232
+ # require 'usagewatch_ext'
233
+ # Object.const_defined?('Usagewatch') ? Usagewatch.uw_load.to_f : 0.0
234
+ 0.0
233
235
  end,
234
236
  total_mem: total_mem,
235
237
  threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
@@ -349,15 +351,17 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
349
351
  get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/copies} do
350
352
  fetch do |wallet|
351
353
  copies = Copies.new(File.join(settings.copies, wallet.id))
352
- copies.load.map do |c|
353
- "#{c[:name]}: #{c[:host]}:#{c[:port]} #{c[:score]} #{c[:time].utc.iso8601}"
354
- end.join("\n") +
355
- "\n\n" +
356
- copies.all.map do |c|
357
- w = Wallet.new(c[:path])
358
- "#{c[:name]}: #{c[:score]} #{w.mnemo} \
354
+ [
355
+ copies.load.map do |c|
356
+ "#{c[:name]}: #{c[:host]}:#{c[:port]} #{c[:score]} #{c[:time].utc.iso8601}"
357
+ end.join("\n"),
358
+ "\n\n",
359
+ copies.all.map do |c|
360
+ w = Wallet.new(c[:path])
361
+ "#{c[:name]}: #{c[:score]} #{w.mnemo} \
359
362
  #{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}"
360
- end.join("\n")
363
+ end.join("\n")
364
+ ].join
361
365
  end
362
366
  end
363
367
 
@@ -366,7 +370,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
366
370
  name = params[:name]
367
371
  copy = Copies.new(File.join(settings.copies, wallet.id)).all.find { |c| c[:name] == name }
368
372
  error 404 if copy.nil?
369
- IO.read(copy[:path])
373
+ File.read(copy[:path])
370
374
  end
371
375
  end
372
376
 
@@ -407,13 +411,13 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
407
411
 
408
412
  get '/ledger' do
409
413
  content_type('text/plain')
410
- File.exist?(settings.ledger) ? IO.read(settings.ledger) : ''
414
+ File.exist?(settings.ledger) ? File.read(settings.ledger) : ''
411
415
  end
412
416
 
413
417
  get '/ledger.json' do
414
418
  content_type('application/json')
415
419
  pretty(
416
- (File.exist?(settings.ledger) ? IO.read(settings.ledger).split("\n") : []).map do |t|
420
+ (File.exist?(settings.ledger) ? File.read(settings.ledger).split("\n") : []).map do |t|
417
421
  parts = t.split(';')
418
422
  {
419
423
  found: parts[0],
@@ -446,7 +450,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
446
450
  Thread.list.map do |t|
447
451
  [
448
452
  "#{t.name}: status=#{t.status}; alive=#{t.alive?}",
449
- 'Vars: ' + t.thread_variables.map { |v| "#{v}=\"#{t.thread_variable_get(v)}\"" }.join('; '),
453
+ "Vars: #{t.thread_variables.map { |v| "#{v}=\"#{t.thread_variable_get(v)}\"" }.join('; ')}",
450
454
  t.backtrace.nil? ? 'NO BACKTRACE' : " #{t.backtrace.join("\n ")}"
451
455
  ].join("\n")
452
456
  end
@@ -460,7 +464,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
460
464
 
461
465
  get '/queue' do
462
466
  content_type('text/plain')
463
- DirItems.new(settings.async_dir).fetch.select { |f| /^[0-9a-f]{16}-/.match?(f) }.map do |f|
467
+ DirItems.new(settings.async_dir).fetch.grep(/^[0-9a-f]{16}-/).map do |f|
464
468
  Wallet.new(File.join(settings.async_dir, f)).mnemo
465
469
  rescue Errno::ENOENT
466
470
  f
@@ -488,7 +492,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
488
492
  content_type('text/plain')
489
493
  file = File.join(settings.journal_dir, params[:id])
490
494
  error(404, "Journal item not found at #{file}") unless File.exist?(file)
491
- IO.read(file)
495
+ File.read(file)
492
496
  end
493
497
 
494
498
  not_found do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -45,9 +45,9 @@ module Zold
45
45
  def acq(id, exclusive: false)
46
46
  @wallets.acq(id, exclusive: exclusive) do |wallet|
47
47
  return yield wallet unless exclusive
48
- before = wallet.exists? ? IO.read(wallet.path) : ''
48
+ before = wallet.exists? ? File.read(wallet.path) : ''
49
49
  res = yield wallet
50
- after = wallet.exists? ? IO.read(wallet.path) : ''
50
+ after = wallet.exists? ? File.read(wallet.path) : ''
51
51
  unless before == after
52
52
  diff = Diffy::Diff.new(before, after, context: 0).to_s
53
53
  @log.info("The wallet #{id} was modified:\n #{diff.gsub("\n", "\n ")}")
@@ -70,7 +70,7 @@ module Zold
70
70
 
71
71
  def to_json
72
72
  @pipeline.to_json.merge(
73
- 'dir': @dir
73
+ dir: @dir
74
74
  )
75
75
  end
76
76
 
@@ -78,7 +78,7 @@ module Zold
78
78
  def push(id, body, wallets, log, lifetime: 6)
79
79
  DirItems.new(@dir).fetch.each do |f|
80
80
  f = File.join(@dir, f)
81
- File.delete(f) if File.mtime(f) < Time.now - lifetime * 60 * 60
81
+ File.delete(f) if File.mtime(f) < Time.now - (lifetime * 60 * 60)
82
82
  end
83
83
  journal = File.join(@dir, "#{Time.now.utc.iso8601.gsub(/[^0-9]/, '-')}-#{id}")
84
84
  jlog = Logger.new(journal)
@@ -89,7 +89,7 @@ module Zold
89
89
  jlog.info("Zold gem version: #{Zold::VERSION}")
90
90
  modified = @pipeline.push(id, body, JournaledPipeline::Wallets.new(wallets, jlog), Log::Tee.new(log, jlog))
91
91
  jlog.info("push(#{id}): done")
92
- FileUtils.mv(journal, journal + '-done')
92
+ FileUtils.mv(journal, "#{journal}-done")
93
93
  modified
94
94
  end
95
95
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -66,7 +66,7 @@ and '#{after[0..8]}' hash has already been seen #{Age.new(@zache.mtime(id.to_s))
66
66
  private
67
67
 
68
68
  def hash(id, body)
69
- OpenSSL::Digest::SHA256.new(id.to_s + ' ' + body).hexdigest
69
+ OpenSSL::Digest.new('SHA256', "#{id} #{body}").hexdigest
70
70
  end
71
71
  end
72
72
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -53,7 +53,7 @@ module Zold
53
53
  # Show its internals.
54
54
  def to_json
55
55
  {
56
- 'ledger': File.exist?(@ledger) ? IO.read(@ledger).split("\n").count : 0
56
+ ledger: File.exist?(@ledger) ? File.read(@ledger).split("\n").count : 0
57
57
  }
58
58
  end
59
59
 
@@ -96,13 +96,13 @@ module Zold
96
96
  )
97
97
  end
98
98
  @mutex.synchronize do
99
- txns = File.exist?(@ledger) ? IO.read(@ledger).strip.split("\n") : []
100
- txns += IO.read(f.path).strip.split("\n")
101
- IO.write(
99
+ txns = File.exist?(@ledger) ? File.read(@ledger).strip.split("\n") : []
100
+ txns += File.read(f.path).strip.split("\n")
101
+ File.write(
102
102
  @ledger,
103
103
  txns.map { |t| t.split(';') }
104
104
  .uniq { |t| "#{t[1]}-#{t[3]}" }
105
- .reject { |t| Txn.parse_time(t[0]) < Time.now - 24 * 60 * 60 }
105
+ .reject { |t| Txn.parse_time(t[0]) < Time.now - (24 * 60 * 60) }
106
106
  .map { |t| t.join(';') }
107
107
  .join("\n")
108
108
  .strip
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -60,7 +60,7 @@ module Zold
60
60
  raise 'Id must be of type Id' unless id.is_a?(Id)
61
61
  raise 'Body can\'t be nil' if body.nil?
62
62
  Tempfile.open(['', Wallet::EXT]) do |f|
63
- IO.write(f, body)
63
+ File.write(f, body)
64
64
  wallet = Wallet.new(f.path)
65
65
  wallet.refurbish
66
66
  unless wallet.protocol == Zold::PROTOCOL
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -56,8 +56,8 @@ module Zold
56
56
 
57
57
  def to_json
58
58
  @entrance.to_json.merge(
59
- 'modified': @modified.size,
60
- 'push': @push.to_json
59
+ modified: @modified.size,
60
+ push: @push.to_json
61
61
  )
62
62
  end
63
63
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/patch.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -51,7 +51,7 @@ module Zold
51
51
  def legacy(wallet, hours: 24)
52
52
  raise 'You can\'t add legacy to a non-empty patch' unless @id.nil?
53
53
  wallet.txns.each do |txn|
54
- @txns << txn if txn.amount.negative? && txn.date < Time.now - hours * 60 * 60
54
+ @txns << txn if txn.amount.negative? && txn.date < Time.now - (hours * 60 * 60)
55
55
  end
56
56
  end
57
57
 
@@ -170,18 +170,17 @@ doesn't have this transaction: #{txn.to_text.inspect}")
170
170
  added += 1
171
171
  next unless txn.amount.negative?
172
172
  File.open(ledger, 'a') do |f|
173
- f.puts(
174
- [
175
- Time.now.utc.iso8601,
176
- txn.id,
177
- txn.date.utc.iso8601,
178
- wallet.id,
179
- txn.bnf,
180
- txn.amount.to_i * -1,
181
- txn.prefix,
182
- txn.details
183
- ].map(&:to_s).join(';') + "\n"
184
- )
173
+ msg = [
174
+ Time.now.utc.iso8601,
175
+ txn.id,
176
+ txn.date.utc.iso8601,
177
+ wallet.id,
178
+ txn.bnf,
179
+ txn.amount.to_i * -1,
180
+ txn.prefix,
181
+ txn.details
182
+ ].map(&:to_s).join(';')
183
+ f.puts("#{msg}\n")
185
184
  end
186
185
  end
187
186
  end
@@ -214,7 +213,7 @@ doesn't have this transaction: #{txn.to_text.inspect}")
214
213
  end
215
214
  else
216
215
  FileUtils.mkdir_p(File.dirname(file))
217
- IO.write(file, IO.read(f.path))
216
+ File.write(file, File.read(f.path))
218
217
  end
219
218
  end
220
219
  before != wallet.digest
data/lib/zold/prefixes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/remotes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -166,7 +166,7 @@ at #{response.headers['X-Zold-Path']}"
166
166
  max_errors = list.empty? ? 0 : list.max_by { |r| r[:errors] }[:errors]
167
167
  max_errors = 1 if max_errors.zero?
168
168
  list.sort_by do |r|
169
- (1 - r[:errors] / max_errors) * 5 + (r[:score] / max_score)
169
+ ((1 - (r[:errors] / max_errors)) * 5) + (r[:score] / max_score)
170
170
  end.reverse
171
171
  end
172
172
 
@@ -176,9 +176,7 @@ at #{response.headers['X-Zold-Path']}"
176
176
 
177
177
  def masters
178
178
  MASTERS.each do |r|
179
- if block_given?
180
- next unless yield(r[:host], r[:port])
181
- end
179
+ next if block_given? && !yield(r[:host], r[:port])
182
180
  add(r[:host], r[:port])
183
181
  end
184
182
  end
@@ -273,7 +271,7 @@ at #{response.headers['X-Zold-Path']}"
273
271
  FileUtils.mkdir_p(File.dirname(@file))
274
272
  Futex.new(@file).open do
275
273
  list = yield(load)
276
- IO.write(
274
+ File.write(
277
275
  @file,
278
276
  list.uniq { |r| "#{r[:host]}:#{r[:port]}" }.map do |r|
279
277
  [
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/size.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/tax.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -94,7 +94,7 @@ module Zold
94
94
  end
95
95
 
96
96
  def debt
97
- FEE * @wallet.txns.count * @wallet.age - paid
97
+ (FEE * @wallet.txns.count * @wallet.age) - paid
98
98
  end
99
99
 
100
100
  def paid
@@ -106,8 +106,10 @@ module Zold
106
106
  score = Score.parse(body)
107
107
  next unless score.valid?
108
108
  next unless score.value == EXACT_SCORE || @ignore_score_weakness
109
- if score.strength < @strength && !@ignore_score_weakness
110
- next unless MILESTONES.find { |d, s| t.date < d && score.strength >= s }
109
+ if score.strength < @strength && !@ignore_score_weakness && !MILESTONES.find do |d, s|
110
+ t.date < d && score.strength >= s
111
+ end
112
+ next
111
113
  end
112
114
  next if t.amount * -1 > MAX_PAYMENT
113
115
  t
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -110,7 +110,7 @@ it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}
110
110
  name: t.name,
111
111
  status: t.status,
112
112
  alive: t.alive?,
113
- vars: Hash[t.thread_variables.map { |v| [v.to_s, t.thread_variable_get(v)] }]
113
+ vars: t.thread_variables.map { |v| [v.to_s, t.thread_variable_get(v)] }.to_h
114
114
  }
115
115
  end
116
116
  end
@@ -120,7 +120,7 @@ it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}
120
120
  @threads.map do |t|
121
121
  [
122
122
  "#{t.name}: status=#{t.status}; alive=#{t.alive?}",
123
- 'Vars: ' + t.thread_variables.map { |v| "#{v}=\"#{t.thread_variable_get(v)}\"" }.join('; '),
123
+ "Vars: #{t.thread_variables.map { |v| "#{v}=\"#{t.thread_variable_get(v)}\"" }.join('; ')}",
124
124
  t.backtrace.nil? ? 'NO BACKTRACE' : " #{t.backtrace.join("\n ")}"
125
125
  ].join("\n")
126
126
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal